With my code below I get annoying scroll action.
On a long page if I cut or paste My code scrolls to the end of the pasted text. If it is only one word it scrolls so as this word is at the bottom of the text box. If I don't set the scroll position I end up at the top.
How can I paste and not have the textbox move at all. If I press Control V it behaves as I want. However if I put the keydown, keypress code into the paste button nothing happens.
On a long page if I cut or paste My code scrolls to the end of the pasted text. If it is only one word it scrolls so as this word is at the bottom of the text box. If I don't set the scroll position I end up at the top.
How can I paste and not have the textbox move at all. If I press Control V it behaves as I want. However if I put the keydown, keypress code into the paste button nothing happens.
B4X:
Case 18 'btnPaste
If TextEdit.SelectionStart > -1 Then
i = TextEdit.SelectionStart
If TextEdit.SelectionLength > 0 Then 'The pasted text should replace the selection.
TextEdit.Text = StrRemove(TextEdit.Text,i,TextEdit.SelectionLength)
End If
If cPPC Then 'Paste from the clipboard on the device
s = clip.GetClipboardData
Else 'Paste from the global variable on the desktop
s = DesktopString
End If
TextEdit.Text = StrInsert(TextEdit.Text,i,s)
TextEdit.SelectionStart = i + StrLength(s)
TextEdit.ScrollToCaret
' TextEdit.Focus
' Hardware.KeyDown(17)
' hardware.KeyPress(Asc("V"))
' hardware.KeyUp(17)
End If