Skip to content

Commit 5aad286

Browse files
committed
upgrading ACE to 1.4.14
1 parent d1a8a7f commit 5aad286

File tree

7 files changed

+286
-163
lines changed

7 files changed

+286
-163
lines changed

webui/src/js/libs/ace/ace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3881,7 +3881,7 @@ function deHyphenate(str) {
38813881
return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
38823882
}
38833883

3884-
exports.version = "1.4.13";
3884+
exports.version = "1.4.14";
38853885

38863886
});
38873887

webui/src/js/libs/ace/ext-beautify.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,20 @@ exports.beautify = function(session) {
4848
};
4949

5050
var trimLine = function() {
51-
code = code.replace(/ +$/, "");
52-
};
51+
var end = code.length - 1;
52+
53+
while (true) {
54+
if (end == 0)
55+
break;
56+
if (code[end] !== " ")
57+
break;
58+
59+
end = end - 1;
60+
}
5361

62+
code = code.slice(0, end + 1);
63+
};
64+
5465
var trimCode = function() {
5566
code = code.trimRight();
5667
breakBefore = false;
@@ -206,7 +217,7 @@ exports.beautify = function(session) {
206217
if (caseBody)
207218
unindent = 1;
208219
}
209-
if (breakBefore && !(token.type.match(/^(comment)$/) && !value.substr(0, 1).match(/^[/#]$/)) && !(token.type.match(/^(string)$/) && !value.substr(0, 1).match(/^['"]$/))) {
220+
if (breakBefore && !(token.type.match(/^(comment)$/) && !value.substr(0, 1).match(/^[/#]$/)) && !(token.type.match(/^(string)$/) && !value.substr(0, 1).match(/^['"@]$/))) {
210221

211222
indent = lastIndent;
212223

webui/src/js/libs/ace/ext-hardwrap.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
ace.define("ace/ext/hardwrap",["require","exports","module","ace/range"], function(require, exports, module) {
1+
ace.define("ace/ext/hardwrap",["require","exports","module","ace/range","ace/editor","ace/config"], function(require, exports, module) {
22
"use strict";
33

44
var Range = require("../range").Range;
55

66
function hardWrap(editor, options) {
77
var max = options.column || editor.getOption("printMarginColumn");
8+
var allowMerge = options.allowMerge != false;
89

910
var row = Math.min(options.startRow, options.endRow);
1011
var endRow = Math.max(options.startRow, options.endRow);
@@ -16,10 +17,11 @@ function hardWrap(editor, options) {
1617
if (line.length > max) {
1718
var space = findSpace(line, max, 5);
1819
if (space) {
19-
session.replace(new Range(row,space.start,row,space.end), "\n");
20+
var indentation = /^\s*/.exec(line)[0];
21+
session.replace(new Range(row,space.start,row,space.end), "\n" + indentation);
2022
}
2123
endRow++;
22-
} else if (/\S/.test(line) && row != endRow) {
24+
} else if (allowMerge && /\S/.test(line) && row != endRow) {
2325
var nextLine = session.getLine(row + 1);
2426
if (nextLine && /\S/.test(nextLine)) {
2527
var trimmedLine = line.replace(/\s+$/, "");
@@ -32,6 +34,8 @@ function hardWrap(editor, options) {
3234
session.replace(replaceRange, " ");
3335
row--;
3436
endRow--;
37+
} else if (trimmedLine.length < line.length) {
38+
session.remove(new Range(row, trimmedLine.length, row, line.length));
3539
}
3640
}
3741
}
@@ -65,14 +69,50 @@ function hardWrap(editor, options) {
6569
if (spaceBefore && spaceBefore[2] && spaceBefore.index > min) {
6670
return {
6771
start: spaceBefore.index,
68-
end: spaceBefore.index + spaceBefore[3].length
72+
end: spaceBefore.index + spaceBefore[2].length
73+
};
74+
}
75+
if (spaceAfter && spaceAfter[2]) {
76+
start = max + spaceAfter[2].length;
77+
return {
78+
start: start,
79+
end: start + spaceAfter[3].length
6980
};
7081
}
71-
7282
}
7383

7484
}
7585

86+
function wrapAfterInput(e) {
87+
if (e.command.name == "insertstring" && /\S/.test(e.args)) {
88+
var editor = e.editor;
89+
var cursor = editor.selection.cursor;
90+
if (cursor.column <= editor.renderer.$printMarginColumn) return;
91+
var lastDelta = editor.session.$undoManager.$lastDelta;
92+
93+
hardWrap(editor, {
94+
startRow: cursor.row, endRow: cursor.row,
95+
allowMerge: false
96+
});
97+
if (lastDelta != editor.session.$undoManager.$lastDelta)
98+
editor.session.markUndoGroup();
99+
}
100+
}
101+
102+
var Editor = require("../editor").Editor;
103+
require("../config").defineOptions(Editor.prototype, "editor", {
104+
hardWrap: {
105+
set: function(val) {
106+
if (val) {
107+
this.commands.on("afterExec", wrapAfterInput);
108+
} else {
109+
this.commands.off("afterExec", wrapAfterInput);
110+
}
111+
},
112+
value: false
113+
}
114+
});
115+
76116
exports.hardWrap = hardWrap;
77117

78118
}); (function() {

0 commit comments

Comments
 (0)