TextArea SelectionChanged Bug?

When typing in a DesktopTextArea, the SelectionChanged event handler fires with every letter typed, even when you have no text selected.

Isn’t it supposed to only fire when the number of characters highlighted has changed?

Xojo 2022 R4.1
MacOS Ventura 13.1

This also happens in Xojo 2022 R3.2

No, as that’s intended like that. Every time you type a character, the SelectionStart changes, hence the SelectionChanged is fired, too.
An empty selection is still a selection :wink:

I guess the documentation and description for SelectionChanged event needs to updated, as they both read, “The range of characters HIGHLIGHTED has changed.”

When you’re typing, the number of characters highlighted never changes - it’s still zero, even if the selection start has changed.

The key word is “range” - where the selection starts, and how many characters are selected. When you have some text explicitly highlighted, the range starts at the first character and extends to the last one.

When you have no characters selected, the “selection” actually represents the insertion point – where the blinking carat is located - with a length of zero. Hence, as you type, the carat moves and Selection changed fires. You will get the same result by using the mouse to place the carat at various points in the text.

“You will get the same result by using the mouse to place the carat at various points in the text.”

May you get that. I don’t. If I highlight a word with the mouse, selection changed fires. If I click elsewhere with the mouse, it does not fire.

Video of Selection Changed not firing.

That’s very interesting. What if you move the carat with the arrow keys?

Arrow keys will fire the SelectionChanged event.

In that case, I’d say the lack of firing when clicking the mouse is a bug that should be reported, unless someone wants to chime in and explain why it isn’t.

In older versions, it does fire on mouse click. Just a data point. If you can confirm in a new project with just a textarea and no other code that it doesn’t fire on mouse click, then please raise an issue.

Seems to work well here.
(steps I used): added a TextArea in a blank project and added its SelectionChanged event like this: self.Title=System.Ticks.ToString
Running, filling the TextArea with random characters, clicking with the mouse at various places. The event worked as expected.