Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for eclipse bug 512109 #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions bundles/org.eclipse.orion.client.core/web/orion/bidiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ define ([
],
function(util) { /* BDL */

var bidiEnabledStorage = "/orion/preferences/bidi/bidiEnabled"; //$NON-NLS-0$
var bidiLayoutStorage = "/orion/preferences/bidi/bidiLayout"; //$NON-NLS-0$
var LRE = "\u202A"; //$NON-NLS-0$
var PDF = "\u202C"; //$NON-NLS-0$
var RLE = "\u202B"; //$NON-NLS-0$

function setBrowserLangDirection() {

var lang;
Expand All @@ -29,7 +23,7 @@ function(util) { /* BDL */
}
var isBidi = lang && "ar iw he".indexOf(lang.substring(0, 2)) !== - 1;

if (isBidi && isBidiEnabled()) {
if (isBidi) {
var htmlElement = document.getElementsByTagName("html")[0];
if (htmlElement){ //should be always true
htmlElement.setAttribute ("dir", "rtl");
Expand All @@ -39,6 +33,12 @@ function(util) { /* BDL */

setBrowserLangDirection();

var bidiEnabledStorage = "/orion/preferences/bidi/bidiEnabled"; //$NON-NLS-0$
var bidiLayoutStorage = "/orion/preferences/bidi/bidiLayout"; //$NON-NLS-0$
var LRE = "\u202A"; //$NON-NLS-0$
var PDF = "\u202C"; //$NON-NLS-0$
var RLE = "\u202B"; //$NON-NLS-0$

var bidiLayout = getBidiLayout();

/**
Expand Down Expand Up @@ -146,7 +146,16 @@ function(util) { /* BDL */
}
}

function enforceTextDir(range) {
function createNewStyle ( oldStyle, textDir ) {
var newStyle = oldStyle;
if (typeof newStyle.attributes === "undefined") {
newStyle.attributes = {};
}
newStyle.attributes.dir = textDir;
return newStyle;
}

function enforceTextDir( range, textDir ) {
var comments = [{name:"comment block"},
{name:"comment line double-slash"},
{name:"comment block documentation"},
Expand All @@ -163,13 +172,17 @@ function(util) { /* BDL */
var newStyle = style;
if (typeof newStyle.attributes === "undefined") {
newStyle.attributes = {};
}
newStyle.attributes.dir = getTextDirection(text);
range.style = newStyle;
}
range.style = createNewStyle( style, getTextDirection(text) );
return range;
}
}
}
else if (style && textDir && textDir.length > 0) {
range.style = createNewStyle( style, textDir );
return range;
}

return range;
}

Expand Down
7 changes: 6 additions & 1 deletion bundles/org.eclipse.orion.client.core/web/orion/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ define(function() {
var isTouch = typeof document !== "undefined" && "ontouchstart" in document.createElement("input"); //$NON-NLS-1$ //$NON-NLS-0$

var platformDelimiter = isWindows ? "\r\n" : "\n"; //$NON-NLS-1$ //$NON-NLS-0$
var LtrMarker = "\u202A\u202A\u202A\u202A\u202A"; //$NON-NLS-0$
var RtlMarker = "\u202B\u202B\u202B\u202B\u202B"; //$NON-NLS-0$

function formatMessage(msg) {
var args = arguments;
Expand Down Expand Up @@ -85,6 +87,9 @@ define(function() {
/** Capabilities */
isTouch: isTouch,

platformDelimiter: platformDelimiter
platformDelimiter: platformDelimiter,
LtrMarker: LtrMarker,
RtlMarker: RtlMarker

};
});
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ define("orion/editor/keyModes", [ //$NON-NLS-0$
bindings.push({actionID: "escape", keyBinding: new KeyBinding(27), predefined: true}); //$NON-NLS-0$
bindings.push({actionID: "selectAll", keyBinding: new KeyBinding('a', true), predefined: true}); //$NON-NLS-1$ //$NON-NLS-0$
bindings.push({actionID: "toggleTabMode", keyBinding: new KeyBinding('m', true), predefined: true}); //$NON-NLS-1$ //$NON-NLS-0$
bindings.push({actionID: "dirLTR", keyBinding: new KeyBinding(36, null, true, true), predefined: true}); //$NON-NLS-0$
bindings.push({actionID: "dirRTL", keyBinding: new KeyBinding(35, null, true, true), predefined: true}); //$NON-NLS-0$
if (util.isMac) {
bindings.push({actionID: "deleteNext", keyBinding: new KeyBinding(46, null, true), predefined: true}); //$NON-NLS-0$
bindings.push({actionID: "deleteWordPrevious", keyBinding: new KeyBinding(8, null, null, true), predefined: true}); //$NON-NLS-0$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ define({//Default message bundle
"toggleWrapMode": "Toggle Wrap Mode", //$NON-NLS-1$ //$NON-NLS-0$
"toggleTabMode": "Toggle Tab Mode", //$NON-NLS-1$ //$NON-NLS-0$
"toggleOverwriteMode": "Toggle Overwrite Mode", //$NON-NLS-1$ //$NON-NLS-0$
"dirLTR": "Set Left to Right Text Direction", //$NON-NLS-1$ //$NON-NLS-0$
"dirRTL": "Set Right to Left Text Direction", //$NON-NLS-1$ //$NON-NLS-0$

"committerOnTime": "${0} on ${1}", //$NON-NLS-1$ //$NON-NLS-0$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ define("orion/editor/projectionTextModel", ['orion/editor/textModel', 'orion/edi
getLineDelimiter: function() {
return this._model.getLineDelimiter();
},
/**
* @see orion.editor.TextModel#getLineTextDir
*/
getLineTextDir: function(lineIndex) {
return this._model.getLineTextDir(lineIndex);
},
/**
* @see orion.editor.TextModel#getTextForSave
*/
getTextForSave: function() {
return this._model.getTextForSave();
},
/**
* @see orion.editor.TextModel#getLineEnd
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ define("orion/editor/textModel", ['orion/editor/eventTarget', 'orion/regex', 'or
this._lastLineIndex = -1;
this._text = [""];
this._lineOffsets = [0];
this._textDirs = [""];
this.setText(text);
this.setLineDelimiter(lineDelimiter);
}
Expand Down Expand Up @@ -370,6 +371,23 @@ define("orion/editor/textModel", ['orion/editor/eventTarget', 'orion/regex', 'or
}
return this._lineOffsets[lineIndex];
},
/**
* Returns the text direction of the given line.
* <p>
* The valid indices are 0 to line count exclusive. Returns <code>""</code>
* if the index is out of range.
* </p>
*
* @param {Number} lineIndex the zero based index of the line.
* @return {String} the text direction of the line<code>""</code> if out of range.
*
*/
getLineTextDir: function(lineIndex) {
if (!(0 <= lineIndex && lineIndex < this.getLineCount())) {
return "";
}
return this._textDirs[lineIndex];
},
/**
* Returns the text for the given range.
* <p>
Expand Down Expand Up @@ -416,6 +434,23 @@ define("orion/editor/textModel", ['orion/editor/eventTarget', 'orion/regex', 'or
var afterText = this._text[lastChunk].substring(0, end - lastOffset);
return beforeText + this._text.slice(firstChunk+1, lastChunk).join("") + afterText;
},
/**
* Returns the whole text for save. We keep the text direction of each line by adding the ltr/rtl marker.
*
*/
getTextForSave: function() {
var text = "";
for (var i = 0; i<this.getLineCount(); i++) {
if (this._textDirs[i] === "ltr") {
text += util.LtrMarker + this.getLine(i, true);
} else if (this._textDirs[i] === "rtl") {
text += util.RtlMarker + this.getLine(i, true);
} else {
text += this.getLine(i, true);
}
}
return text;
},
/**
* Notifies all listeners that the text is about to change.
* <p>
Expand Down Expand Up @@ -508,6 +543,8 @@ define("orion/editor/textModel", ['orion/editor/eventTarget', 'orion/regex', 'or
if (start === undefined) { start = 0; }
if (end === undefined) { end = this.getCharCount(); }
if (start === end && text === "") { return; }
var ltrMarker = util.LtrMarker;
var rtlMarker = util.RtlMarker;
var startLine = this.getLineAtOffset(start);
var endLine = this.getLineAtOffset(end);
var eventStart = start;
Expand All @@ -517,12 +554,21 @@ define("orion/editor/textModel", ['orion/editor/eventTarget', 'orion/regex', 'or
var addedLineCount = 0;
var lineCount = this.getLineCount();

var cr = 0, lf = 0, index = 0;
var cr = 0, lf = 0, index = 0, shift = 0;
var newLineOffsets = [];
while (true) {
var newTextDirs = [];
var origText = text;


while (true) {
if (cr !== -1 && cr <= index) { cr = text.indexOf("\r", index); } //$NON-NLS-0$
if (lf !== -1 && lf <= index) { lf = text.indexOf("\n", index); } //$NON-NLS-0$
if (lf === -1 && cr === -1) { break; }
if (text.substr(index, ltrMarker.length) == ltrMarker) {
shift += ltrMarker.length;
} else if (text.substr(index, rtlMarker.length) == rtlMarker) {
shift += rtlMarker.length;
}
if (cr !== -1 && lf !== -1) {
if (cr + 1 === lf) {
index = lf + 1;
Expand All @@ -534,8 +580,20 @@ define("orion/editor/textModel", ['orion/editor/eventTarget', 'orion/regex', 'or
} else {
index = lf + 1;
}
newLineOffsets.push(start + index);
newLineOffsets.push(start + index - shift);
addedLineCount++;
if (text.substr(index, ltrMarker.length) == ltrMarker) {
newTextDirs.push("ltr"); //$NON-NLS-0$
} else if (text.substr(index, rtlMarker.length) == rtlMarker) {
newTextDirs.push("rtl"); //$NON-NLS-0$
} else {
newTextDirs.push(""); //$NON-NLS-0$
}
}
if (text !== ltrMarker && text !== rtlMarker) {
var re1 = new RegExp(ltrMarker, "g"), re2 = new RegExp(rtlMarker, "g");
text = text.replace(re1, "").replace(re2, "");
addedCharCount = text.length;
}

var modelChangingEvent = {
Expand Down Expand Up @@ -582,16 +640,26 @@ define("orion/editor/textModel", ['orion/editor/eventTarget', 'orion/regex', 'or
if (newLineOffsets.length < limit) {
args = [startLine + 1, removedLineCount].concat(newLineOffsets);
Array.prototype.splice.apply(this._lineOffsets, args);
args = [startLine + 1, removedLineCount].concat(newTextDirs);
Array.prototype.splice.apply(this._textDirs, args);
} else {
index = startLine + 1;
this._lineOffsets.splice(index, removedLineCount);
for (var k = 0; k < newLineOffsets.length; k += limit) {
args = [index, 0].concat(newLineOffsets.slice(k, Math.min(newLineOffsets.length, k + limit)));
Array.prototype.splice.apply(this._lineOffsets, args);
args = [index, 0].concat(newTextDirs.slice(k, Math.min(newTextDirs.length, k + limit)));
Array.prototype.splice.apply(this._textDirs, args);
index += limit;
}
}

if (origText.indexOf(ltrMarker) == 0) {
this._textDirs[startLine] = "ltr"; //$NON-NLS-0$
} else if (origText.indexOf(rtlMarker) == 0) {
this._textDirs[startLine] = "rtl"; //$NON-NLS-0$
}

var offset = 0, chunk = 0, length;
while (chunk<this._text.length) {
length = this._text[chunk].length;
Expand Down
Loading