diff --git a/lib/ace/document.js b/lib/ace/document.js index 14e04ff9..a2ca7210 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -120,6 +120,7 @@ var Document = function(text) { this.$detectNewLine = function(text) { var match = text.match(/^.*?(\r\n|\r|\n)/m); this.$autoNewLine = match ? match[1] : "\n"; + this._signal("changeNewLineMode"); }; /** @@ -152,6 +153,7 @@ var Document = function(text) { return; this.$newLineMode = newLineMode; + this._signal("changeNewLineMode"); }; /** diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index 50b00196..fd81f5ff 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -41,18 +41,31 @@ var Text = function(parentEl) { this.element = dom.createElement("div"); this.element.className = "ace_layer ace_text-layer"; parentEl.appendChild(this.element); + this.$updateEolChar = this.$updateEolChar.bind(this); }; (function() { oop.implement(this, EventEmitter); - this.EOF_CHAR = "\xB6"; //"¶"; - this.EOL_CHAR = "\xAC"; //"¬"; - this.TAB_CHAR = "\u2192"; //"→" "\u21E5"; - this.SPACE_CHAR = "\xB7"; //"·"; + this.EOF_CHAR = "\xB6"; + this.EOL_CHAR_LF = "\xAC"; + this.EOL_CHAR_CRLF = "\xa4"; + this.EOL_CHAR = this.EOL_CHAR_LF; + this.TAB_CHAR = "\u2192"; //"\u21E5"; + this.SPACE_CHAR = "\xB7"; this.$padding = 0; + this.$updateEolChar = function() { + var EOL_CHAR = this.session.doc.getNewLineCharacter() == "\n" + ? this.EOL_CHAR_LF + : this.EOL_CHAR_CRLF; + if (this.EOL_CHAR != EOL_CHAR) { + this.EOL_CHAR = EOL_CHAR; + return true; + } + } + this.setPadding = function(padding) { this.$padding = padding; this.element.style.padding = "0 " + padding + "px"; diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index c5eb42a9..28cefde1 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -227,8 +227,13 @@ var VirtualRenderer = function(container, theme) { * Associates the renderer with an [[EditSession `EditSession`]]. **/ this.setSession = function(session) { + if (this.session) + this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode); + this.session = session; - + if (!session) + return; + if (this.scrollMargin.top && session.getScrollTop() <= 0) session.setScrollTop(-this.scrollMargin.top); @@ -239,6 +244,10 @@ var VirtualRenderer = function(container, theme) { this.$textLayer.setSession(session); this.$loop.schedule(this.CHANGE_FULL); this.session.$setFontMetrics(this.$fontMetrics); + + this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this); + this.onChangeNewLineMode() + this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode); }; /** @@ -272,6 +281,11 @@ var VirtualRenderer = function(container, theme) { this.$loop.schedule(this.CHANGE_LINES); }; + this.onChangeNewLineMode = function() { + this.$loop.schedule(this.CHANGE_TEXT); + this.$textLayer.$updateEolChar(); + }; + this.onChangeTabSize = function() { this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER); this.$textLayer.onChangeTabSize();