-
Notifications
You must be signed in to change notification settings - Fork 18
Custom keyboard navigation through tables #304
Conversation
# Conflicts: # src/tableediting.js
…e in a table cell.
…ed handling of widgets at beginning/end of table cell. Code cleanup and added inline comments.
☝️ I see that it works for multiple blocks, one after another, but in the screencast its a single block with wrapped content. |
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.
The feature looks good to me. I only had some small concerns regarding implementation. Let's move ahead with this feature.
…handle hidden image captions.
This should be fixed now in eebd6f2. |
cc @ckeditor/qa-team Can you have a look at this? Navigation over table cells should be as intuitive as possible. Note that on the first/last text lines in a cell the caret is moved to first/last position in that cell (it's expected behavior). It's using DOM client rects so we should test it in different browsers. |
We've tested it in all browsers and besides the issue above, it works fine 👍 |
…aragraph when next paragraph is single-line.
This is how Firefox handles |
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.
Some tests are failing on the CI.
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.
Mostly concerns regarding docs.
src/tablenavigation.js
Outdated
} | ||
|
||
/** | ||
* Returns a range from beginning/end of range up to selection closest position. |
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 probably needs rephrasing ("a range from the beginning of range") because honestly I don't understand what it does without digging into the code.
src/tablenavigation.js
Outdated
} | ||
|
||
/** | ||
* Checks if the `modelRange` renders to a single line in the DOM. |
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.
That's probably one of the key methods around here. It deserves more documentation, especially that model ranges do not work at the DOM level. You should explain that you're checking out a DOM range corresponding to the model range and then you analyze its DOMRects to figure out whether the DOM range visually wraps to the next line.
Co-Authored-By: Aleksander Nowodzinski <a.nowodzinski@cksource.com>
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.
Minor remarks concerning tests.
tests/tablenavigation.js
Outdated
@@ -0,0 +1,2277 @@ | |||
import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard'; | |||
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; |
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.
We try to follow a convention in which named imports usually land after default imports.
Also, we try (at least to some extent) to group imports (external packages in one group (image, horizontal line), in-package imports (table, table editing) in another, global helpers (global
, env
) in another).
This should probably be explained in https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/framework/guides/contributing/code-style.html (cc @Reinmar).
} ); | ||
} ); | ||
|
||
describe( 'contains image widget with caption and selection inside the caption', () => { |
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.
What contains that image? TCs suggest this is about a cell where the initial selection is but it is not clear from the description. It could as well describe a place the selection should be anchored to after the navigation.
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.
Table cell contains image.
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.
OK I'll stop here.
The feature works great and for me the issues which I'll report below are minor and can be follow ups.
As for the code:
- I really don't like the
ck-hidden
check in the view. For now I think that we could live with this but I'd rather see if we cannot detect this case differently. What if we change view class? And that kind of question - I feel that this might be a bigger issue as how to reflect such things in the model. - Some
if
clause removals - just to have them nicer to read. - I've went through the
_handleArrowKeys()
method - my feeling is that some checks were an outcome of a long-living code that evolved with each edge case. I found some improvements and simplifications - those might be minor things really. I only wonder if the checks shouldn't be revisited with a "fresh" eye to spot other possible cases to handle differently - especially to remove the dependency on a view (in theck-hidden
case - the calculating DOM Rects is a pretty neat idea and we don't have any other option. - Don't import from model in features. We have API for that™.
- The
_isSingleLineRange
needs better comments as current one were hard to dig into. However I don't have an idea how to improve them now. - I didn't read the tests so I hope @oleq found something there :D
tests/table.js
Outdated
it( 'requires TableEditing, TableUI, TableSelection, TableClipboard, and Widget', () => { | ||
expect( Table.requires ).to.deep.equal( [ TableEditing, TableUI, TableSelection, TableClipboard, Widget ] ); | ||
expect( Table.requires ).to.deep.equal( [ TableEditing, TableUI, TableSelection, TableClipboard, TableNavigation, Widget ] ); | ||
} ); |
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.
Test name is wrong ;)
If you wish you could split it to 6 separate tests (each for required plugin). But changing test name is enough.
src/tablenavigation.js
Outdated
case keyCodes.arrowleft: return isLtrContent ? 'left' : 'right'; | ||
case keyCodes.arrowright: return isLtrContent ? 'right' : 'left'; | ||
case keyCodes.arrowup: return 'up'; | ||
case keyCodes.arrowdown: return 'down'; |
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.
Please format it so each return
is in new line (code style consistency with existing code).
And I have and inconsistency in the behaviour. Basically the feature works like the Google docs but - I don't find it OK but maybe it's just me. So Google docs navigating with arrow (gets "trapped"): So Google docs navigating with TAB (as in CKEditor - navigate on the same row): Browsers (Chrome & Firefox) with arrows (similar to TAB action): Similarly to browser, the Libre office follows the TAB behaviour pattern for arrows: So as long we think that having different behaviour for TAB is OK (so as in GDocs) then it is a minor issue. cc @oleq . |
Co-Authored-By: Maciej <jodator@jodator.net>
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.
LGTM now 👍.
The issues were addressed and the navigation itself works great.
CC @Reinmar I'd go with this in current iteration. We can also close handling shift ckeditor/ckeditor5#6641.
The test that fails is from Firefox. I don't see what is causing this in this PR so I'm merging it and try fix CI later. |
Suggested merge commit message (convention)
Other: Custom keyboard navigation through tables. Closes ckeditor/ckeditor5#3267. Closes ckeditor/ckeditor5#3286.
Additional information