improve wrapping for markdown
This commit is contained in:
parent
a4a30b6665
commit
9f068dc45d
2 changed files with 23 additions and 11 deletions
|
|
@ -1846,6 +1846,8 @@ var EditSession = function(text, mode) {
|
||||||
var displayLength = tokens.length;
|
var displayLength = tokens.length;
|
||||||
var lastSplit = 0, lastDocSplit = 0;
|
var lastSplit = 0, lastDocSplit = 0;
|
||||||
|
|
||||||
|
var isCode = this.$wrapAsCode;
|
||||||
|
|
||||||
function addSplit(screenPos) {
|
function addSplit(screenPos) {
|
||||||
var displayed = tokens.slice(lastSplit, 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
|
// If there is a space or tab at this split position, then making
|
||||||
// a split is simple.
|
// 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.
|
// Include all following spaces + tabs in this split as well.
|
||||||
while (tokens[split] >= SPACE) {
|
while (tokens[split] >= SPACE) {
|
||||||
split ++;
|
split ++;
|
||||||
}
|
} */
|
||||||
addSplit(split);
|
addSplit(split);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -1886,9 +1889,7 @@ var EditSession = function(text, mode) {
|
||||||
// Check if split is inside of a placeholder. Placeholder are
|
// Check if split is inside of a placeholder. Placeholder are
|
||||||
// not splitable. Therefore, seek the beginning of the placeholder
|
// not splitable. Therefore, seek the beginning of the placeholder
|
||||||
// and try to place the split beofre the placeholder's start.
|
// and try to place the split beofre the placeholder's start.
|
||||||
if (tokens[split] == PLACEHOLDER_START
|
if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
|
||||||
|| tokens[split] == PLACEHOLDER_BODY)
|
|
||||||
{
|
|
||||||
// Seek the start of the placeholder and do the split
|
// Seek the start of the placeholder and do the split
|
||||||
// before the placeholder. By definition there always
|
// before the placeholder. By definition there always
|
||||||
// a PLACEHOLDER_START between split and lastSplit.
|
// 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.
|
// placeholder. So, let's seek for the end of the placeholder.
|
||||||
split = lastSplit + wrapLimit;
|
split = lastSplit + wrapLimit;
|
||||||
for (split; split < tokens.length; split++) {
|
for (split; split < tokens.length; split++) {
|
||||||
if (tokens[split] != PLACEHOLDER_BODY)
|
if (tokens[split] != PLACEHOLDER_BODY) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1931,12 +1931,21 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
// === ELSE ===
|
// === ELSE ===
|
||||||
// Search for the first non space/tab/placeholder/punctuation token backwards.
|
// 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) {
|
while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
|
||||||
split --;
|
split --;
|
||||||
}
|
}
|
||||||
while (split > minSplit && tokens[split] == PUNCTUATION) {
|
if (isCode) {
|
||||||
split --;
|
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 we found one, then add the split.
|
||||||
if (split > minSplit) {
|
if (split > minSplit) {
|
||||||
|
|
@ -2477,6 +2486,9 @@ config.defineOptions(EditSession.prototype, "session", {
|
||||||
set: function(val) {this.doc.setNewLineMode(val)},
|
set: function(val) {this.doc.setNewLineMode(val)},
|
||||||
get: function() {return this.doc.getNewLineMode()},
|
get: function() {return this.doc.getNewLineMode()},
|
||||||
handlesSet: true
|
handlesSet: true
|
||||||
|
},
|
||||||
|
wrapAsCode: {
|
||||||
|
initialValue: false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -988,7 +988,7 @@ var VirtualRenderer = function(container, theme) {
|
||||||
|
|
||||||
this.$getLongestLine = function() {
|
this.$getLongestLine = function() {
|
||||||
var charCount = this.session.getScreenWidth();
|
var charCount = this.session.getScreenWidth();
|
||||||
if (this.$textLayer.showInvisibles)
|
if (this.showInvisibles && !this.session.$useWrapMode)
|
||||||
charCount += 1;
|
charCount += 1;
|
||||||
|
|
||||||
return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
|
return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue