Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_handleSelectionMove( keyCode ) {
const selection = this.document.selection;
const newSelection = new ViewSelection( selection.getRanges(), { backward: selection.isBackward, fake: false } );
// Left or up arrow pressed - move selection to start.
if ( keyCode == keyCodes.arrowleft || keyCode == keyCodes.arrowup ) {
newSelection.setTo( newSelection.getFirstPosition() );
}
// Right or down arrow pressed - move selection to end.
if ( keyCode == keyCodes.arrowright || keyCode == keyCodes.arrowdown ) {
newSelection.setTo( newSelection.getLastPosition() );
}
const data = {
oldSelection: selection,
newSelection,
domSelection: null
};
// Fire dummy selection change event.
this.document.fire( 'selectionChange', data );
'foo[]',
keyCodes.arrowdown,
'foo[]'
);
test(
'should not move selection if there is no correct location - left arrow',
'[]foo',
keyCodes.arrowleft,
'[]foo'
);
test(
'should not move selection if there is no correct location - up arrow',
'[]foo',
keyCodes.arrowup,
'[]foo'
);
it( 'should prevent default behaviour when there is no correct location - document end', () => {
const keydownHandler = sinon.spy();
const domEventDataMock = {
keyCode: keyCodes.arrowright,
preventDefault: sinon.spy(),
};
setModelData( doc, 'foo[]' );
viewDocument.on( 'keydown', keydownHandler );
viewDocument.fire( 'keydown', domEventDataMock );
expect( getModelData( doc ) ).to.equal( 'foo[]' );
sinon.assert.calledOnce( domEventDataMock.preventDefault );
'foo[]',
{ keyCode: keyCodes.arrowleft, altKey: true },
'foo[]'
);
test(
'should work correctly with modifier key: left arrow + shift',
'foo[]',
{ keyCode: keyCodes.arrowleft, shiftKey: true },
'foo[]'
);
test(
'should work correctly with modifier key: up arrow + ctrl',
'foo[]',
{ keyCode: keyCodes.arrowup, ctrlKey: true },
'foo[]'
);
test(
'should work correctly with modifier key: up arrow + alt',
'foo[]',
{ keyCode: keyCodes.arrowup, altKey: true },
'foo[]'
);
test(
'should work correctly with modifier key: up arrow + shift',
'foo[]',
{ keyCode: keyCodes.arrowup, shiftKey: true },
'foo[]'
);
it( 'should fire selectionChange event with new selection when up arrow key is pressed', () => {
return checkSelectionChange(
'foo[<strong>bar</strong>]baz',
keyCodes.arrowup,
'foo[]<strong>bar</strong>baz'
);
} );
it( 'intercepts the arrow* events and overrides the default toolbar behavior', () => {
const keyEvtData = {
stopPropagation: sinon.spy()
};
keyEvtData.keyCode = keyCodes.arrowdown;
view.keystrokes.press( keyEvtData );
sinon.assert.calledOnce( keyEvtData.stopPropagation );
keyEvtData.keyCode = keyCodes.arrowup;
view.keystrokes.press( keyEvtData );
sinon.assert.calledTwice( keyEvtData.stopPropagation );
keyEvtData.keyCode = keyCodes.arrowleft;
view.keystrokes.press( keyEvtData );
sinon.assert.calledThrice( keyEvtData.stopPropagation );
keyEvtData.keyCode = keyCodes.arrowright;
view.keystrokes.press( keyEvtData );
sinon.assert.callCount( keyEvtData.stopPropagation, 4 );
} );
it( 'should prevent default for up arrow key', ( ) => {
return checkEventPrevention( keyCodes.arrowup );
} );
'[]foo',
keyCodes.arrowdown,
'[]foo'
);
test(
'should move selection backward from selected object - left arrow',
'foo[]',
keyCodes.arrowleft,
'foo[]'
);
test(
'should move selection backward from selected object - up arrow',
'foo[]',
keyCodes.arrowup,
'foo[]'
);
test(
'should move selection to next widget - right arrow',
'[]',
keyCodes.arrowright,
'[]'
);
test(
'should move selection to next widget - down arrow',
'[]',
keyCodes.arrowdown,
'[]'
);
expect( () => {
fireKeyDownEvent( { keyCode: keyCodes.arrowup } );
} ).to.not.throw();
} );
function isArrowKeyCode( keyCode ) {
return keyCode == keyCodes.arrowright ||
keyCode == keyCodes.arrowleft ||
keyCode == keyCodes.arrowup ||
keyCode == keyCodes.arrowdown;
}
function _isArrowKeyCode( keyCode ) {
return keyCode == keyCodes.arrowright ||
keyCode == keyCodes.arrowleft ||
keyCode == keyCodes.arrowup ||
keyCode == keyCodes.arrowdown;
}