Merge pull request #2316 from ajaxorg/misc

Fix xml autodindent and several small issues
This commit is contained in:
Ruben Daniels 2015-02-16 11:27:16 -08:00
commit 34f57e7499
10 changed files with 93 additions and 29 deletions

View file

@ -97,24 +97,28 @@ exports.commands = [{
name: "fold", name: "fold",
bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"), bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
exec: function(editor) { editor.session.toggleFold(false); }, exec: function(editor) { editor.session.toggleFold(false); },
multiSelectAction: "forEach",
scrollIntoView: "center", scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "unfold", name: "unfold",
bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"), bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
exec: function(editor) { editor.session.toggleFold(true); }, exec: function(editor) { editor.session.toggleFold(true); },
multiSelectAction: "forEach",
scrollIntoView: "center", scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "toggleFoldWidget", name: "toggleFoldWidget",
bindKey: bindKey("F2", "F2"), bindKey: bindKey("F2", "F2"),
exec: function(editor) { editor.session.toggleFoldWidget(); }, exec: function(editor) { editor.session.toggleFoldWidget(); },
multiSelectAction: "forEach",
scrollIntoView: "center", scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "toggleParentFoldWidget", name: "toggleParentFoldWidget",
bindKey: bindKey("Alt-F2", "Alt-F2"), bindKey: bindKey("Alt-F2", "Alt-F2"),
exec: function(editor) { editor.session.toggleFoldWidget(true); }, exec: function(editor) { editor.session.toggleFoldWidget(true); },
multiSelectAction: "forEach",
scrollIntoView: "center", scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
@ -415,7 +419,7 @@ exports.commands = [{
readOnly: true readOnly: true
}, { }, {
name: "passKeysToBrowser", name: "passKeysToBrowser",
bindKey: bindKey("null", "null"), bindKey: bindKey(null, null),
exec: function() {}, exec: function() {},
passEvent: true, passEvent: true,
readOnly: true readOnly: true

View file

@ -160,6 +160,8 @@
z-index: 1; z-index: 1;
position: absolute; position: absolute;
overflow: hidden; overflow: hidden;
/* workaround for chrome bug https://github.com/ajaxorg/ace/issues/2312*/
word-wrap: normal;
white-space: pre; white-space: pre;
height: 100%; height: 100%;
width: 100%; width: 100%;

View file

@ -1580,13 +1580,11 @@ var EditSession = function(text, mode) {
**/ **/
this.setWrapLimitRange = function(min, max) { this.setWrapLimitRange = function(min, max) {
if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) { if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
this.$wrapLimitRange = { this.$wrapLimitRange = { min: min, max: max };
min: min,
max: max
};
this.$modified = true; this.$modified = true;
// This will force a recalculation of the wrap limit // This will force a recalculation of the wrap limit
this._signal("changeWrapMode"); if (this.$useWrapMode)
this._signal("changeWrapMode");
} }
}; };
@ -2467,6 +2465,7 @@ config.defineOptions(EditSession.prototype, "session", {
if (this.$wrap == value) if (this.$wrap == value)
return; return;
this.$wrap = value;
if (!value) { if (!value) {
this.setUseWrapMode(false); this.setUseWrapMode(false);
} else { } else {
@ -2474,7 +2473,6 @@ config.defineOptions(EditSession.prototype, "session", {
this.setWrapLimitRange(col, col); this.setWrapLimitRange(col, col);
this.setUseWrapMode(true); this.setUseWrapMode(true);
} }
this.$wrap = value;
}, },
get: function() { get: function() {
if (this.getUseWrapMode()) { if (this.getUseWrapMode()) {

View file

@ -794,7 +794,7 @@ function Folding() {
this.foldAll(startRow, endRow, options.all ? 10000 : 0); this.foldAll(startRow, endRow, options.all ? 10000 : 0);
} else if (options.children) { } else if (options.children) {
endRow = range ? range.end.row : this.getLength(); endRow = range ? range.end.row : this.getLength();
this.foldAll(row + 1, range.end.row, options.all ? 10000 : 0); this.foldAll(row + 1, endRow, options.all ? 10000 : 0);
} else if (range) { } else if (range) {
if (options.all) if (options.all)
range.collapseChildren = 10000; range.collapseChildren = 10000;

View file

@ -62,7 +62,7 @@ function findAnnotations(session, row, dir) {
if (i < 0) if (i < 0)
i = -i - 1; i = -i - 1;
if (i >= annotations.length - 1) if (i >= annotations.length)
i = dir > 0 ? 0 : annotations.length - 1; i = dir > 0 ? 0 : annotations.length - 1;
else if (i === 0 && dir < 0) else if (i === 0 && dir < 0)
i = annotations.length - 1; i = annotations.length - 1;

View file

@ -66,23 +66,25 @@ define(function(require, exports, module) {
var d = ""; var d = "";
function format(p) { function format(p) {
if (typeof p != "object") if (typeof p != "object")
return p + "" return p + "";
if ("line" in p) { if ("line" in p) {
return p.line + ":" + p.ch return p.line + ":" + p.ch;
} }
if ("anchor" in p) { if ("anchor" in p) {
return format(p.anchor) + "->" + format(p.head) return format(p.anchor) + "->" + format(p.head);
} }
if (Array.isArray(p)) if (Array.isArray(p))
return "[" + p.map(function(x) {return format(x)})+"]" return "[" + p.map(function(x) {
return JSON.stringify(p) return format(x);
}) + "]";
return JSON.stringify(p);
} }
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
var p = arguments[i] var p = arguments[i];
var f = format(p) var f = format(p);
d+= f+" " d += f + " ";
} }
console.log(d) console.log(d);
} }
var Range = require("../range").Range; var Range = require("../range").Range;
var EventEmitter = require("../lib/event_emitter").EventEmitter; var EventEmitter = require("../lib/event_emitter").EventEmitter;
@ -94,6 +96,7 @@ define(function(require, exports, module) {
var useragent = require("../lib/useragent"); var useragent = require("../lib/useragent");
var SearchHighlight = require("../search_highlight").SearchHighlight; var SearchHighlight = require("../search_highlight").SearchHighlight;
var multiSelectCommands = require("../commands/multi_select_commands"); var multiSelectCommands = require("../commands/multi_select_commands");
var TextModeTokenRe = require("../mode/text").Mode.prototype.tokenRe;
require("../multi_select"); require("../multi_select");
var CodeMirror = function(ace) { var CodeMirror = function(ace) {
@ -157,6 +160,11 @@ define(function(require, exports, module) {
CodeMirror.signal = function(o, name, e) { return o._signal(name, e) }; CodeMirror.signal = function(o, name, e) { return o._signal(name, e) };
CodeMirror.on = event.addListener; CodeMirror.on = event.addListener;
CodeMirror.off = event.removeListener; CodeMirror.off = event.removeListener;
CodeMirror.isWordChar = function(ch) {
TextModeTokenRe.lastIndex = 0;
return TextModeTokenRe.test(ch);
};
(function() { (function() {
oop.implement(CodeMirror.prototype, EventEmitter); oop.implement(CodeMirror.prototype, EventEmitter);
@ -383,13 +391,19 @@ define(function(require, exports, module) {
sel.moveCursorBy(0, increment); sel.moveCursorBy(0, increment);
} }
}; };
this.findPosV = function(start, amaount, unit, goalColumn) { this.findPosV = function(start, amount, unit, goalColumn) {
if (unit == 'page') {
var renderer = this.ace.renderer;
var config = renderer.layerConfig;
amount = amount * Math.floor(config.height / config.lineHeight);
unit = 'line';
}
if (unit == 'line') { if (unit == 'line') {
var screenPos = this.ace.session.documentToScreenPosition(start.line, start.ch); var screenPos = this.ace.session.documentToScreenPosition(start.line, start.ch);
if (goalColumn != null) if (goalColumn != null)
screenPos.column = goalColumn; screenPos.column = goalColumn;
screenPos.row += amaount; screenPos.row += amount;
// not what codemirror does but vim mode needs only it // not what codemirror does but vim mode needs only this
screenPos.row = Math.min(Math.max(0, screenPos.row), this.ace.session.getScreenLength() - 1); screenPos.row = Math.min(Math.max(0, screenPos.row), this.ace.session.getScreenLength() - 1);
var pos = this.ace.session.screenToDocumentPosition(screenPos.row, screenPos.column); var pos = this.ace.session.screenToDocumentPosition(screenPos.row, screenPos.column);
return toCmPos(pos); return toCmPos(pos);
@ -1121,7 +1135,9 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
var numberRegex = /[\d]/; var numberRegex = /[\d]/;
var wordRegexp = [(/\w/), (/[^\w\s]/)], bigWordRegexp = [(/\S/)]; var wordRegexp = [{test: CodeMirror.isWordChar}, {test: function(ch) {
return !CodeMirror.isWordChar(ch) && !/\s/.test(ch);
}}], bigWordRegexp = [(/\S/)];
function makeKeyRange(start, size) { function makeKeyRange(start, size) {
var keys = []; var keys = [];
for (var i = start; i < start + size; i++) { for (var i = start; i < start + size; i++) {
@ -2380,6 +2396,15 @@ dom.importCssString(".normal-mode .ace_cursor{\
(line > last && cur.line == last)) { (line > last && cur.line == last)) {
return; return;
} }
// /ace patch
var fold = cm.ace.session.getFoldAt(line, endCh);
if (fold) {
if (motionArgs.forward)
line = fold.end.row + 1;
else
line = fold.start.row - 1;
}
// /ace patche
if (motionArgs.toFirstChar){ if (motionArgs.toFirstChar){
endCh=findFirstNonWhiteSpaceCharacter(cm.getLine(line)); endCh=findFirstNonWhiteSpaceCharacter(cm.getLine(line));
vim.lastHPos = endCh; vim.lastHPos = endCh;
@ -4085,7 +4110,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
var min = cm.firstLine(); var min = cm.firstLine();
var max = cm.lastLine(); var max = cm.lastLine();
var start, end, i = line; var start, end, i = line;
function isEmpty(i) { return !cm.getLine(i); } function isEmpty(i) { return !/\S/.test(cm.getLine(i)); }
function isBoundary(i, dir, any) { function isBoundary(i, dir, any) {
if (any) { return isEmpty(i) != isEmpty(i + dir); } if (any) { return isEmpty(i) != isEmpty(i + dir); }
return !isEmpty(i) && isEmpty(i + dir); return !isEmpty(i) && isEmpty(i + dir);
@ -5942,7 +5967,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
} }
} }
} };
var renderVirtualNumbers = { var renderVirtualNumbers = {
getText: function(session, row) { getText: function(session, row) {
return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9? "\xb7" : "" ))) + "" return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9? "\xb7" : "" ))) + ""
@ -5969,6 +5994,9 @@ dom.importCssString(".normal-mode .ace_cursor{\
}, },
type: "boolean" type: "boolean"
}, false); }, false);
Vim.defineEx('write', 'w', function() {
console.log(':write is not implemented')
});
defaultKeymap.push( defaultKeymap.push(
{ keys: 'zc', type: 'action', action: 'fold', actionArgs: { open: false } }, { keys: 'zc', type: 'action', action: 'fold', actionArgs: { open: false } },
{ keys: 'zC', type: 'action', action: 'fold', actionArgs: { open: false, all: true } }, { keys: 'zC', type: 'action', action: 'fold', actionArgs: { open: false, all: true } },

View file

@ -30,6 +30,7 @@
if (typeof process !== "undefined") { if (typeof process !== "undefined") {
require("amd-loader"); require("amd-loader");
require("../../test/mockdom");
} }
define(function(require, exports, module) { define(function(require, exports, module) {
@ -42,6 +43,7 @@ var Editor = require("../../editor").Editor;
var EditSession = require("../../edit_session").EditSession; var EditSession = require("../../edit_session").EditSession;
var MockRenderer = require("../../test/mockrenderer").MockRenderer; var MockRenderer = require("../../test/mockrenderer").MockRenderer;
var JavaScriptMode = require("../javascript").Mode; var JavaScriptMode = require("../javascript").Mode;
var XMLMode = require("../xml").Mode;
var editor; var editor;
var exec = function(name, times, args) { var exec = function(name, times, args) {
do { do {
@ -117,9 +119,9 @@ module.exports = {
editor.setValue(""); editor.setValue("");
exec("insertstring", 1, "{"); exec("insertstring", 1, "{");
assert.equal(editor.getValue(), "{") assert.equal(editor.getValue(), "{");
exec("insertstring", 1, "\n"); exec("insertstring", 1, "\n");
assert.equal(editor.getValue(), "{\n \n}") assert.equal(editor.getValue(), "{\n \n}");
editor.setValue(""); editor.setValue("");
exec("insertstring", 1, "("); exec("insertstring", 1, "(");
@ -129,6 +131,34 @@ module.exports = {
exec("backspace", 1); exec("backspace", 1);
exec("insertstring", 1, '"'); exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("")'); assert.equal(editor.getValue(), '("")');
editor.setValue("('foo')", 1);
exec("gotoleft", 1);
exec("selectleft", 1);
exec("selectMoreBefore", 1);
exec("insertstring", 1, "'");
assert.equal(editor.getValue(), "('foo')");
exec("selectleft", 1);
exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("foo")');
exec("selectleft", 1);
exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("foo")');
},
"test: xml": function() {
editor = new Editor(new MockRenderer());
editor.setValue(["<OuterTag>",
" <SelfClosingTag />"
].join("\n"));
editor.session.setMode(new XMLMode);
exec("gotolinedown", 1);
exec("gotolineend", 1);
exec("insertstring", 1, '\n');
assert.equal(editor.session.getLine(2), " ");
exec("gotolineup", 1);
exec("gotolineend", 1);
exec("insertstring", 1, '\n');
assert.equal(editor.session.getLine(2), " ");
} }
}; };

View file

@ -256,7 +256,7 @@ var CstyleBehaviour = function() {
text: quote + selected + quote, text: quote + selected + quote,
selection: false selection: false
}; };
} else { } else if (!selected) {
var cursor = editor.getCursorPosition(); var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row); var line = session.doc.getLine(cursor.row);
var leftChar = line.substring(cursor.column-1, cursor.column); var leftChar = line.substring(cursor.column-1, cursor.column);
@ -278,7 +278,7 @@ var CstyleBehaviour = function() {
if (stringBefore && !stringAfter) if (stringBefore && !stringAfter)
return null; // wrap string with different quote return null; // wrap string with different quote
if (stringBefore && stringAfter) if (stringBefore && stringAfter)
return null; // do not pair quotes inside strings return null; // do not pair quotes inside strings
var wordRe = session.$mode.tokenRe; var wordRe = session.$mode.tokenRe;
wordRe.lastIndex = 0; wordRe.lastIndex = 0;
var isWordBefore = wordRe.test(leftChar); var isWordBefore = wordRe.test(leftChar);

View file

@ -155,6 +155,8 @@ var XmlBehaviour = function () {
var token = iterator.getCurrentToken(); var token = iterator.getCurrentToken();
if (token && token.type.indexOf("tag-close") !== -1) { if (token && token.type.indexOf("tag-close") !== -1) {
if (token.value == "/>")
return;
//get tag name //get tag name
while (token && token.type.indexOf("tag-name") === -1) { while (token && token.type.indexOf("tag-name") === -1) {
token = iterator.stepBackward(); token = iterator.stepBackward();

View file

@ -104,7 +104,7 @@ var ShHighlightRules = function() {
token : "keyword.operator" token : "keyword.operator"
}, { }, {
stateName: "heredoc", stateName: "heredoc",
regex : "(<<)(\\s*)(['\"`]?)([\\w\\-]+)(['\"`]?)", regex : "(<<-?)(\\s*)(['\"`]?)([\\w\\-]+)(['\"`]?)",
onMatch : function(value, currentState, stack) { onMatch : function(value, currentState, stack) {
var next = value[2] == '-' ? "indentedHeredoc" : "heredoc"; var next = value[2] == '-' ? "indentedHeredoc" : "heredoc";
var tokens = value.split(this.splitRegex); var tokens = value.split(this.splitRegex);