I would like to know how to insert a text starting from cursor position and keep this possition for each net new line.
The goal is to using this feature for insert some code and keep its format.
For example.
My line here. (crlf)
(tab) (tab) Another line (crlf)
_(here my new position)
Usualy, i’ve this result.
My line here. (crlf)
(tab) (tab) Another line (crlf)
_(here my new position)
So after the (crlf) i would like to keep the cursor position just before: Another line
I use selStart and selText, all is right , just missing this feature.
Sorry, I misunderstood your question, I think this should sort it. It checks the number of tabs in front of the cursor until it hits the start of the new line. It then uses that number of tabs to put on the new line after the paste to bring the caret back to the same indent, is that what you were after?
[code]Dim tmp As String
Dim tabs As Integer = 0
For i As Integer = TextArea1.SelStart DownTo 1
tmp = textarea1.Text.Mid(i, 1)
if Asc(tmp)= 9 then
tabs = tabs + 1
End If
If Asc(tmp) = 13 or i = 1 Then
'found start of line
TextArea1.SelText = “MOO” + Chr(13)
for tabs = tabs DownTo 1
TextArea1.SelText = Chr(9)
Next
'We dont need to go back any further
Exit
End If
Next[/code]
textarea1.seltext = “MOO”
i = Len(textarea1.Text) // This is when you append text, not for when you insert text
textarea1.SelStart = i + LineLen[/code]
In short: I store in i the position after MOO,
Add it to the length of the text in Another_Line
And set the cursor position at the end of Another_Line.
Now if you want to set the cursor at the end of the text, use:
Here you go, different platforms put different characters in to denote carriage returns etc. This should cover them all.
[code]Dim tmp As String
Dim tabs As Integer = 0
For i As Integer = TextArea1.SelStart DownTo 1
tmp = textarea1.Text.Mid(i, 1)
'System.DebugLog(tmp + “=” + Str(Asc(tmp)))
If Asc(tmp)= 9 Then
tabs = tabs + 1
End If
If (Asc(tmp) > 9 And Asc(tmp) < 14) Or i = 1 Then
'found start of line
TextArea1.SelText = “MOO” + Chr(13)
For tabs = tabs DownTo 1
TextArea1.SelText = Chr(9)
Next
'We dont need to go back any further
Exit
End If
Next[/code]
TextArea.SelStart is the cursor position in characters from the start of the textarea.