Divec has uploaded a new change for review.
https://gerrit.wikimedia.org/r/179203
Change subject: Get CSS directionality from selected node
......................................................................
Get CSS directionality from selected node
Previously, the CSS directionality was read from the keydown event target,
which was generally the top-level contenteditable div. This is incorrect if
a descendent node has a different CSS directionality.
TODO: Handle directionality boundaries within plaintext
Change-Id: I54b7fef29efec8398ed0d0e5883a7a895e81f046
---
M demos/ve/pages/rtl.html
M src/ce/ve.ce.Surface.js
2 files changed, 25 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/03/179203/1
diff --git a/demos/ve/pages/rtl.html b/demos/ve/pages/rtl.html
index 1306780..dcd1076 100644
--- a/demos/ve/pages/rtl.html
+++ b/demos/ve/pages/rtl.html
@@ -1,3 +1,8 @@
+<p dir="ltr">1. A shprakh <img src="shprakh"> iz a dialekt mit an armey un
flot</p>
+<p dir="ltr">2. אַ שפּראַך <img src="shprakh"> איז אַ דיאַלעקט מיט אַן אַרמיי
און פֿלאָט</p>
+<p dir="rtl">3. A shprakh <img src="shprakh"> iz a dialekt mit an armey un
flot</p>
+<p dir="rtl">4. אַ שפּראַך <img src="shprakh"> איז אַ דיאַלעקט מיט אַן אַרמיי
און פֿלאָט</p>
+
<p><b>שכל אם כיצד פיסול.</b> הראשי תחבורה נוסחאות של אתה, עמוד שינויים תיאטרון
מתן מה. סדר אל שאלות עסקים, אתה אם יכול מוסיקה ספינות, הרוח קהילה מה מתן. כדי
אם הבקשה משחקים לטיפול. הבאים רשימות של כדי, דת אנא יכול מיזמים. צ'ט של ערכים
לעריכת לויקיפדיה.</p>
<p>ובמתן המלצת אחר על, <a href="העיר">גם ויש העיר בעברית</a>. שמו על מיזם
ספורט תחבורה, על לוח העמוד לויקיפדיה. כדור ערבית גם רבה, הראשי למתחילים
סטטיסטיקה מה כלל. ארץ את מדעי תחבורה סטטיסטיקה. מדעי עסקים לחיבור גם כתב, את
זכר חינוך ליצירתה.</p>
diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 6eff240..768c2b1 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -2489,7 +2489,8 @@
* @param {jQuery.Event} e Left or right key down event
*/
ve.ce.Surface.prototype.handleLinearLeftOrRightArrowKey = function ( e ) {
- var direction, range = this.getModel().getSelection().getRange();
+ var direction, cursorNode, directionality,
+ range = this.getModel().getSelection().getRange();
// On Mac OS pressing Command (metaKey) + Left/Right is same as
pressing Home/End.
// As we are not able to handle it programmatically (because we don't
know at which offsets
@@ -2508,11 +2509,25 @@
} finally {
this.decRenderLock();
}
- if ( this.$( e.target ).css( 'direction' ) === 'rtl' ) {
- // If the language direction is RTL, switch left/right
directions:
- direction = e.keyCode === OO.ui.Keys.LEFT ? 1 : -1;
+
+ // Read the CSS directionality of the node at the cursor
+ // TODO: handle plaintext bidi better
+ cursorNode = this.nativeSelection.focusNode;
+ if ( OO.ui.contains( this.$pasteTarget[0], cursorNode, true ) ) {
+ // Using emulated selection; get cursorNode from DM selection
+ cursorNode = this.getDocument().getNodeAndOffset( range.from
).node;
+ }
+ if ( cursorNode.nodeType === Node.TEXT_NODE ) {
+ cursorNode = cursorNode.parentNode;
+ }
+ directionality = this.$( cursorNode ).css( 'direction' ) || 'ltr';
+ /*jshint bitwise:false */
+ if ( e.keyCode === OO.ui.Keys.LEFT ^ directionality === 'rtl' ) {
+ // leftarrow in ltr, or rightarrow in rtl
+ direction = -1;
} else {
- direction = e.keyCode === OO.ui.Keys.LEFT ? -1 : 1;
+ // leftarrow in rtl, or rightarrow in ltr
+ direction = 1;
}
range = this.model.getDocument().getRelativeRange(
--
To view, visit https://gerrit.wikimedia.org/r/179203
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I54b7fef29efec8398ed0d0e5883a7a895e81f046
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