Adventures in TextInputCavas : 12

OK back to things ( sorry for the long intermission:P )

All the code I update is in the github repo

A few clean up items to take care of

  1. if you just click then there’s a bug where the code tries to convert a click into a line and column when there is no text
  2. a click well beyond the end of the text can try to access lines that dont exist and you get an out of bound exception
  3. the blinking insertion point isnt tracking the end of the line properly once you insert a few new lines

Fixes
#1 - insert into XYToLineColumn at line 10 the following

// no lines then ANY click inside our bounds is line 0 column 0 
If lines.ubound < 0 Then
  lineNumber = 0
  column = 0
  Return
End If

#2 Alter LineColumnTiPosition to the following

// NOTE this is NOT EFFICIENT !!!!!!
// since we split things into lines in PAINT and again here
// if we really need lines we should figure out how to do this as few times as possible

// if line , col exceeds the n entire text buffer then the position should be the end of the buffer

Dim lines() As String = Split( ReplaceLineEndings(mTextBuffer, EndOfLine), EndOfLine )

Dim tmpPosition As Integer

// count up the lengths of whole lines
For i As Integer = 0 To min(line - 1, lines.Ubound)
  tmpPosition = tmpPosition + lines(i).Len
Next

// plus hte last line we add in just the columns since it may not be the wbole line
tmpPosition = tmpPosition + column

Return Min(tmpPosition, mTextBuffer.Len)

#3 add as the first line to the Inserttext event handler

Text = ReplaceLineEndings(Text, EndOfLine)

The DoCommand handlers for insert newline, insert linebreak etc already used endOfLine

Again, all the code is in the GitHub repository

1 Like