Divec has uploaded a new change for review.
https://gerrit.wikimedia.org/r/83977
Change subject: Fix pawn on pre-annotation and keypress
......................................................................
Fix pawn on pre-annotation and keypress
modules/ve/ce/ve.ce.SurfaceObserver.js
* pollOnceNoEmit method to update SurfaceObserver's benchmark text
modules/ve/ce/ve.ce.Surface.js
* pollOnceNoEmit from onUnlock
Change-Id: Idb14a6aea723c42109b3825478766799d4abef22
---
M modules/ve/ce/ve.ce.Surface.js
M modules/ve/ce/ve.ce.SurfaceObserver.js
2 files changed, 45 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/77/83977/1
diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js
index fbefcf3..99c59ff 100644
--- a/modules/ve/ce/ve.ce.Surface.js
+++ b/modules/ve/ce/ve.ce.Surface.js
@@ -1158,7 +1158,7 @@
*/
ve.ce.Surface.prototype.onUnlock = function () {
this.surfaceObserver.locked = false;
- // TODO: should we pollOnce?
+ this.surfaceObserver.pollOnceNoEmit();
};
/*! Relocation */
diff --git a/modules/ve/ce/ve.ce.SurfaceObserver.js
b/modules/ve/ce/ve.ce.SurfaceObserver.js
index 0e114e1..d0637be 100644
--- a/modules/ve/ce/ve.ce.SurfaceObserver.js
+++ b/modules/ve/ce/ve.ce.SurfaceObserver.js
@@ -125,8 +125,6 @@
/**
* Poll for changes.
*
- * If `postpone` is false or undefined then polling will occcur immediately.
- *
* TODO: fixing selection in certain cases, handling selection across multiple
nodes in Firefox
*
* FIXME: Does not work well (selectionChange is not emitted) when cursor is
placed inside a slug
@@ -137,6 +135,34 @@
* @emits selectionChange
*/
ve.ce.SurfaceObserver.prototype.pollOnce = function () {
+ this.pollOnceInternal( true );
+};
+
+/**
+ * Poll to update SurfaceObserver, but don't emit change events
+ *
+ * @method
+ */
+
+ve.ce.SurfaceObserver.prototype.pollOnceNoEmit = function () {
+ this.pollOnceInternal( false );
+};
+
+/**
+ * Poll for changes.
+ *
+ * TODO: fixing selection in certain cases, handling selection across multiple
nodes in Firefox
+ *
+ * FIXME: Does not work well (selectionChange is not emitted) when cursor is
placed inside a slug
+ * with a mouse.
+ *
+ * @method
+ * @private
+ * @param {boolean} emitChanges Emit change events if selection changed
+ * @emits contentChange
+ * @emits selectionChange
+ */
+ve.ce.SurfaceObserver.prototype.pollOnceInternal = function ( emitChanges ) {
var $nodeOrSlug, node, text, hash, range, rangyRange;
range = this.range;
@@ -169,12 +195,15 @@
text = ve.ce.getDomText( node.$[0] );
hash = ve.ce.getDomHash( node.$[0] );
if ( this.text !== text || this.hash !== hash ) {
- this.emit(
- 'contentChange',
- node,
- { 'text': this.text, 'hash': this.hash,
'range': this.range },
- { 'text': text, 'hash': hash, 'range': range }
- );
+ if ( emitChanges ) {
+ this.emit(
+ 'contentChange',
+ node,
+ { 'text': this.text, 'hash': this.hash,
+ 'range': this.range },
+ { 'text': text, 'hash': hash, 'range':
range }
+ );
+ }
this.text = text;
this.hash = hash;
}
@@ -182,11 +211,13 @@
// Only emit selectionChange event if there's a meaningful range
difference
if ( ( this.range && range ) ? !this.range.equals( range ) : (
this.range !== range ) ) {
- this.emit(
- 'selectionChange',
- this.range,
- range
- );
+ if ( emitChanges ) {
+ this.emit(
+ 'selectionChange',
+ this.range,
+ range
+ );
+ }
this.range = range;
}
};
--
To view, visit https://gerrit.wikimedia.org/r/83977
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idb14a6aea723c42109b3825478766799d4abef22
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits