Inez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/55829
Change subject: Add support for slugs in
ve.ce.Document.prototype.getRelativeOffset
......................................................................
Add support for slugs in ve.ce.Document.prototype.getRelativeOffset
Also removed ve.ce.Surface.prototype.adjustCursor because it is not being used
anymore
Change-Id: Ib7dd8f4f6eaa688995d33247600875a45fc5a602
---
M modules/ve/ce/ve.ce.Document.js
M modules/ve/ce/ve.ce.Surface.js
2 files changed, 19 insertions(+), 59 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/29/55829/1
diff --git a/modules/ve/ce/ve.ce.Document.js b/modules/ve/ce/ve.ce.Document.js
index c7ea4db..27e2767 100644
--- a/modules/ve/ce/ve.ce.Document.js
+++ b/modules/ve/ce/ve.ce.Document.js
@@ -95,7 +95,7 @@
inc = direction > 0 ? 1 : -1,
oneChar, prevType, nextType;
if ( !data[i] || data[i].type !== undefined ) {
- return this.model.getRelativeContentOffset( offset, direction );
+ return this.getRelativeOffset( offset, direction, 'character' );
} else {
config = $.browser.msie ? config.ie : config.default;
config = direction > 0 ? config.right : config.left;
@@ -136,10 +136,26 @@
* @returns {number} Relative offset
*/
ve.ce.Document.prototype.getRelativeOffset = function ( offset, direction,
unit ) {
+ var bias, relativeContentOffset, relativeStructuralOffset;
if ( unit === 'word' ) { // word
return this.getSiblingWordBoundary( offset, direction );
} else { // character
- // TODO: add support for slugs
- return this.model.getRelativeContentOffset( offset, direction );
+ bias = direction > 0 ? 1 : -1;
+ relativeContentOffset = this.model.getRelativeContentOffset(
offset, direction );
+ relativeStructuralOffset =
this.model.getRelativeStructuralOffset( offset + bias, direction, true );
+ // Check if we've moved into a slug
+ if ( !!this.getSlugAtOffset( relativeStructuralOffset ) ) {
+ // Check if the relative content offset is in the
opposite direction we are trying to go
+ if ( ( relativeContentOffset - offset < 0 ? -1 : 1 )
!== bias ) {
+ // There's nothing past the slug we are already
in, stay in it
+ return relativeStructuralOffset;
+ }
+ // There's a slug neaby, go into it if it's closer
+ return direction > 0 ?
+ Math.min( relativeContentOffset,
relativeStructuralOffset ) :
+ Math.max( relativeContentOffset,
relativeStructuralOffset );
+ } else {
+ return relativeContentOffset;
+ }
}
};
\ No newline at end of file
diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js
index b1c013d..262d7ae 100644
--- a/modules/ve/ce/ve.ce.Surface.js
+++ b/modules/ve/ce/ve.ce.Surface.js
@@ -1092,62 +1092,6 @@
};
/**
- * Adjust the cursor position in a given distance.
- *
- * This method only affects the selection target, preserving selections that
are not collapsed and
- * the direction of the selection.
- *
- * @method
- * @param {number} adjustment Distance to adjust the cursor, can be positive
or negative
- * @returns {boolean} Cursor was moved
- */
-ve.ce.Surface.prototype.adjustCursor = function ( adjustment ) {
- // Bypass for zero-adjustment
- if ( !adjustment ) {
- return false;
- }
- var adjustedTargetOffset,
- bias = adjustment > 0 ? 1 : -1,
- selection = this.model.getSelection(),
- targetOffset = selection.to,
- documentModel = this.model.getDocument(),
- relativeContentOffset = documentModel.getRelativeContentOffset(
targetOffset, adjustment ),
- relativeStructuralOffset =
documentModel.getRelativeStructuralOffset(
- targetOffset + bias, adjustment, true
- );
- // Check if we've moved into a slug
- if ( this.hasSlugAtOffset( relativeStructuralOffset ) ) {
- // Check if the relative content offset is in the opposite
direction we are trying to go
- if ( ( relativeContentOffset - targetOffset < 0 ? -1 : 1 ) !==
bias ) {
- // There's nothing past the slug we are already in,
stay in it
- adjustedTargetOffset = relativeStructuralOffset;
- } else {
- // There's a slug neaby, go into it if it's closer
- adjustedTargetOffset = adjustment < 0 ?
- Math.max( relativeContentOffset,
relativeStructuralOffset ) :
- Math.min( relativeContentOffset,
relativeStructuralOffset );
- }
- }
- // Check if we've moved a different distance than we asked for
- else if ( relativeContentOffset !== targetOffset + adjustment ) {
- // We can't trust the browser, move programatically
- adjustedTargetOffset = relativeContentOffset;
- }
- // If the target changed, update the model
- if ( adjustedTargetOffset ) {
- this.model.change(
- null,
- new ve.Range(
- selection.isCollapsed() ?
- adjustedTargetOffset : selection.from,
adjustedTargetOffset
- )
- );
- return true;
- }
- return false;
-};
-
-/**
* Show selection on a range.
*
* @method
--
To view, visit https://gerrit.wikimedia.org/r/55829
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7dd8f4f6eaa688995d33247600875a45fc5a602
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Inez <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits