From 56619e516b60f7b4a712e091150521e5f70190ac Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Mon, 16 May 2011 20:11:57 +0200 Subject: [PATCH 1/3] Add 20px more width to the editor/cli --- demo/demo.js | 2 +- demo/styles.css | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index d662c933..31bde34d 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -337,7 +337,7 @@ exports.launch = function(env) { } function onResize() { - var width = (document.documentElement.clientWidth - 300); + var width = (document.documentElement.clientWidth - 280); container.style.width = width + "px"; cockpitInput.style.width = width + "px"; container.style.height = (document.documentElement.clientHeight - 22) + "px"; diff --git a/demo/styles.css b/demo/styles.css index d2046a8a..a4735753 100644 --- a/demo/styles.css +++ b/demo/styles.css @@ -1,6 +1,6 @@ html { height: 100%; - width: 100%; + width: 100%; overflow: hidden; } @@ -24,7 +24,7 @@ body { #editor { position: absolute; top: 0px; - left: 300px; + left: 280px; bottom: 0px; right: 0px; background: white; @@ -44,7 +44,7 @@ body { #cockpitInput { position: absolute; - left: 300px; + left: 280px; right: 0px; bottom: 0; From 55e0f8ceff87e4c05ea3ab27d52f6a765be3ab3b Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Tue, 17 May 2011 16:16:28 +0200 Subject: [PATCH 2/3] Fix calculation of EditSession.getScreenLength. --- demo/demo.js | 2 ++ lib/ace/edit_session.js | 36 ++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index 31bde34d..58234d3a 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -155,6 +155,8 @@ exports.launch = function(env) { var container = document.getElementById("editor"); var cockpitInput = document.getElementById("cockpitInput"); env.editor = new Editor(new Renderer(container, theme)); + window.env = env; + window.ace = env.editor; var modes = { text: new TextMode(), diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 98125892..f9994c52 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -463,7 +463,7 @@ var EditSession = function(text, mode) { this.$stopWorker(); - if (this.$useWorker) + if (this.$useWorker) this.$startWorker(); var tokenizer = mode.getTokenizer(); @@ -492,10 +492,10 @@ var EditSession = function(text, mode) { this.$stopWorker = function() { if (this.$worker) this.$worker.terminate(); - + this.$worker = null; }; - + this.$startWorker = function() { if (typeof Worker !== "undefined" && !require.noWorker) { try { @@ -503,7 +503,7 @@ var EditSession = function(text, mode) { } catch (e) { console.log("Could not load worker"); console.log(e); - this.$worker = null; + this.$worker = null; } } else @@ -1418,7 +1418,7 @@ var EditSession = function(text, mode) { } } var docRowCacheLast = docRow; - // clamp row before clamping column, for selection on last line + // clamp row before clamping column, for selection on last line var maxRow = this.getLength() - 1; var foldLine = this.getNextFold(docRow); @@ -1449,7 +1449,7 @@ var EditSession = function(text, mode) { if (foldLine && foldLine.start.row <= docRow) line = this.getFoldDisplayLine(foldLine); - else { + else { line = this.getLine(docRow); foldLine = null; } @@ -1596,21 +1596,29 @@ var EditSession = function(text, mode) { }; this.getScreenLength = function() { - var length = this.getLength(); var screenRows = 0; + var lastFoldLine = null; + var foldLine = null; if (!this.$useWrapMode) { - screenRows = length; + screenRows = this.getLength(); + + // Remove the folded lines again. + var foldData = this.$foldData; + for (var i = 0; i < foldData.length; i++) { + foldLine = foldData[i]; + screenRows -= foldLine.end.row - foldLine.start.row; + } } else { for (var row = 0; row < this.$wrapData.length; row++) { - screenRows += this.$wrapData[row].length + 1; + if (foldLine = this.getFoldLine(row, lastFoldLine)) { + row = foldLine.end.row; + screenRows += 1; + } else { + screenRows += this.$wrapData[row].length + 1; + } } } - var foldData = this.$foldData; - for (var i = 0; i < foldData.length; i++) { - var foldLine = foldData[i]; - screenRows -= foldLine.end.row - foldLine.start.row; - } return screenRows; } From 62f168eb8e838ddb6b85c2520027ce23fa8673f5 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Tue, 17 May 2011 20:28:48 +0200 Subject: [PATCH 3/3] Fix bug in EditSession.$updateInternalDataOnChange. Shifting the fold lines on deletion have to use end.row instead of lastRow, as lastRow is "normalized". --- lib/ace/edit_session.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index f9994c52..6afa7107 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -1010,7 +1010,7 @@ var EditSession = function(text, mode) { removedFolds = this.getFoldsInRange(e.data.range); this.removeFolds(removedFolds); - var foldLine = this.getFoldLine(lastRow); + var foldLine = this.getFoldLine(end.row); var idx = 0; if (foldLine) { foldLine.addRemoveChars(end.row, end.column, start.column - end.column); @@ -1026,7 +1026,7 @@ var EditSession = function(text, mode) { for (idx; idx < foldLines.length; idx++) { var foldLine = foldLines[idx]; - if (foldLine.start.row >= lastRow) { + if (foldLine.start.row >= end.row) { foldLine.shiftRow(-len); } }