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

Commit

Permalink
Fix: Jumping over the filler should not be hindered by the two-step c…
Browse files Browse the repository at this point in the history
…aret movement.
  • Loading branch information
oleq committed Apr 18, 2018
1 parent e89e69d commit d32625f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
6 changes: 5 additions & 1 deletion src/utils/bindtwostepcarettoattribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class TwoStepCaretHandler {
*
* @param {module:engine/model/position~Position} position The model position at the moment of the key press.
* @param {module:engine/view/observer/domeventdata~DomEventData} data Data of the key press.
* @returns {Boolean} `true` when the handler prevented caret movement
*/
handleForwardMovement( position, data ) {
const attribute = this.attribute;
Expand Down Expand Up @@ -302,6 +303,7 @@ class TwoStepCaretHandler {
*
* @param {module:engine/model/position~Position} position The model position at the moment of the key press.
* @param {module:engine/view/observer/domeventdata~DomEventData} data Data of the key press.
* @returns {Boolean} `true` when the handler prevented caret movement
*/
handleBackwardMovement( position, data ) {
const attribute = this.attribute;
Expand Down Expand Up @@ -418,7 +420,9 @@ class TwoStepCaretHandler {
this._skipNextAutomaticGravityRestoration();
this._overrideGravity();

return true;
// Don't return "true" here because we didn't call preventPrevent.
// Returning here will destabilize the filler logic, which also listens to
// keydown (and it will be stopped).
}
}
}
Expand Down
58 changes: 29 additions & 29 deletions tests/utils/bindtwostepcarettoattribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
{ selectionAttributes: [ 'c' ], isGravityOverridden: false, preventDefault: 0, evtStopCalled: 0 },
'←',
// Caret movement was not blocked but the gravity is overridden.
{ selectionAttributes: [ 'c' ], isGravityOverridden: true, preventDefault: 0, evtStopCalled: 1 },
{ selectionAttributes: [ 'c' ], isGravityOverridden: true, preventDefault: 0, evtStopCalled: 0 },
'←',
{ selectionAttributes: [ 'a', 'b' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 2 },
{ selectionAttributes: [ 'a', 'b' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 1 },
'←',
{ selectionAttributes: [ 'a', 'b' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 2 },
{ selectionAttributes: [ 'a', 'b' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 1 },
] );
} );

Expand All @@ -237,11 +237,11 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
{ selectionAttributes: [ 'a', 'b' ], isGravityOverridden: false, preventDefault: 0, evtStopCalled: 0 },
'←',
// Caret movement was not blocked.
{ selectionAttributes: [ 'a', 'b' ], isGravityOverridden: true, preventDefault: 0, evtStopCalled: 1 },
{ selectionAttributes: [ 'a', 'b' ], isGravityOverridden: true, preventDefault: 0, evtStopCalled: 0 },
'←',
{ selectionAttributes: [ 'c' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 2 },
{ selectionAttributes: [ 'c' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 1 },
'←',
{ selectionAttributes: [ 'c' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 2 }
{ selectionAttributes: [ 'c' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 1 }
] );
} );

Expand Down Expand Up @@ -286,16 +286,16 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 0, evtStopCalled: 0 },
'←',
// <$text a="2">foo</$text><$text a="1">[]bar</$text>
{ selectionAttributes: [ 'a' ], isGravityOverridden: true, preventDefault: 0, evtStopCalled: 1 },
{ selectionAttributes: [ 'a' ], isGravityOverridden: true, preventDefault: 0, evtStopCalled: 0 },
'←',
// <$text a="2">foo</$text>[]<$text a="1">bar</$text>
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 2 },
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 1 },
'←',
// <$text a="2">foo[]</$text><$text a="1">bar</$text>
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 3 },
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 2 },
'←',
// <$text a="2">fo[]o</$text><$text a="1">bar</$text>
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 3 }
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 2 }
] );
} );

Expand Down Expand Up @@ -367,13 +367,13 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 0, evtStopCalled: 0 },
'←',
// <$text a="1">{}xyz</$text>
{ selectionAttributes: [ 'a' ], isGravityOverridden: true, preventDefault: 0, evtStopCalled: 1 },
{ selectionAttributes: [ 'a' ], isGravityOverridden: true, preventDefault: 0, evtStopCalled: 0 },
'←',
// {}<$text a="1">xyz</$text>
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 2 },
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 1 },
'←',
// {}<$text a="1">xyz</$text>
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 2 }
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 1 }
] );
} );

Expand Down Expand Up @@ -407,13 +407,13 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 1 },
'←',
// <$text a="1">xy</$text>[]z
{ selectionAttributes: [], isGravityOverridden: true, preventDefault: 1, evtStopCalled: 2 },
{ selectionAttributes: [], isGravityOverridden: true, preventDefault: 1, evtStopCalled: 1 },
'←',
// <$text a="1">xy[]</$text>z
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 3 },
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 2 },
'w',
// <$text a="1">xyw[]</$text>
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 3 },
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 2 },
] );
} );

Expand Down Expand Up @@ -461,16 +461,16 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 1 },
'←',
// foo <$text a="1">[]bar</$text>
{ selectionAttributes: [ 'a' ], isGravityOverridden: true, preventDefault: 1, evtStopCalled: 2 },
{ selectionAttributes: [ 'a' ], isGravityOverridden: true, preventDefault: 1, evtStopCalled: 1 },
'←',
// foo []<$text a="1">bar</$text>
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 3 },
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 2 },
'←',
// foo[] <$text a="1">bar</$text>
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 3 },
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 2 },
'←',
// fo[]o <$text a="1">bar</$text>
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 3 },
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 2 },
] );
} );

Expand Down Expand Up @@ -586,37 +586,37 @@ describe( 'bindTwoStepCaretToAttribute()', () => {
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 0, evtStopCalled: 0 },
'←',
// foo<$text a="true">foo</$text><$text a="true" c="true">bar</$text><$text c="true">baz</$text>[]qux
{ selectionAttributes: [], isGravityOverridden: true, preventDefault: 0, evtStopCalled: 1 },
{ selectionAttributes: [], isGravityOverridden: true, preventDefault: 0, evtStopCalled: 0 },
'←',
// foo<$text a="true">foo</$text><$text a="true" c="true">bar</$text><$text c="true">baz[]</$text>qux
{ selectionAttributes: [ 'c' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 2 },
{ selectionAttributes: [ 'c' ], isGravityOverridden: false, preventDefault: 1, evtStopCalled: 1 },
'←',
'←',
'←',
// foo<$text a="true">foo</$text><$text a="true" c="true">bar</$text><$text c="true">[]baz</$text>qux
{ selectionAttributes: [ 'c' ], isGravityOverridden: true, preventDefault: 1, evtStopCalled: 3 },
{ selectionAttributes: [ 'c' ], isGravityOverridden: true, preventDefault: 1, evtStopCalled: 1 },
'←',
// foo<$text a="true">foo</$text><$text a="true" c="true">bar[]</$text><$text c="true">baz</$text>qux
{ selectionAttributes: [ 'a', 'c' ], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 4 },
{ selectionAttributes: [ 'a', 'c' ], isGravityOverridden: false, preventDefault: 2, evtStopCalled: 2 },
'←',
'←',
'←',
// foo<$text a="true">foo</$text><$text a="true" c="true">[]bar</$text><$text c="true">baz</$text>qux
{ selectionAttributes: [ 'a', 'c' ], isGravityOverridden: true, preventDefault: 2, evtStopCalled: 5 },
{ selectionAttributes: [ 'a', 'c' ], isGravityOverridden: true, preventDefault: 2, evtStopCalled: 2 },
'←',
// foo<$text a="true">foo[]</$text><$text a="true" c="true">bar</$text><$text c="true">baz</$text>qux
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 3, evtStopCalled: 6 },
{ selectionAttributes: [ 'a' ], isGravityOverridden: false, preventDefault: 3, evtStopCalled: 3 },
'←',
'←',
'←',
// foo<$text a="true">[]foo</$text><$text a="true" c="true">bar</$text><$text c="true">baz</$text>qux
{ selectionAttributes: [ 'a' ], isGravityOverridden: true, preventDefault: 3, evtStopCalled: 7 },
{ selectionAttributes: [ 'a' ], isGravityOverridden: true, preventDefault: 3, evtStopCalled: 3 },
'←',
// foo[]<$text a="true">foo</$text><$text a="true" c="true">bar</$text><$text c="true">baz</$text>qux
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 4, evtStopCalled: 8 },
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 4, evtStopCalled: 4 },
'←',
// fo[]o<$text a="true">foo</$text><$text a="true" c="true">bar</$text><$text c="true">baz</$text>qux
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 4, evtStopCalled: 8 },
{ selectionAttributes: [], isGravityOverridden: false, preventDefault: 4, evtStopCalled: 4 },
] );
} );
} );
Expand Down

0 comments on commit d32625f

Please sign in to comment.