diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 17252d29..e70d05c5 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -1846,6 +1846,8 @@ var EditSession = function(text, mode) { var displayLength = tokens.length; var lastSplit = 0, lastDocSplit = 0; + var isCode = this.$wrapAsCode; + function addSplit(screenPos) { var displayed = tokens.slice(lastSplit, screenPos); @@ -1873,11 +1875,12 @@ var EditSession = function(text, mode) { // If there is a space or tab at this split position, then making // a split is simple. - if (tokens[split] >= SPACE) { + if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) { + /* disabled see https://github.com/ajaxorg/ace/issues/1186 // Include all following spaces + tabs in this split as well. while (tokens[split] >= SPACE) { split ++; - } + } */ addSplit(split); continue; } @@ -1886,9 +1889,7 @@ var EditSession = function(text, mode) { // Check if split is inside of a placeholder. Placeholder are // not splitable. Therefore, seek the beginning of the placeholder // and try to place the split beofre the placeholder's start. - if (tokens[split] == PLACEHOLDER_START - || tokens[split] == PLACEHOLDER_BODY) - { + if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) { // Seek the start of the placeholder and do the split // before the placeholder. By definition there always // a PLACEHOLDER_START between split and lastSplit. @@ -1912,8 +1913,7 @@ var EditSession = function(text, mode) { // placeholder. So, let's seek for the end of the placeholder. split = lastSplit + wrapLimit; for (split; split < tokens.length; split++) { - if (tokens[split] != PLACEHOLDER_BODY) - { + if (tokens[split] != PLACEHOLDER_BODY) { break; } } @@ -1931,12 +1931,21 @@ var EditSession = function(text, mode) { // === ELSE === // Search for the first non space/tab/placeholder/punctuation token backwards. - var minSplit = Math.max(split - 10, lastSplit - 1); + var minSplit = Math.max(split - (isCode ? 10 : wrapLimit >> 1), lastSplit - 1); while (split > minSplit && tokens[split] < PLACEHOLDER_START) { split --; } - while (split > minSplit && tokens[split] == PUNCTUATION) { - split --; + if (isCode) { + while (split > minSplit && tokens[split] < PLACEHOLDER_START) { + split --; + } + while (split > minSplit && tokens[split] == PUNCTUATION) { + split --; + } + } else { + while (split > minSplit && tokens[split] < SPACE) { + split --; + } } // If we found one, then add the split. if (split > minSplit) { @@ -2477,6 +2486,9 @@ config.defineOptions(EditSession.prototype, "session", { set: function(val) {this.doc.setNewLineMode(val)}, get: function() {return this.doc.getNewLineMode()}, handlesSet: true + }, + wrapAsCode: { + initialValue: false } }); diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 9c1efb3b..ab62eb46 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -988,7 +988,7 @@ var VirtualRenderer = function(container, theme) { this.$getLongestLine = function() { var charCount = this.session.getScreenWidth(); - if (this.$textLayer.showInvisibles) + if (this.showInvisibles && !this.session.$useWrapMode) charCount += 1; return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));