[Gambas-user] Paste into a textarea
T Lee Davidson
t.lee.davidson at gmail.com
Mon Jan 27 19:08:07 CET 2020
On 1/27/20 1:15 AM, Bruce wrote:
> Hi folks,
>
> Is there any way to check or trap that a textarea has just been pasted into?
> It's OK for them to type into it, so the Change event doesn't solve my problem, which is I need to clean up the text that has
> just been pasted.
>
> Bruce
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
There are two ways that text can be pasted. By keyboard (Ctrl-V) and by mouse (right-click, paste). Trapping the Ctrl-V key
event is rather trivial. The only way I can think of off hand to trap a right-click & paste is to track and test for a certain
sequence of events. A mouse paste would consist of a MouseDown event followed by a Change event (there is no MouseUp event on a
right-click).
Both methods of pasting can be caught like so:
' Gambas class file
Public bMouseRight As Boolean
Public Sub TextArea1_Change()
If bMouseRight Then
Print "Mouse paste"
Endif
bMouseRight = False
End
Public Sub TextArea1_MouseDown()
If Mouse.Right Then
bMouseRight = True
Else 'Perhaps user clicked to get rid of the right-click menu
bMouseRight = False
Endif
End
Public Sub TextArea1_KeyPress()
If Key.Control And If Key.Code = Key["v"] Then Print "Key Paste"
End
~~~
Now as far as cleaning up _only_ the text that has been pasted, perhaps you could also keep track of the Pos property in a
separate variable so that you know the position of the text cursor prior to the paste.
--
Lee
More information about the User
mailing list