Pasting Text and LimitText

If I paste 12 characters in a TextField that has .LimitText as 11 characters, the Mac (and Win I think too) refuses to do it.

How can I do this where at least it will put in what it can and truncate the rest?

I’ll answer my own question: abandon using LimitText and handle it all in TextChange? Is there another more standard way?

The obvious place where to crop the clipboard content would be a menu handler for the EditPaste menu, but it simply never gets fired. Managing the text limit in TextChanged seems the only way.

According to the documentation:

My question becomes does the documentation need to be changed, or does LimitText need to be fixed?
Tested, it’s not a one off occurrence.

So what happens?
Does the documentation get changed, or is someone going to fix LimitText to work the way it should?

New <https://xojo.com/issue/33746>

I’m not saying this is a bug or anything, I completely understand that LimitText would refuse a paste that don’t concur with it’s limitations.

I got it !

For some reason, a menu handler for the EditPaste menu item never fires. When EditUndo does.

I removed the EditPaste menu item, and replaced it by Pasta, with the same command/ctrl-V shortcut, and now a menu handler for that fires. Now the problem becomes to manage paste wherever it is necessary. If we only had to paste to EditField1, the code would then be :

Function Pasta() As Boolean Dim c As New Clipboard If c.TextAvailable Then if len(c.Text)>11 then c.Text = left(c.Text,11) TextField1.Text = c.Text End If c.Close Return false End Function

Of course, things are a bit more complex to insure paste works in every control…

[quote=93724:@Michel Bujardet]I got it !

For some reason, a menu handler for the EditPaste menu item never fires. When EditUndo does.

I removed the EditPaste menu item, and replaced it by Pasta, with the same command/ctrl-V shortcut, and now a menu handler for that fires. Now the problem becomes to manage paste wherever it is necessary. If we only had to paste to EditField1, the code would then be :

Function Pasta() As Boolean Dim c As New Clipboard If c.TextAvailable Then if len(c.Text)>11 then c.Text = left(c.Text,11) TextField1.Text = c.Text End If c.Close Return false End Function

Of course, things are a bit more complex to insure paste works in every control…[/quote]

Each control could set a flag in GotFocus which would serve to know what to do in Pasta.