Divec has uploaded a new change for review.
https://gerrit.wikimedia.org/r/179223
Change subject: Native backspace and delete
......................................................................
Native backspace and delete
Use native backspace and delete actions, provided there is some text in the
direction of the deletion. This is particularly important for delete, which
generally removes an entire grapheme cluster. Backspace usually removes a
single code point (which can be a surrogate pair of code units).
Change-Id: I7f775446675139a0430084b46eda56ddc351721a
---
M src/ce/ve.ce.Surface.js
1 file changed, 22 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/23/179223/1
diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 6eff240..e35bd45 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1087,11 +1087,13 @@
break;
case OO.ui.Keys.BACKSPACE:
case OO.ui.Keys.DELETE:
- e.preventDefault();
if ( selection instanceof ve.dm.LinearSelection ) {
- this.handleLinearDelete( e );
+ if ( this.handleLinearDelete( e ) ) {
+ e.preventDefault();
+ }
updateFromModel = true;
} else if ( selection instanceof ve.dm.TableSelection )
{
+ e.preventDefault();
this.handleTableDelete( e );
}
break;
@@ -2951,9 +2953,11 @@
* Handle delete and backspace key down events with a linear selection.
*
* @param {jQuery.Event} e Delete key down event
+ * @return {bool} whether the delete action was handled in javascript
*/
ve.ce.Surface.prototype.handleLinearDelete = function ( e ) {
var docLength, startNode, tableEditingRange,
+ surfaceObserver = this.surfaceObserver,
direction = e.keyCode === OO.ui.Keys.DELETE ? 1 : -1,
unit = ( e.altKey === true || e.ctrlKey === true ) ? 'word' :
'character',
offset = 0,
@@ -2962,12 +2966,25 @@
data = documentModel.data;
if ( rangeToRemove.isCollapsed() ) {
+ // Use native behaviour then poll, if we are adjacent to some
content
+ // TODO: this may not be safe when CTRL is depressed
+ offset = rangeToRemove.start;
+ if (
+ ( direction === -1 && offset > 0 && !data.getData(
offset - 1 ).type ) ||
+ ( direction === 1 && offset < data.getLength() &&
!data.getData( offset ).type )
+ ) {
+ this.eventSequencer.afterOne( { keydown: function () {
+ surfaceObserver.pollOnce();
+ } } );
+ return false;
+ }
+
// In case when the range is collapsed use the same logic that
is used for cursor left and
// right movement in order to figure out range to remove.
rangeToRemove = documentModel.getRelativeRange( rangeToRemove,
direction, unit, true );
tableEditingRange = this.getActiveTableNode() ?
this.getActiveTableNode().getEditingRange() : null;
if ( tableEditingRange && !tableEditingRange.containsRange(
rangeToRemove ) ) {
- return;
+ return true;
}
offset = rangeToRemove.start;
docLength = data.getLength();
@@ -2980,12 +2997,12 @@
startNode =
documentModel.getDocumentNode().getNodeFromOffset( offset + 1 );
if ( startNode.isFocusable() ) {
this.getModel().setLinearSelection(
startNode.getOuterRange() );
- return;
+ return true;
}
}
if ( rangeToRemove.isCollapsed() ) {
// For instance beginning or end of the document.
- return;
+ return true;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/179223
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f775446675139a0430084b46eda56ddc351721a
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits