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 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
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue