-
Notifications
You must be signed in to change notification settings - Fork 40
T/ckeditor5 typing/92: Add support for "word" unit in modifySelection()
helper.
#1287
Conversation
c651496
to
9ce6455
Compare
I had some troubles with modifing It does too much now - maybe I should refactor it and extract |
src/model/utils/modifyselection.js
Outdated
@@ -13,6 +13,8 @@ import Range from '../range'; | |||
import { isInsideSurrogatePair, isInsideCombinedSymbol } from '@ckeditor/ckeditor5-utils/src/unicode'; | |||
import DocumentSelection from '../documentselection'; | |||
|
|||
const wordBoundaryCharacters = ' ,.-():\'"'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is '
a word boundary? What about "it's"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks that it is (as far as I can test it in textarea and Gnome Text editor:
it's a trap
- the text will stop: on spaces and on '
.
Also check this docs: https://www.unicode.org/reports/tr29/#Default_Word_Boundaries.
We might think of expanding this list to full unicode support but I've used the most common ones for the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is - check the behovior on textarea or in text editor:
It's a trap!
In the above the cursor will stop on spaces and on '
.
Also check this docs: https://www.unicode.org/reports/tr29/#Default_Word_Boundaries.
We might think of expanding this list to full unicode support but I've used the most common ones for the text.
edit: to be precise: https://www.unicode.org/reports/tr29/#Single_Quote
But examples shows that can't
is one word...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... we should expand the list of boundaryCharacters
with at least: ?|;
and probably some more common interpuntion characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wwalc told me that we need to differentiate between "it's" (which is made of two words so the caret should stop after "s") and "Peter's" where it's a single word which should be removed at once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm joking of course. Since a single quote is popular in English and e.g. in macOS it's not treated as a word boundary, I'd not treat it as such.
src/model/utils/modifyselection.js
Outdated
@@ -31,6 +33,7 @@ import DocumentSelection from '../documentselection'; | |||
* For example `𨭎` is represented in `String` by `\uD862\uDF4E`. Both `\uD862` and `\uDF4E` do not have any meaning | |||
* outside the pair (are rendered as ? when alone). Position between them would be incorrect. In this case, selection | |||
* extension will include whole "surrogate pair". | |||
* * `'word'` - moves selection by whole word. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"a whole word"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'd go with:
// current: ' ,.-():\'"';
const wordBoundaryCharacters = ' ,.?!:;"-()';
src/model/utils/modifyselection.js
Outdated
@@ -79,11 +82,13 @@ export default function modifySelection( model, selection, options = {} ) { | |||
} | |||
|
|||
// Checks whether the selection can be extended to the the walker's next value (next position). | |||
// @param {{ walker, unit, isForward, schema }} data | |||
// @param {{ item, nextPosition, type}} value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that value
is of the TreeWalkerValue
type
src/model/utils/modifyselection.js
Outdated
|
||
while ( isInsideSurrogatePair( data, offset ) || ( unit == 'character' && isInsideCombinedSymbol( data, offset ) ) ) { | ||
while ( | ||
isInsideSurrogatePair( data, offset ) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a separate function.
tests/model/utils/modifyselection.js
Outdated
test( | ||
'expands selection to the word start', | ||
'<p>foo bar[b]az</p>', | ||
// TODO: '<p>foo [barb]az</p>', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this TODO and other TODOs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've forgot to remove them while working.
I was pleased to see a great test suite. As for the code, you may try to improve it a bit – especially when it comes to overly long conditions. But it's completely internal stuff so it can be far from perfection. |
I've tested it manually and it works very well. |
Suggested merge commit message (convention)
Feature: Add support for "word" unit in
modifySelection()
helper.Additional information