Skip to content

Commit

Permalink
fix line highlight on the last line
Browse files Browse the repository at this point in the history
 Issue #934
  • Loading branch information
nightwing committed Oct 1, 2012
1 parent a2332b3 commit ee65c53
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
33 changes: 25 additions & 8 deletions lib/ace/edit_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
* {
Expand Down
32 changes: 14 additions & 18 deletions lib/ace/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,27 +481,23 @@ 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.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 ((this.$selectionStyle != "line" || !this.selection.isMultiLine()))
highlight = this.getCursorPosition();
}
};

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;
Expand Down

0 comments on commit ee65c53

Please sign in to comment.