From dfe918e339dc2c1d4adef0bfa0f850b387964326 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 1 Oct 2012 17:12:42 +0400 Subject: [PATCH] fix line highlight on the last line Issue #934 --- lib/ace/edit_session.js | 33 +++++++++++++++++++++++++-------- lib/ace/editor.js | 32 ++++++++++++++------------------ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index a739b677..d24888da 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -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: * { diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 937e0e73..16588ec0 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -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; @@ -2126,4 +2122,4 @@ var Editor = function(renderer, session) { exports.Editor = Editor; -}); \ No newline at end of file +});