Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 514792 - AnnotationStyler to merge html and DOM node style in com…
…pare widget.
  • Loading branch information
libingw committed Jun 22, 2017
1 parent 2962df6 commit cb48ab8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 62 deletions.
Expand Up @@ -585,7 +585,7 @@ define("orion/editor/annotations", ['i18n!orion/editor/nls/messages', 'orion/edi
skip = function() {
while (i < annotations.length) {
var a = annotations[i++];
if ((start === a.start) || (start > a.start ? start < a.end : a.start < end)) {
if ((start === a.start) || (a.start === a.end && a.end === end) || (start > a.start ? start < a.end : a.start < end)) {
return a;
}
if (a.start >= end) {
Expand Down
Expand Up @@ -651,8 +651,9 @@ define("orion/editor/textView", [ //$NON-NLS-1$
}
TextLine.prototype = /** @lends orion.editor.TextLine.prototype */ {
/** @private */
create: function(_parent, div) {
create: function(_parent, div, drawing) {
if (this._lineDiv) { return; }
this.drawing = drawing;
var child = this._lineDiv = this._createLine(_parent, div, this.lineIndex);
child._line = this;
return child;
Expand Down Expand Up @@ -889,7 +890,11 @@ define("orion/editor/textView", [ //$NON-NLS-1$
child.innerHTML = style.html;
child.ignore = true;
} else if (style && style.node) {
child.appendChild(style.node);
if (this.drawing) {
child.appendChild(style.node);
} else {
child.appendChild(style.node.cloneNode(true));
}
child.ignore = true;
} else if (style && style.bidi) {
child.ignore = true;
Expand Down Expand Up @@ -7481,14 +7486,14 @@ define("orion/editor/textView", [ //$NON-NLS-1$
var frag = doc.createDocumentFragment();
for (lineIndex=lineStart; lineIndex<=lineEnd; lineIndex++) {
if (!child || child.lineIndex > lineIndex) {
new TextLine(this, lineIndex).create(frag, null);
new TextLine(this, lineIndex).create(frag, null, true);
} else {
if (frag.firstChild) {
clientDiv.insertBefore(frag, child);
frag = doc.createDocumentFragment();
}
if (child && child.lineChanged) {
child = new TextLine(this, lineIndex).create(frag, child);
child = new TextLine(this, lineIndex).create(frag, child, true);
child.lineChanged = false;
}
child = this._getLineNext(child);
Expand Down
Expand Up @@ -10,7 +10,7 @@
******************************************************************************/

/*eslint-env browser, amd*/
define(['orion/compare/compareUtils'], function(mCompareUtils) {
define(['orion/compare/compareUtils', 'orion/editor/rulers', 'orion/objects'], function(mCompareUtils, mRulers, Object) {
var orion = orion || {};

orion.CompareRuler = (function() {
Expand All @@ -19,46 +19,10 @@ orion.CompareRuler = (function() {
* @class The compare ruler is used by the compare editor to render trim around the editor.
* @name orion.compare.rulers.CompareRuler
*/
function CompareRuler (rulerLocation, rulerOverview, rulerStyle) {
this._location = rulerLocation || "left"; //$NON-NLS-0$
this._overview = rulerOverview || "page"; //$NON-NLS-0$
this._rulerStyle = rulerStyle;
this._editor = null;
var self = this;
this._listener = {
onModelChanged: function(e) {
self._onModelChanged(e);
}
};
function CompareRuler (annoModel, rulerLocation, rulerOverview, rulerStyle) {
mRulers.Ruler.call(this, annoModel, rulerLocation, rulerOverview, rulerStyle);
}
CompareRuler.prototype = /** @lends orion.compare.rulers.CompareRuler.prototype */ {
setView: function (editor) {
if (this._onModelChanged && this._editor) {
this._editor.removeEventListener("ModelChanged", this._listener.onModelChanged); //$NON-NLS-0$
}
this._editor = editor;
if (this._onModelChanged && this._editor) {
this._editor.addEventListener("ModelChanged", this._listener.onModelChanged); //$NON-NLS-0$
}
},
getLocation: function() {
return this._location;
},
getOverview: function(editor) {
return this._overview;
},
getAnnotationModel: function() {
return null;
},
addAnnotationType: function(type) {
},
isAnnotationTypeVisible: function(type) {
return false;
},
removeAnnotationType: function(type) {
},
setAnnotationModel: function (annotationModel) {
},
CompareRuler.prototype = Object.mixin(new mRulers.Ruler(), /** @lends orion.compare.rulers.CompareRuler.prototype */ {
getAnnotations: function(startLine, endLine) {
var result = [];
for (var i=startLine; i<endLine; i++) {
Expand All @@ -75,7 +39,7 @@ orion.CompareRuler = (function() {
getRulerStyle: function() {
return this.getStyle(undefined);
}
};
});
return CompareRuler;
}());

Expand All @@ -85,8 +49,8 @@ orion.LineNumberCompareRuler = (function() {
* @class The line number ruler is used by the compare editor to render line numbers next to the editor
* @name orion.compare.rulers.LineNumberCompareRuler
*/
function LineNumberCompareRuler (diffNavigator, mapperColumnIndex , rulerLocation, rulerStyle, oddStyle, evenStyle) {
orion.CompareRuler.call(this, rulerLocation, "page", rulerStyle); //$NON-NLS-0$
function LineNumberCompareRuler (diffNavigator, mapperColumnIndex , annoModel, rulerLocation, rulerStyle, oddStyle, evenStyle) {
orion.CompareRuler.call(this, annoModel, rulerLocation, "page", rulerStyle); //$NON-NLS-0$
this._diffNavigator = diffNavigator;
this._oddStyle = oddStyle || {style: {backgroundColor: "white"}}; //$NON-NLS-0$
this._evenStyle = evenStyle || {style: {backgroundColor: "white"}}; //$NON-NLS-0$
Expand All @@ -102,7 +66,7 @@ orion.LineNumberCompareRuler = (function() {
}
};
LineNumberCompareRuler.prototype.getHTML = function(lineIndex) {
var model = this._editor.getModel();
var model = this._view.getModel();
var diffFeeder = this._diffNavigator.getFeeder(this._mapperColumnIndex === 0);
if(!diffFeeder){
return "";
Expand All @@ -122,23 +86,23 @@ orion.LineNumberCompareRuler = (function() {
};
LineNumberCompareRuler.prototype._onModelChanged = function(e) {
var start = e.start;
var model = this._editor.getModel();
var model = this._view.getModel();
var lineCount = model.getLineCount();
var numOfDigits = (lineCount+"").length;
if (this._numOfDigits !== numOfDigits) {
this._numOfDigits = numOfDigits;
var startLine = model.getLineAtOffset(start);
this._editor.redrawLines(startLine, lineCount, this);
this._view.redrawLines(startLine, lineCount, this);
}
};
return LineNumberCompareRuler;
}());

orion.CompareOverviewRuler = (function() {
function CompareOverviewRuler ( rulerLocation, rulerStyle , diffNavigator , onClick) {
function CompareOverviewRuler ( annoModel, rulerLocation, rulerStyle , diffNavigator , onClick) {
this._diffNavigator = diffNavigator;
this._onClick = onClick;
orion.CompareRuler.call(this, rulerLocation, "document", rulerStyle); //$NON-NLS-0$
orion.CompareRuler.call(this, annoModel, rulerLocation, "document", rulerStyle); //$NON-NLS-0$
}
CompareOverviewRuler.prototype = new orion.CompareRuler();
CompareOverviewRuler.prototype.getStyle = function(lineIndex) {
Expand Down Expand Up @@ -187,7 +151,7 @@ orion.CompareOverviewRuler = (function() {
if(anH < 0){
return null;
}
var clientArea = this._editor.getClientArea();
var clientArea = this._view.getClientArea();
var height = Math.floor(clientArea.height*anH/lC);
if (height < 2){
height = 2;
Expand All @@ -210,10 +174,10 @@ orion.CompareOverviewRuler = (function() {
this._onClick(lineIndex , this);
};
CompareOverviewRuler.prototype._onModelChanged = function(e) {
var model = this._editor.getModel();
var model = this._view.getModel();
var lineCount = model.getLineCount();
if(lineCount > 0){
this._editor.redrawLines(0, 1, this);
this._view.redrawLines(0, 1, this);
}
};
return CompareOverviewRuler;
Expand Down
Expand Up @@ -377,7 +377,7 @@ exports.TwoWayCompareView = (function() {
//Create editor on the left side
this._editors.push(this._createEditor(initString, this._uiFactory.getEditorParentDiv(true), this._uiFactory.getStatusDiv(true), this.options.newFile, true));
//Create the overview ruler
this._overviewRuler = new mCompareRulers.CompareOverviewRuler("right", {styleClass: "ruler overview"} , null, //$NON-NLS-1$ //$NON-NLS-0$
this._overviewRuler = new mCompareRulers.CompareOverviewRuler(this._editors[1].getAnnotationModel(), "right", {styleClass: "ruler overview"} , null, //$NON-NLS-1$ //$NON-NLS-0$
function(lineIndex, ruler){this._diffNavigator.matchPositionFromOverview(lineIndex);}.bind(this));
//If either editor is dirty, popup the warning message.
if(this.options.postCreate) {
Expand Down Expand Up @@ -583,8 +583,8 @@ exports.TwoWayCompareView = (function() {

TwoWayCompareView.prototype.addRulers = function(){
if(this._editors && !this._hasRuler){
var lRuler = new mCompareRulers.LineNumberCompareRuler(this._diffNavigator, 0, "left", {styleClass: "ruler lines"}, {styleClass: "rulerLines odd"}, {styleClass: "rulerLines even"}); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
var rRuler = new mCompareRulers.LineNumberCompareRuler(this._diffNavigator, 0, "left", {styleClass: "ruler lines"}, {styleClass: "rulerLines odd"}, {styleClass: "rulerLines even"}); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
var lRuler = new mCompareRulers.LineNumberCompareRuler(this._diffNavigator, 0, this._editors[0].getAnnotationModel(), "left", {styleClass: "ruler lines"}, {styleClass: "rulerLines odd"}, {styleClass: "rulerLines even"}); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
var rRuler = new mCompareRulers.LineNumberCompareRuler(this._diffNavigator, 0, this._editors[1].getAnnotationModel(), "left", {styleClass: "ruler lines"}, {styleClass: "rulerLines odd"}, {styleClass: "rulerLines even"}); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
this._editors[1].getTextView().addRuler(lRuler);
this._editors[0].getTextView().addRuler(rRuler);
this._editors[0].getTextView().addRuler(this._overviewRuler);
Expand Down Expand Up @@ -823,9 +823,9 @@ exports.InlineCompareView = (function() {

this._textView = this._editor.getTextView();

this._rulerOrigin = new mCompareRulers.LineNumberCompareRuler(this._diffNavigator, 1,"left", {styleClass: "ruler lines inlineRulerLeft"}, {styleClass: "rulerLines odd"}, {styleClass: "rulerLines even"}); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
this._rulerNew = new mCompareRulers.LineNumberCompareRuler(this._diffNavigator, 0,"left", {styleClass: "ruler lines"}, {styleClass: "rulerLines odd"}, {styleClass: "rulerLines even"}); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
this._overviewRuler = new mCompareRulers.CompareOverviewRuler("right", {styleClass: "ruler overview"} , null, //$NON-NLS-1$ //$NON-NLS-0$
this._rulerOrigin = new mCompareRulers.LineNumberCompareRuler(this._diffNavigator, 1, this._editor.getAnnotationModel(), "left", {styleClass: "ruler lines inlineRulerLeft"}, {styleClass: "rulerLines odd"}, {styleClass: "rulerLines even"}); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
this._rulerNew = new mCompareRulers.LineNumberCompareRuler(this._diffNavigator, 0, this._editor.getAnnotationModel(), "left", {styleClass: "ruler lines"}, {styleClass: "rulerLines odd"}, {styleClass: "rulerLines even"}); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
this._overviewRuler = new mCompareRulers.CompareOverviewRuler(this._editor.getAnnotationModel(), "right", {styleClass: "ruler overview"} , null, //$NON-NLS-1$ //$NON-NLS-0$
function(lineIndex, ruler){this._diffNavigator.matchPositionFromOverview(lineIndex);}.bind(this));

this._textView.addEventListener("Selection", function(evt){ //$NON-NLS-0$
Expand Down

0 comments on commit cb48ab8

Please sign in to comment.