diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index f7d3a147..80b25b06 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -62,6 +62,8 @@ var fillDropdown = util.fillDropdown; var bindCheckbox = util.bindCheckbox; var bindDropdown = util.bindDropdown; +var ElasticTabstopsLite = require("ace/elastic_tabstops_lite").ElasticTabstopsLite; + /*********** create editor ***************************/ var container = document.getElementById("editor-container"); @@ -379,7 +381,8 @@ bindDropdown("split", function(value) { bindCheckbox("elastic_tabstops", function(checked) { - env.editor.setUseElasticTabstops(checked); + if (checked === true) + new ElasticTabstopsLite(env.editor); }); diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 3a5d7f05..8e39d25c 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -462,8 +462,8 @@ var Editor = function(renderer, session) { // update cursor because tab characters can influence the cursor position this.$cursorChange(); - - if (this.$useElasticTabstops) { + console.log(e); + /*if (this.$useElasticTabstops) { if (this.ElasticTabstops === undefined) { var ElasticTabstops = require("./elastic_tabstops").ElasticTabstops; this.ElasticTabstops = new ElasticTabstops(this, this.session); @@ -476,7 +476,7 @@ var Editor = function(renderer, session) { // block event calling, because this method makes changes this.ElasticTabstops.processRow([row]); } - } + }*/ }; this.onTokenizerUpdate = function(e) { @@ -1057,29 +1057,6 @@ var Editor = function(renderer, session) { return this.getOption("fadeFoldWidgets"); }; - this.$useElasticTabstops = false; - - /** - * Determines whether or not elastic tabstops should be used. - * @param {Boolean} useElasticTabstops Set to `true` to enable elastic tabstops - * - **/ - this.setUseElasticTabstops = function(useElasticTabstops) { - if (this.$useElasticTabstops == useElasticTabstops) - return; - - this.$useElasticTabstops = useElasticTabstops; - }; - - /** - * Returns whether or not elastic tabstops are set. - * @returns {Boolean} The current elastic tabstops setting - * - **/ - this.getUseElasticTabstops = function() { - return this.$useElasticTabstops; - }; - /** * Removes words of text from the editor. A "word" is defined as a string of characters bookended by whitespace. * @param {String} dir The direction of the deletion to occur, either "left" or "right" diff --git a/lib/ace/elastic_tabstops.js b/lib/ace/elastic_tabstops_lite.js similarity index 91% rename from lib/ace/elastic_tabstops.js rename to lib/ace/elastic_tabstops_lite.js index c3fa0411..5eb9dcf6 100644 --- a/lib/ace/elastic_tabstops.js +++ b/lib/ace/elastic_tabstops_lite.js @@ -31,9 +31,8 @@ define(function(require, exports, module) { "use strict"; -var ElasticTabstops = function(editor, session) { +var ElasticTabstopsLite = function(editor) { this.$editor = editor; - this.$session = session; }; (function() { @@ -78,7 +77,7 @@ var ElasticTabstops = function(editor, session) { // forward (not including starting row) rowIter = row; - var numRows = this.$session.getLength(); + var numRows = this.$editor.session.getLength(); while (rowIter < numRows - 1) { rowIter++; @@ -99,7 +98,7 @@ var ElasticTabstops = function(editor, session) { var tabs = [-1].concat(this.$tabsForRow(row)); var widths = tabs.map(function (el) { return 0; } ).slice(1); - var line = this.$session.getLine(row); + var line = this.$editor.session.getLine(row); for (var i = 0, len = tabs.length - 1; i < len; i++) { var leftEdge = tabs[i]+1; @@ -115,7 +114,7 @@ var ElasticTabstops = function(editor, session) { this.$selectionColumnsForRow = function(row) { var selections = [], cursor = this.$editor.getCursorPosition(); - if (this.$session.getSelection().isEmpty()) { + if (this.$editor.session.getSelection().isEmpty()) { // todo: support multicursor if (row == cursor.row) selections.push(cursor.column); @@ -177,7 +176,7 @@ var ElasticTabstops = function(editor, session) { }; this.$tabsForRow = function(row) { - var rowTabs = [], line = this.$session.getLine(row), + var rowTabs = [], line = this.$editor.session.getLine(row), re = /\t/g, match; while ((match = re.exec(line)) != null) { @@ -207,21 +206,21 @@ var ElasticTabstops = function(editor, session) { if (difference == 0) continue; - var partialLine = this.$session.getLine(row).substr(0, it ); + var partialLine = this.$editor.session.getLine(row).substr(0, it ); var strippedPartialLine = partialLine.replace(/\s*$/g, ""); var ispaces = partialLine.length - strippedPartialLine.length; if (difference > 0) { // put the spaces after the tab and then delete the tab, so any insertion // points behave as expected - this.$session.getDocument().insertInLine({row: row, column: it + 1}, Array(difference + 1).join(" ") + "\t"); - this.$session.getDocument().removeInLine(row, it, it + 1); + this.$editor.session.getDocument().insertInLine({row: row, column: it + 1}, Array(difference + 1).join(" ") + "\t"); + this.$editor.session.getDocument().removeInLine(row, it, it + 1); bias += difference; } if (difference < 0 && ispaces >= -difference) { - this.$session.getDocument().removeInLine(row, it + difference, it); + this.$editor.session.getDocument().removeInLine(row, it + difference, it); bias += difference; } } @@ -269,8 +268,8 @@ var ElasticTabstops = function(editor, session) { return expandedSet; }; -}).call(ElasticTabstops.prototype); +}).call(ElasticTabstopsLite.prototype); -exports.ElasticTabstops = ElasticTabstops; +exports.ElasticTabstopsLite = ElasticTabstopsLite; }); \ No newline at end of file