Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

T/ckeditor5 typing/92: Add support for "word" unit in modifySelection() helper. #1287

Merged
merged 11 commits into from
Feb 16, 2018

Conversation

jodator
Copy link
Contributor

@jodator jodator commented Feb 8, 2018

Suggested merge commit message (convention)

Feature: Add support for "word" unit in modifySelection() helper.


Additional information

@jodator jodator requested a review from Reinmar February 8, 2018 13:13
@jodator
Copy link
Contributor Author

jodator commented Feb 8, 2018

I had some troubles with modifing getCorrectPosition() to some sane form.

It does too much now - maybe I should refactor it and extract word logic to other method?

@@ -13,6 +13,8 @@ import Range from '../range';
import { isInsideSurrogatePair, isInsideCombinedSymbol } from '@ckeditor/ckeditor5-utils/src/unicode';
import DocumentSelection from '../documentselection';

const wordBoundaryCharacters = ' ,.-():\'"';
Copy link
Member

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"?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@jodator jodator Feb 14, 2018

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...

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"a whole word"

Copy link
Contributor Author

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 = ' ,.?!:;"-()';

@@ -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
Copy link
Member

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


while ( isInsideSurrogatePair( data, offset ) || ( unit == 'character' && isInsideCombinedSymbol( data, offset ) ) ) {
while (
isInsideSurrogatePair( data, offset ) ||
Copy link
Member

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.

test(
'expands selection to the word start',
'<p>foo bar[b]az</p>',
// TODO: '<p>foo [barb]az</p>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member

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?

Copy link
Contributor Author

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.

@Reinmar
Copy link
Member

Reinmar commented Feb 14, 2018

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.

@Reinmar
Copy link
Member

Reinmar commented Feb 14, 2018

I've tested it manually and it works very well.

@coveralls
Copy link

coveralls commented Feb 14, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling e0a0766 on t/ckeditor5-typing/92 into 4b7d435 on master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants