fix linewidgets interaction with folding

pull/134/merge
nightwing 2015-08-28 03:44:03 +04:00
rodzic 9c91ae4a8c
commit 1ca8dbdd31
2 zmienionych plików z 63 dodań i 20 usunięć

Wyświetl plik

@ -119,7 +119,7 @@ function Folding() {
var folds = this.getFoldsInRange(ranges);
}
return folds;
}
};
/*
* Returns all folds in the document
@ -229,15 +229,15 @@ function Folding() {
end = foldLine.end.row,
start = foldLine.start.row;
if (end >= last) {
if(start < last) {
if(start >= first)
if (start < last) {
if (start >= first)
rowCount -= last-start;
else
rowCount = 0;//in one fold
rowCount = 0; // in one fold
}
break;
} else if(end >= first){
if (start >= first) //fold inside range
} else if (end >= first){
if (start >= first) // fold inside range
rowCount -= end-start;
else
rowCount -= end-first+1;
@ -340,7 +340,7 @@ function Folding() {
// Notify that fold data has changed.
this.$modified = true;
this._emit("changeFold", { data: fold, action: "add" });
this._signal("changeFold", { data: fold, action: "add" });
return fold;
};
@ -401,7 +401,7 @@ function Folding() {
// Notify that fold data has changed.
this.$modified = true;
this._emit("changeFold", { data: fold, action: "remove" });
this._signal("changeFold", { data: fold, action: "remove" });
};
this.removeFolds = function(folds) {
@ -593,7 +593,7 @@ function Folding() {
var placeholder = "...";
if (!range.isMultiLine()) {
placeholder = this.getTextRange(range);
if(placeholder.length < 4)
if (placeholder.length < 4)
return;
placeholder = placeholder.trim().substring(0, 2) + "..";
}
@ -610,7 +610,7 @@ function Folding() {
if (dir != 1) {
do {
token = iterator.stepBackward();
} while(token && re.test(token.type));
} while (token && re.test(token.type));
iterator.stepForward();
}
@ -622,7 +622,7 @@ function Folding() {
if (dir != -1) {
do {
token = iterator.stepForward();
} while(token && re.test(token.type));
} while (token && re.test(token.type));
token = iterator.stepBackward();
} else
token = iterator.getCurrentToken();
@ -698,7 +698,7 @@ function Folding() {
this.off('change', this.$updateFoldWidgets);
this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets);
this._emit("changeAnnotation");
this._signal("changeAnnotation");
if (!foldMode || this.$foldStyle == "manual") {
this.foldWidgets = null;
@ -740,7 +740,7 @@ function Folding() {
range: i !== -1 && range,
firstRange: firstRange
};
}
};
this.onFoldWidgetClick = function(row, e) {
e = e.domEvent;
@ -752,7 +752,7 @@ function Folding() {
var range = this.$toggleFoldWidget(row, options);
if (!range) {
var el = (e.target || e.srcElement)
var el = (e.target || e.srcElement);
if (el && /ace_fold-widget/.test(el.className))
el.className += " ace_invalid";
}
@ -849,7 +849,7 @@ function Folding() {
if (this.foldWidgets.length > rows.first)
this.foldWidgets.splice(rows.first, this.foldWidgets.length);
}
}
};
}
exports.Folding = Folding;

53
node_modules/ace/lib/ace/line_widgets.js wygenerowano vendored
Wyświetl plik

@ -48,6 +48,7 @@ function LineWidgets(session) {
this.$onChangeEditor = this.$onChangeEditor.bind(this);
this.session.on("change", this.updateOnChange);
this.session.on("changeFold", this.updateOnFold);
this.session.on("changeEditor", this.$onChangeEditor);
}
@ -68,8 +69,8 @@ function LineWidgets(session) {
this.$getWidgetScreenLength = function() {
var screenRows = 0;
this.lineWidgets.forEach(function(w){
if (w && w.rowCount)
screenRows +=w.rowCount;
if (w && w.rowCount && !w.hidden)
screenRows += w.rowCount;
});
return screenRows;
};
@ -113,6 +114,32 @@ function LineWidgets(session) {
});
};
this.updateOnFold = function(e, session) {
var lineWidgets = session.lineWidgets;
if (!lineWidgets || !e.action)
return;
var fold = e.data;
var start = fold.start.row;
var end = fold.end.row;
var hide = e.action == "add";
for (var i = start + 1; i < end; i++) {
if (lineWidgets[i])
lineWidgets[i].hidden = hide;
}
if (lineWidgets[end]) {
if (hide) {
if (!lineWidgets[start])
lineWidgets[start] = lineWidgets[end];
else
lineWidgets[end].hidden = hide;
} else {
if (lineWidgets[start] == lineWidgets[end])
lineWidgets[start] = undefined;
lineWidgets[end].hidden = hide;
}
}
};
this.updateOnChange = function(delta) {
var lineWidgets = this.session.lineWidgets;
if (!lineWidgets) return;
@ -175,9 +202,22 @@ function LineWidgets(session) {
if (!w.pixelHeight) {
w.pixelHeight = w.el.offsetHeight;
}
if (w.rowCount == null)
if (w.rowCount == null) {
w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight;
}
if (w.fullWidth) {
w.pixelWidth = w.el.pixelWidth;
}
var fold = this.session.getFoldAt(w.row, 0);
w.$fold = fold;
if (fold) {
var lineWidgets = this.session.lineWidgets;
if (w.row == fold.end.row && !lineWidgets[fold.start.row])
lineWidgets[fold.start.row] = w;
else
w.hidden = true;
}
this.session._emit("changeFold", {data:{start:{row: w.row}}});
this.$updateRows();
@ -260,7 +300,10 @@ function LineWidgets(session) {
for (var i = first; i <= last; i++) {
var w = lineWidgets[i];
if (!w || !w.el) continue;
if (w.hidden) {
w.el.style.top = -100 - (w.pixelHeight || 0) + "px";
continue;
}
if (!w._inDocument) {
w._inDocument = true;
renderer.container.appendChild(w.el);