Introduce helper functions.

* ve.ce.isLeftOrRightArrowKey
* ve.ce.isUpOrDownArrowKey
* ve.ce.isArrowKey

Change-Id: Id9fd7975e98085d01e545d1d0fc6086a06648031
This commit is contained in:
Inez Korczyński 2013-03-22 11:42:10 -07:00
parent c8819742eb
commit 5b9964878d

View file

@ -211,7 +211,7 @@ ve.ce.getOffsetFromElementNode = function ( domNode, domOffset, addOuterLength )
if ( addOuterLength === true ) {
return nodeModel.getOffset() + nodeModel.getOuterLength();
} else {
return nodeModel.getOffset();
return nodeModel.getOffset() + (nodeModel.isWrapped() ? 1 : 0);
}
} else {
node = $domNode.contents().last()[0];
@ -247,3 +247,15 @@ ve.ce.getOffsetOfSlug = function ( $node ) {
throw new Error( 'Incorrect slug location' );
}
};
ve.ce.isLeftOrRightArrowKey = function ( keyCode ) {
return keyCode === ve.Keys.DOM_VK_LEFT || keyCode === ve.Keys.DOM_VK_RIGHT;
};
ve.ce.isUpOrDownArrowKey = function ( keyCode ) {
return keyCode === ve.Keys.DOM_VK_UP || keyCode === ve.Keys.DOM_VK_DOWN;
};
ve.ce.isArrowKey = function ( keyCode ) {
return ve.ce.isLeftOrRightArrowKey( keyCode ) || ve.ce.isUpOrDownArrowKey( keyCode );
};