From d8a88762540f68e32a6fd8b0b7e01115f8612f75 Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 18 Nov 2011 20:13:20 +0400 Subject: [PATCH] find and goto must unfold desired locations --- lib/ace/edit_session/folding.js | 24 ++++++++++++++++++++++++ lib/ace/editor.js | 2 ++ 2 files changed, 26 insertions(+) diff --git a/lib/ace/edit_session/folding.js b/lib/ace/edit_session/folding.js index ae53a377..41ff192e 100644 --- a/lib/ace/edit_session/folding.js +++ b/lib/ace/edit_session/folding.js @@ -415,6 +415,30 @@ function Folding() { }, this); } + this.unfold = function(location, expandInner) { + var range, folds; + if (location == null) + range = new Range(0, 0, this.getLength(), 0); + else if (typeof location == "number") + range = new Range(location, 0, location, this.getLine(location).length); + else if ("row" in location) + range = Range.fromPoints(location, location); + else + range = location; + + var folds = this.getFoldsInRange(range); + if (expandInner) { + this.removeFolds(folds); + } else { + // TODO: might need to remove and add folds in one go instead of using + // expandFolds several times. + while (folds.length) { + this.expandFolds(folds); + folds = this.getFoldsInRange(range); + } + } + } + /** * Checks if a given documentRow is folded. This is true if there are some * folded parts such that some parts of the line is still visible. diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 98d82c48..95881cc3 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -1077,6 +1077,7 @@ var Editor = function(renderer, session) { this.gotoLine = function(lineNumber, column) { this.selection.clearSelection(); + this.session.unfold({row: lineNumber - 1, column: column || 0}) this.$blockScrolling += 1; this.moveCursorTo(lineNumber-1, column || 0); @@ -1242,6 +1243,7 @@ var Editor = function(renderer, session) { var range = this.$search.find(this.session); if (range) { + this.session.unfold(range); this.gotoLine(range.end.row+1, range.end.column); this.selection.setSelectionRange(range); }