Merge pull request #988 from ajaxorg/fix/line-highlight
Fix/line highlight
This commit is contained in:
commit
4618b2aa06
4 changed files with 69 additions and 56 deletions
|
|
@ -375,14 +375,7 @@ var EditSession = function(text, mode) {
|
|||
token.start = c - token.value.length;
|
||||
return token;
|
||||
};
|
||||
|
||||
this.highlight = function(re) {
|
||||
if (!this.$searchHighlight) {
|
||||
var highlight = new SearchHighlight(null, "ace_selected-word", "text");
|
||||
this.$searchHighlight = this.addDynamicMarker(highlight);
|
||||
}
|
||||
this.$searchHighlight.setRegexp(re);
|
||||
}
|
||||
|
||||
/**
|
||||
* EditSession.setUndoManager(undoManager)
|
||||
* - undoManager (UndoManager): The new undo manager
|
||||
|
|
@ -736,6 +729,30 @@ var EditSession = function(text, mode) {
|
|||
return inFront ? this.$frontMarkers : this.$backMarkers;
|
||||
};
|
||||
|
||||
this.highlight = function(re) {
|
||||
if (!this.$searchHighlight) {
|
||||
var highlight = new SearchHighlight(null, "ace_selected-word", "text");
|
||||
this.$searchHighlight = this.addDynamicMarker(highlight);
|
||||
}
|
||||
this.$searchHighlight.setRegexp(re);
|
||||
}
|
||||
|
||||
// experimental
|
||||
this.highlightLines = function(startRow, endRow, clazz, inFront) {
|
||||
if (typeof endRow != "number") {
|
||||
clazz = endRow;
|
||||
endRow = startRow;
|
||||
}
|
||||
if (!clazz)
|
||||
clazz = "ace_step";
|
||||
|
||||
var range = new Range(startRow, 0, endRow, Infinity);
|
||||
|
||||
var id = this.addMarker(range, clazz, "fullLine", inFront);
|
||||
range.id = id;
|
||||
return range;
|
||||
},
|
||||
|
||||
/*
|
||||
* Error:
|
||||
* {
|
||||
|
|
|
|||
|
|
@ -481,28 +481,24 @@ var Editor = function(renderer, session) {
|
|||
this.$updateHighlightActiveLine = function() {
|
||||
var session = this.getSession();
|
||||
|
||||
if (session.$highlightLineMarker)
|
||||
session.removeMarker(session.$highlightLineMarker);
|
||||
|
||||
session.$highlightLineMarker = null;
|
||||
|
||||
var highlight;
|
||||
if (this.$highlightActiveLine) {
|
||||
var cursor = this.getCursorPosition();
|
||||
var foldLine = this.session.getFoldLine(cursor.row);
|
||||
if ((this.$selectionStyle != "line" || !this.selection.isMultiLine()))
|
||||
highlight = this.getCursorPosition();
|
||||
}
|
||||
|
||||
if ((this.getSelectionStyle() != "line" || !this.selection.isMultiLine())) {
|
||||
var range;
|
||||
if (foldLine) {
|
||||
range = new Range(foldLine.start.row, 0, foldLine.end.row + 1, 0);
|
||||
} else {
|
||||
range = new Range(cursor.row, 0, cursor.row+1, 0);
|
||||
}
|
||||
session.$highlightLineMarker = session.addMarker(range, "ace_active-line", "background");
|
||||
}
|
||||
if (session.$highlightLineMarker && !highlight) {
|
||||
session.removeMarker(session.$highlightLineMarker.id);
|
||||
session.$highlightLineMarker = null;
|
||||
} else if (!session.$highlightLineMarker && highlight) {
|
||||
session.$highlightLineMarker = session.highlightLines(highlight.row, highlight.row, "ace_active-line");
|
||||
} else if (highlight) {
|
||||
session.$highlightLineMarker.start.row = highlight.row;
|
||||
session.$highlightLineMarker.end.row = highlight.row;
|
||||
session._emit("changeBackMarker");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.onSelectionChange = function(e) {
|
||||
var session = this.session;
|
||||
|
||||
|
|
|
|||
|
|
@ -153,8 +153,7 @@ var Cursor = function(parentEl) {
|
|||
if (!position)
|
||||
position = this.session.selection.getCursor();
|
||||
var pos = this.session.documentToScreenPosition(position);
|
||||
var cursorLeft = Math.round(this.$padding +
|
||||
pos.column * this.config.characterWidth);
|
||||
var cursorLeft = this.$padding + pos.column * this.config.characterWidth;
|
||||
var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
|
||||
this.config.lineHeight;
|
||||
|
||||
|
|
|
|||
|
|
@ -78,26 +78,20 @@ var Marker = function(parentEl) {
|
|||
range = range.toScreenRange(this.session);
|
||||
if (marker.renderer) {
|
||||
var top = this.$getTop(range.start.row, config);
|
||||
var left = Math.round(
|
||||
this.$padding + range.start.column * config.characterWidth
|
||||
);
|
||||
var left = this.$padding + range.start.column * config.characterWidth;
|
||||
marker.renderer(html, range, left, top, config);
|
||||
}
|
||||
if (marker.type == "fullLine") {
|
||||
this.drawFullLineMarker(html, range, marker.clazz, config);
|
||||
}
|
||||
else if (range.isMultiLine()) {
|
||||
if (marker.type == "text") {
|
||||
if (marker.type == "text")
|
||||
this.drawTextMarker(html, range, marker.clazz, config);
|
||||
} else {
|
||||
this.drawMultiLineMarker(
|
||||
html, range, marker.clazz, config,
|
||||
marker.type
|
||||
);
|
||||
}
|
||||
else
|
||||
this.drawMultiLineMarker(html, range, marker.clazz, config);
|
||||
}
|
||||
else {
|
||||
this.drawSingleLineMarker(
|
||||
html, range, marker.clazz + " ace_start", config,
|
||||
null, marker.type
|
||||
);
|
||||
this.drawSingleLineMarker(html, range, marker.clazz + " ace_start", config);
|
||||
}
|
||||
}
|
||||
this.element = dom.setInnerHtml(this.element, html.join(""));
|
||||
|
|
@ -133,11 +127,11 @@ var Marker = function(parentEl) {
|
|||
|
||||
// Draws a multi line marker, where lines span the full width
|
||||
this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, type) {
|
||||
var padding = type === "background" ? 0 : this.$padding;
|
||||
// from selection start to the end of the line
|
||||
var padding = this.$padding;
|
||||
var height = config.lineHeight;
|
||||
var top = this.$getTop(range.start.row, config);
|
||||
var left = Math.round(padding + range.start.column * config.characterWidth);
|
||||
var left = padding + range.start.column * config.characterWidth;
|
||||
|
||||
stringBuilder.push(
|
||||
"<div class='", clazz, " ace_start' style='",
|
||||
|
|
@ -149,7 +143,7 @@ var Marker = function(parentEl) {
|
|||
|
||||
// from start of the last line to the selection end
|
||||
top = this.$getTop(range.end.row, config);
|
||||
var width = Math.round(range.end.column * config.characterWidth);
|
||||
var width = range.end.column * config.characterWidth;
|
||||
|
||||
stringBuilder.push(
|
||||
"<div class='", clazz, "' style='",
|
||||
|
|
@ -175,19 +169,12 @@ var Marker = function(parentEl) {
|
|||
};
|
||||
|
||||
// Draws a marker which covers part or whole width of a single screen line
|
||||
this.drawSingleLineMarker = function(stringBuilder, range, clazz, layerConfig, extraLength, type) {
|
||||
var padding = type === "background" ? 0 : this.$padding;
|
||||
var height = layerConfig.lineHeight;
|
||||
this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength) {
|
||||
var height = config.lineHeight;
|
||||
var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth;
|
||||
|
||||
if (type === "background")
|
||||
var width = layerConfig.width;
|
||||
else
|
||||
width = Math.round((range.end.column + (extraLength || 0) - range.start.column) * layerConfig.characterWidth);
|
||||
|
||||
var top = this.$getTop(range.start.row, layerConfig);
|
||||
var left = Math.round(
|
||||
padding + range.start.column * layerConfig.characterWidth
|
||||
);
|
||||
var top = this.$getTop(range.start.row, config);
|
||||
var left = this.$padding + range.start.column * config.characterWidth;
|
||||
|
||||
stringBuilder.push(
|
||||
"<div class='", clazz, "' style='",
|
||||
|
|
@ -198,6 +185,20 @@ var Marker = function(parentEl) {
|
|||
);
|
||||
};
|
||||
|
||||
this.drawFullLineMarker = function(stringBuilder, range, clazz, config) {
|
||||
var top = this.$getTop(range.start.row, config);
|
||||
var height = config.lineHeight;
|
||||
if (range.start.row != range.end.row)
|
||||
height += this.$getTop(range.end.row, config) - top;
|
||||
|
||||
stringBuilder.push(
|
||||
"<div class='", clazz, "' style='",
|
||||
"height:", height, "px;",
|
||||
"top:", top, "px;",
|
||||
"left:0;right:0;'></div>"
|
||||
);
|
||||
}
|
||||
|
||||
}).call(Marker.prototype);
|
||||
|
||||
exports.Marker = Marker;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue