New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement word selection for textfield, start word selection by double clicking and dragging #2580
base: develop
Are you sure you want to change the base?
Conversation
When first added and clicked, a timing error occurs when setting __caretIndex and __selectionIndex - `__selectionIndex` defaults to 0, and the double click verification cant change it in time, so the first click results in a selection from 0 to __caretIndex
Interesting! I knew that double-clicking a word would select the whole word, but I didn't know that if you dragged after double-clicking, it would expand selection to whole words instead of character by character. |
another thing i didnt know (which i plan to implement too) is that a triple click selects an entire pragraph, and dragging selects from the initial paragraph to the one under the mouse. i thought it selected lines, but thats probably because i use vscode too much😆 |
Another thing, you might have noticed i removed the event listener for |
would this be merged right after 9.2? if so, should i also add the triple click, paragraph-selection capabilities? |
I know what to fix to make CI working, I'll do the fix after 9.2 is out |
It just your use of the final keyword. This is only supported since haxe 4. Since we still support backwards compatibility with older versions, you should avoid using syntax only available in new releases of Haxe. |
can someone trigger CI to check the last commit? i wan to see if there's anything i missed |
Can this be merged now? i want to work on the other selection changes, but I'm wating for this to get merged |
Bumping this, the selection changes, or at least further modification of the way openfl does text selection is really needed, especially for web platforms, on which OpenFl's textfields stick out like a sore thumb... And another question - if this PR is still both relevant & applicable, can it be merged into 9.4.0-Dev instead? seems more fitting imo |
I merged #2587 the other day, and I'd like to merge this one too (into 9.4.0-Dev). I think that this one should be updated to use |
I'm quite busy today, and there's also some work to do with paragraph selection iirc (triple clilck) |
…ubleClick event as it is not referenced anywhere and is not necessary
…by line (paragraph selection is the same thing, its name line selection for clarity
All is pretty much done! some things have changed since the start of this pr:
Things i haven't tested:
Things i haven't implemented/done:
|
@ShaharMS I may have some more feedback after I get into testing the code, but just reading through it, can you remove the |
Or maybe go all the way and only allow these types of selection when doubleClickEnabled is true? Which route should I go? |
I checked the other day, and TextField's doubleClickEnabled is false in Flash. So just remove that line, and it's all good. |
…listening anymore
@joshtynjala line removed. Can this be merged? |
Thanks! When I have time again, I'll do some testing, and merge it if everything looks good. |
Heres a PR that implements word selection.
To summarize, i made two external, non-completion variables -
__wordSelection
and__wordSelectionInitialIndex
.__wordSelection
is used to check if the textfield is currently "double clicked". if so, regular dragging is modified to only account for word starts/endings as indices__wordSelectionInitialIndex
is used to know where to start the selection from, and to which direction (for example, if__caretIndex > __wordSelectionInitialIndex
, we need to select from the start of the first selected word to the end of the last. othewise, select from the end of the first word selected, to the start of the last)I also made two non-completeion functions to calculate the selection indices:
This one is used to set
__caretIndex
https://github.com/ShaharMS/openfl/blob/f8d1f60c2391d6aaf0ebdb1be6e1a08b7aad443a/src/openfl/text/TextField.hx#L1964-L1987
And this one is used to set
__selectionIndex
https://github.com/ShaharMS/openfl/blob/f8d1f60c2391d6aaf0ebdb1be6e1a08b7aad443a/src/openfl/text/TextField.hx#L1989-L2011