Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update ace++

  • Loading branch information...
commit 74923607a151d06e6f839565a197a940243d040e 1 parent 64b6efa
@nightwing nightwing authored
View
521 chrome/content/ace++/res/ace/ace-uncompressed.js
@@ -21,6 +21,7 @@ var Editor = function(renderer, session) {
this.container = container;
this.renderer = renderer;
+ this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
this.keyBinding = new KeyBinding(this);
@@ -37,7 +38,6 @@ var Editor = function(renderer, session) {
wrap: true
});
- this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands);
this.setSession(session || new EditSession(""));
};
@@ -132,7 +132,10 @@ var Editor = function(renderer, session) {
this.onChangeMode();
+ this.$blockScrolling += 1;
this.onCursorChange();
+ this.$blockScrolling -= 1;
+
this.onScrollTopChange();
this.onScrollLeftChange();
this.onSelectionChange();
@@ -178,16 +181,16 @@ var Editor = function(renderer, session) {
};
this.setFontSize = function(size, delta) {
- if (delta && !size)
- size = (parseInt(this.container.style.fontSize) || 12) + delta;
- else if (!size)
- size = 12;
+ if (delta && !size)
+ size = (parseInt(this.container.style.fontSize) || 12) + delta;
+ else if (!size)
+ size = 12;
- if (typeof size == "number")
- size = size + "px";
-
+ if (typeof size == "number")
+ size = size + "px";
+
this.container.style.fontSize = size;
- this.renderer.updateFontSize();
+ this.renderer.updateFontSize();
};
this.$highlightBrackets = function() {
@@ -998,12 +1001,12 @@ var Editor = function(renderer, session) {
}
if (pos) {
- if (select) {
- this.selection.selectTo(pos.row, pos.column);
- } else {
- this.clearSelection();
- this.moveCursorTo(pos.row, pos.column);
- }
+ if (select) {
+ this.selection.selectTo(pos.row, pos.column);
+ } else {
+ this.clearSelection();
+ this.moveCursorTo(pos.row, pos.column);
+ }
}
};
@@ -1267,7 +1270,7 @@ var VirtualRenderer = function(container, theme) {
this.scrollTop = 0;
this.scrollLeft = 0;
-
+
event.addListener(this.scroller, "scroll", function() {
_self.session.setScrollLeft(_self.scroller.scrollLeft);
});
@@ -1574,21 +1577,27 @@ var VirtualRenderer = function(container, theme) {
changes & this.CHANGE_SCROLL
)
this.$computeLayerConfig();
+
+ //this.content.style.left = -this.scrollLeft + "px";
+ if (changes & this.CHANGE_H_SCROLL)
+ this.scroller.scrollLeft = this.scrollLeft
// full
if (changes & this.CHANGE_FULL) {
+ // update scrollbar first to not loose scroll position when gutter calls resize
+ this.$updateScrollBar();
this.$textLayer.update(this.layerConfig);
if (this.showGutter)
this.$gutterLayer.update(this.layerConfig);
this.$markerBack.update(this.layerConfig);
this.$markerFront.update(this.layerConfig);
this.$cursorLayer.update(this.layerConfig);
- this.$updateScrollBar();
return;
}
// scrolling
if (changes & this.CHANGE_SCROLL) {
+ this.$updateScrollBar();
if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
this.$textLayer.update(this.layerConfig);
else
@@ -1599,7 +1608,6 @@ var VirtualRenderer = function(container, theme) {
this.$markerBack.update(this.layerConfig);
this.$markerFront.update(this.layerConfig);
this.$cursorLayer.update(this.layerConfig);
- this.$updateScrollBar();
return;
}
@@ -1632,11 +1640,6 @@ var VirtualRenderer = function(container, theme) {
if (changes & this.CHANGE_SIZE)
this.$updateScrollBar();
-
- if (changes & this.CHANGE_H_SCROLL) {
- //this.content.style.left = -this.scrollLeft + "px";
- this.scroller.scrollLeft = this.scrollLeft
- }
};
this.$computeLayerConfig = function() {
@@ -1650,9 +1653,13 @@ var VirtualRenderer = function(container, theme) {
var horizScroll = this.$horizScrollAlwaysVisible || this.$size.scrollerWidth - longestLine < 0;
var horizScrollChanged = this.$horizScroll !== horizScroll;
this.$horizScroll = horizScroll;
- if (horizScrollChanged)
+ if (horizScrollChanged) {
this.scroller.style.overflowX = horizScroll ? "scroll" : "hidden";
-
+ // when we hide scrollbar scroll event isn't emited
+ // leaving session with wrong scrollLeft value
+ if (!horizScroll)
+ this.session.setScrollLeft(0);
+ }
var maxHeight = this.session.getScreenLength() * this.lineHeight;
this.session.setScrollTop(Math.max(0, Math.min(this.scrollTop, maxHeight - this.$size.scrollerHeight)));
@@ -1824,7 +1831,7 @@ var VirtualRenderer = function(container, theme) {
};
this.getScrollLeft = function() {
- return this.session.getScrollTop();
+ return this.session.getScrollLeft();
};
this.getScrollTopRow = function() {
@@ -1841,10 +1848,10 @@ var VirtualRenderer = function(container, theme) {
this.scrollToLine = function(line, center) {
var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
- var offset = pos.top
- if (center) {
+ var offset = pos.top;
+ if (center)
offset -= this.$size.scrollerHeight / 2;
- }
+
this.session.setScrollTop(offset);
};
@@ -1884,14 +1891,19 @@ var VirtualRenderer = function(container, theme) {
var canvasPos = this.scroller.getBoundingClientRect();
var col = Math.round(
- (pageX + this.scrollLeft - canvasPos.left - this.$padding - dom.getPageScrollLeft())
- / this.characterWidth
- );
+ (pageX + this.scrollLeft - canvasPos.left - this.$padding - window.pageYOffset) / this.characterWidth
+ );
var row = Math.floor(
- (pageY + this.scrollTop - canvasPos.top - dom.getPageScrollTop())
- / this.lineHeight
- );
-
+ (pageY + this.scrollTop - canvasPos.top - window.pageYOffset) / this.lineHeight
+ );
+ if (row < 0) {
+ row = 0;
+ } else {
+ var maxRow = this.layerConfig.maxHeight / this.layerConfig.lineHeight - 1;
+ if(row > maxRow)
+ row = maxRow;
+ }
+
return this.session.screenToDocumentPosition(row, Math.max(col, 0));
};
@@ -2094,7 +2106,7 @@ exports.cssText = ".ace-tm .ace_editor {\
}\
\
.ace-tm .ace_fold {\
- background-color: #4b50c3;\
+ background-color: #6B72E6;\
}\
\
.ace-tm .ace_text-layer {\
@@ -2772,7 +2784,7 @@ require("ace/commands/default_commands");
var KeyBinding = function(editor) {
this.$editor = editor;
this.$data = { };
- this.$handlers = [this];
+ this.$handlers = [this.$editor.commands];
};
(function() {
@@ -2783,7 +2795,7 @@ var KeyBinding = function(editor) {
for (var i = 0; i < this.$handlers.length; i++)
this.$handlers[i].detach && this.$handlers[i].detach(this.$editor);
- this.$handlers = [this];
+ this.$handlers = [this.$editor.commands];
if (keyboardHandler) {
this.$handlers.push(keyboardHandler);
keyboardHandler.attach && keyboardHandler.attach(this.$editor);
@@ -2815,21 +2827,23 @@ var KeyBinding = function(editor) {
toExecute = this.$handlers[i].handleKeyboard(
this.$data, hashId, keyString, keyCode, e
);
- if (toExecute && toExecute.command)
+ if (toExecute)
break;
}
- if (!toExecute || !toExecute.command)
+ if (!toExecute)
return false;
var success = false;
var commands = this.$editor.commands;
// allow keyboardHandler to consume keys
- if (toExecute.command != "null")
+ if (toExecute.command == "null")
+ success = true;
+ else if (toExecute.command)
success = commands.exec(toExecute.command, this.$editor, toExecute.args);
else
- success = true;
+ success = commands.exec(toExecute, this.$editor);
if (success && e)
event.stopEvent(e);
@@ -2837,21 +2851,15 @@ var KeyBinding = function(editor) {
return success;
};
- this.handleKeyboard = function(data, hashId, keyString) {
- return {
- command: this.$editor.commands.findKeyCommand(hashId, keyString)
- };
- };
-
this.onCommandKey = function(e, hashId, keyCode) {
- var keyString = keyUtil.keyCodeToString(keyCode);
+ var keyString = keyUtil.keyCodeToString(keyCode).toLowerCase();
this.$callKeyboardHandlers(hashId, keyString, keyCode, e);
};
this.onTextInput = function(text, pasted) {
var success = false;
if (!pasted && text.length == 1)
- success = this.$callKeyboardHandlers(0, text);
+ success = this.$callKeyboardHandlers(-1, text);
if (!success)
this.$editor.commands.exec("insertstring", this.$editor, text);
};
@@ -5157,131 +5165,22 @@ exports.EventEmitter = EventEmitter;
define("ace/commands/command_manager",[], function(require, exports, module) {
-var keyUtil = require("ace/lib/keys");
+var oop = require("ace/lib/oop");
+var HashHandler = require("ace/keyboard/hash_handler").HashHandler;
var CommandManager = function(platform, commands) {
- if (typeof platform !== "string")
- throw new TypeError("'platform' argument must be either 'mac' or 'win'");
-
this.platform = platform;
this.commands = {};
this.commmandKeyBinding = {};
- if (commands)
- commands.forEach(this.addCommand, this);
+ this.addCommands(commands);
};
-(function() {
-
- this.addCommand = function(command) {
- if (this.commands[command.name])
- this.removeCommand(command);
-
- this.commands[command.name] = command;
-
- if (command.bindKey) {
- this._buildKeyHash(command);
- }
- };
-
- this.removeCommand = function(command) {
- var name = (typeof command === 'string' ? command : command.name);
- command = this.commands[name];
- delete this.commands[name];
-
- // exaustive search is brute force but since removeCommand is
- // not a performance critical operation this should be OK
- var ckb = this.commmandKeyBinding;
- for (var hashId in ckb) {
- for (var key in ckb[hashId]) {
- if (ckb[hashId][key] == command)
- delete ckb[hashId][key];
- }
- }
- };
-
- this.addCommands = function(commands) {
- Object.keys(commands).forEach(function(name) {
- var command = commands[name];
- if (typeof command === "string")
- return this.bindKey(command, name);
-
- if (typeof command === "function")
- command = { exec: command };
-
- if (!command.name)
- command.name = name;
-
- this.addCommand(command);
- }, this);
- };
-
- this.removeCommands = function(commands) {
- Object.keys(commands).forEach(function(name) {
- this.removeCommand(commands[name]);
- }, this);
- };
-
- this.bindKey = function(key, command) {
- if(!key)
- return;
-
- var ckb = this.commmandKeyBinding;
- key.split("|").forEach(function(keyPart) {
- var binding = parseKeys(keyPart, command);
- var hashId = binding.hashId;
- (ckb[hashId] || (ckb[hashId] = {}))[binding.key] = command;
- });
- };
-
- this.bindKeys = function(keyList) {
- Object.keys(keyList).forEach(function(key) {
- this.bindKey(key, keyList[key]);
- }, this);
- };
-
- this._buildKeyHash = function(command) {
- var binding = command.bindKey;
- if (!binding)
- return;
-
- var key = typeof binding == "string" ? binding: binding[this.platform];
- this.bindKey(key, command);
- }
-
- function parseKeys(keys, val, ret) {
- var key;
- var hashId = 0;
- var parts = splitSafe(keys);
-
- for (var i=0, l = parts.length; i < l; i++) {
- if (keyUtil.KEY_MODS[parts[i]])
- hashId = hashId | keyUtil.KEY_MODS[parts[i]];
- else
- key = parts[i] || "-"; //when empty, the splitSafe removed a '-'
- }
-
- return {
- key: key,
- hashId: hashId
- }
- }
-
- function splitSafe(s, separator) {
- return (s.toLowerCase()
- .trim()
- .split(new RegExp("[\\s ]*\\-[\\s ]*", "g"), 999));
- }
+oop.inherits(CommandManager, HashHandler);
- this.findKeyCommand = function findKeyCommand(hashId, textOrKey) {
- // Convert keyCode to the string representation.
- if (typeof textOrKey == "number") {
- textOrKey = keyUtil.keyCodeToString(textOrKey);
- }
+(function() {
+// oop.implement(this, HashHandler.prototype)
- var ckbr = this.commmandKeyBinding;
- return ckbr[hashId] && ckbr[hashId][textOrKey.toLowerCase()];
- }
this.exec = function(command, editor, args) {
if (typeof command === 'string')
@@ -5293,7 +5192,11 @@ var CommandManager = function(platform, commands) {
if (editor && editor.$readOnly && !command.readOnly)
return false;
- command.exec(editor, args || {});
+ if (typeof command == "function")
+ command(editor, args || {});
+ else
+ command.exec(editor, args || {});
+
return true;
};
@@ -5307,6 +5210,7 @@ var CommandManager = function(platform, commands) {
if (!this.macro.length)
this.macro = this.oldMacro;
+ editor.status.set("");
return this.recording = false;
}
this.oldMacro = this.macro;
@@ -5316,6 +5220,7 @@ var CommandManager = function(platform, commands) {
this.macro.push([command, args]);
return this.normal_exec(command, editor, args);
};
+ editor.status.set("recording_macro");
return this.recording = true;
};
@@ -5328,6 +5233,7 @@ var CommandManager = function(platform, commands) {
try {
this.$inReplay = true;
+ editor.status.set("in_replay");
this.macro.forEach(function(x) {
if (typeof x == "string")
this.exec(x, editor);
@@ -5336,6 +5242,7 @@ var CommandManager = function(platform, commands) {
}, this)
} finally {
this.$inReplay = false;
+ editor.status.set("replay_finished", 2);
}
};
@@ -5378,7 +5285,7 @@ exports.commands = [{
readOnly: true
}, {
name: "gotoline",
- bindKey: bindKey("Ctrl-R", "Command-L"),
+ bindKey: bindKey("Ctrl-G", "Command-L"),
exec: function(editor) {
var line = parseInt(prompt("Enter line number:"), 10);
if (!isNaN(line)) {
@@ -5402,6 +5309,11 @@ exports.commands = [{
exec: function(editor) { editor.session.foldAll(); },
readOnly: true
}, {
+ name: "foldadjacent",
+ bindKey: bindKey("Alt-9", "Alt-9"),
+ exec: function(editor) { editor.session.foldAdjacent(editor.getCursorPosition().row); },
+ readOnly: true
+}, {
name: "unfoldall",
bindKey: bindKey("Alt-Shift-0", "Alt-Shift-0"),
exec: function(editor) { editor.session.unfold(); },
@@ -5411,7 +5323,7 @@ exports.commands = [{
bindKey: bindKey("Ctrl-W", ""),
exec: function(editor) { editor.selection.selectWord(); },
readOnly: true
-}, , {
+}, {
name: "findnext",
bindKey: bindKey("Ctrl-R", "Command-G"),
exec: function(editor) { editor.findNext(); },
@@ -5595,6 +5507,16 @@ exports.commands = [{
exec: function(editor) { editor.commands.replay(editor); },
readOnly: true
}, {
+ name: "jumptomatching",
+ bindKey: bindKey("Ctrl-P", "Ctrl-P"),
+ exec: function(editor) { editor.jumpToMatching(); },
+ readOnly: true
+}, {
+ name: "jumpselecttomatching",
+ bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
+ exec: function(editor) { editor.jumpToMatching(true); },
+ readOnly: true
+}, {
name: "fontsize++",
bindKey: bindKey("Ctrl-+", "Command-+"),
exec: function(editor) { editor.setFontSize(null, +1) },
@@ -5614,9 +5536,30 @@ exports.commands = [{
// commands disabled in readOnly mode
{
name: "removeline",
- bindKey: bindKey("Ctrl-D", "Command-D"),
+ bindKey: bindKey("Alt-D", "Command-D"),
exec: function(editor) { editor.removeLines(); }
}, {
+ name: "duplicate",
+ bindKey: bindKey("Ctrl-D", "Command-Option-D"),
+ exec: function(editor) {
+ var sel = editor.selection;
+ var doc = editor.session;
+ var range = sel.getRange();
+ if (range.isEmpty()) {
+ var row = range.start.row;
+ doc.duplicateLines(row, row);
+ //ed.copyLinesDown();
+ } else {
+ var reverse = sel.isBackwards()
+ var point = sel.isBackwards() ? range.start : range.end;
+ var endPoint = doc.insert(point, doc.getTextRange(range), false);
+ range.start = point;
+ range.end = endPoint;
+
+ sel.setSelectionRange(range, reverse)
+ }
+ }
+}, {
name: "togglecomment",
bindKey: bindKey("Ctrl-7", "Command-7"),
exec: function(editor) { editor.toggleCommentLines(); }
@@ -5727,14 +5670,6 @@ exports.commands = [{
name: "tolowercase",
bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
exec: function(editor) { editor.toLowerCase(); }
-}, {
- name: "jumptomatching",
- bindKey: bindKey("Ctrl-P", "Ctrl-P"),
- exec: function(editor) { editor.jumpToMatching(); }
-}, {
- name: "jumpselecttomatching",
- bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
- exec: function(editor) { editor.jumpToMatching(true); }
}];
});
@@ -6241,7 +6176,7 @@ function normalizeCommandKeys(callback, e, keyCode) {
exports.addCommandKeyListener = function(el, callback) {
var addListener = exports.addListener;
- if (useragent.isOldGecko) {
+ if (useragent.isOldGecko || useragent.isOpera) {
// Old versions of Gecko aka. Firefox < 4.0 didn't repeat the keydown
// event if the user pressed the key for a longer time. Instead, the
// keydown event was fired once and later on only the keypress event.
@@ -6262,18 +6197,6 @@ exports.addCommandKeyListener = function(el, callback) {
lastDown = e.keyIdentifier || e.keyCode;
return normalizeCommandKeys(callback, e, e.keyCode);
});
-
- // repeated keys are fired as keypress and not keydown events
- if (useragent.isMac && useragent.isOpera) {
- addListener(el, "keypress", function(e) {
- var keyId = e.keyIdentifier || e.keyCode;
- if (lastDown !== keyId) {
- return normalizeCommandKeys(callback, e, lastDown);
- } else {
- lastDown = null;
- }
- });
- }
}
};
@@ -6739,7 +6662,7 @@ var Text = function(parentEl) {
// Size and width can be null if the editor is not visible or
// detached from the document
- if (size.width == 0 && size.height == 0)
+ if (!size.width || !size.height)
return null;
return size;
@@ -7213,8 +7136,8 @@ var Cursor = function(parentEl) {
};
}
- if (!position)
- position = this.session.selection.getCursor();
+ if (!position)
+ position = this.session.selection.getCursor();
var pos = this.session.documentToScreenPosition(position);
var cursorLeft = Math.round(this.$padding +
pos.column * this.config.characterWidth);
@@ -7534,12 +7457,6 @@ define("ace/css/editor.css",[], "\
cursor: text;\
}\
\
-/* setting pointer-events: auto; on node under the mouse, which changes during scroll,\
- will break mouse wheel scrolling in Safari */\
-.ace_content * {\
- pointer-events: none;\
-}\
-\
.ace_composition {\
position: absolute;\
background: #555;\
@@ -7547,12 +7464,6 @@ define("ace/css/editor.css",[], "\
z-index: 4;\
}\
\
-.ace_gutter .ace_layer {\
- position: relative;\
- min-width: 40px;\
- text-align: right;\
-}\
-\
.ace_gutter {\
position: absolute;\
overflow : hidden;\
@@ -7637,6 +7548,16 @@ define("ace/css/editor.css",[], "\
box-sizing: border-box;\
-moz-box-sizing: border-box;\
-webkit-box-sizing: border-box;\
+ /* setting pointer-events: auto; on node under the mouse, which changes\
+ during scroll, will break mouse wheel scrolling in Safari */\
+ pointer-events: none;\
+}\
+\
+.ace_gutter .ace_layer {\
+ position: relative;\
+ min-width: 40px;\
+ text-align: right;\
+ pointer-events: auto;\
}\
\
.ace_text-layer {\
@@ -7729,7 +7650,7 @@ define("ace/css/editor.css",[], "\
cursor: move;\
}\
\
-.ace_folding-enabled .ace_gutter-cell {\
+.ace_folding-enabled > .ace_gutter-cell {\
padding-right: 13px;\
}\
\
@@ -8224,7 +8145,7 @@ var Keys = (function() {
80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
188: ',', 190: '.', 191: '/', 192: '`', 219: '[', 220: '\\',
- 221: ']', 222: '\"'
+ 221: ']', 222: '\''
}
};
@@ -10056,10 +9977,55 @@ function Folding() {
};
+ this.foldAdjacent = function (startRow) {
+ var endRow = this.getLength();
+ var range, self = this;
+ var foldWidgets = this.foldWidgets;
+ var getFoldWidget = function(row) {
+ if (foldWidgets[row] == null)
+ foldWidgets[row] = self.getFoldWidget(row);
+ return foldWidgets[row];
+ }
+
+ var row = startRow || 0
+ var parentFoldFound = false
+ do {
+ var fw = getFoldWidget(row);
+ if (fw != "start")
+ continue;
+
+ if (!parentFoldFound) {
+ parentFoldFound = true
+ continue
+ }
+
+ range = this.getFoldWidgetRange(row);
+ if (range && range.end.row > startRow)
+ break
+ } while (row --> 0)
+
+ startRow = row + 1
+ if (range)
+ endRow = range.end.row
+
+ for (var row = startRow; row < endRow; row++) {
+ if (getFoldWidget(row) != "start")
+ continue
+ range = this.getFoldWidgetRange(row);
+ if (!range)
+ continue;
+ row = range.end.row;
+ if (row < endRow) try {
+ this.addFold("...", range);
+ } catch(e) {}
+ }
+ }
+
this.onFoldWidgetClick = function(row, e) {
var type = this.getFoldWidget(row);
var line = this.getLine(row);
var onlySubfolds = e.shiftKey;
+ var onlyAjacent = !e.shiftKey && !e.ctrlKey && (e.altKey || e.metaKey);
var addSubfolds = onlySubfolds || e.ctrlKey || e.altKey || e.metaKey;
var fold;
@@ -10086,6 +10052,9 @@ function Folding() {
return;
}
}
+
+ if (onlyAjacent)
+ return this.foldAdjacent(range.start.row)
if (!onlySubfolds)
this.addFold("...", range);
@@ -10094,7 +10063,7 @@ function Folding() {
this.foldAll(range.start.row + 1, range.end.row);
} else {
if (addSubfolds)
- this.foldAll(row + 1, this.getLength());
+ this.foldAll(row + 1);
e.target.className += " invalid"
}
};
@@ -10265,6 +10234,140 @@ exports.BracketMatch = BracketMatch;
});
+define("ace/keyboard/hash_handler",[], function(require, exports, module) {
+
+var keyUtil = require("ace/lib/keys");
+
+function HashHandler(config, platform) {
+ this.platform = platform;
+ this.commands = {};
+ this.commmandKeyBinding = {};
+
+ this.addCommands(config);
+};
+
+(function() {
+
+ this.addCommand = function(command) {
+ if (this.commands[command.name])
+ this.removeCommand(command);
+
+ this.commands[command.name] = command;
+
+ if (command.bindKey) {
+ this._buildKeyHash(command);
+ }
+ };
+
+ this.removeCommand = function(command) {
+ var name = (typeof command === 'string' ? command : command.name);
+ command = this.commands[name];
+ delete this.commands[name];
+
+ // exaustive search is brute force but since removeCommand is
+ // not a performance critical operation this should be OK
+ var ckb = this.commmandKeyBinding;
+ for (var hashId in ckb) {
+ for (var key in ckb[hashId]) {
+ if (ckb[hashId][key] == command)
+ delete ckb[hashId][key];
+ }
+ }
+ };
+
+ this.addCommands = function(commands) {
+ commands && Object.keys(commands).forEach(function(name) {
+ var command = commands[name];
+ if (typeof command === "string")
+ return this.bindKey(command, name);
+
+ if (typeof command === "function")
+ command = { exec: command };
+
+ if (!command.name)
+ command.name = name;
+
+ this.addCommand(command);
+ }, this);
+ };
+
+ this.removeCommands = function(commands) {
+ Object.keys(commands).forEach(function(name) {
+ this.removeCommand(commands[name]);
+ }, this);
+ };
+
+ this.bindKey = function(key, command) {
+ if(!key)
+ return;
+
+ var ckb = this.commmandKeyBinding;
+ key.split("|").forEach(function(keyPart) {
+ var binding = parseKeys(keyPart, command);
+ var hashId = binding.hashId;
+ (ckb[hashId] || (ckb[hashId] = {}))[binding.key] = command;
+ });
+ };
+
+ this.bindKeys = function(keyList) {
+ Object.keys(keyList).forEach(function(key) {
+ this.bindKey(key, keyList[key]);
+ }, this);
+ };
+
+ this._buildKeyHash = function(command) {
+ var binding = command.bindKey;
+ if (!binding)
+ return;
+
+ var key = typeof binding == "string" ? binding: binding[this.platform];
+ this.bindKey(key, command);
+ }
+
+ function parseKeys(keys, val, ret) {
+ var key;
+ var hashId = 0;
+ var parts = splitSafe(keys.toLowerCase());
+
+ for (var i=0, l = parts.length; i < l; i++) {
+ if (keyUtil.KEY_MODS[parts[i]])
+ hashId = hashId | keyUtil.KEY_MODS[parts[i]];
+ else
+ key = parts[i] || "-"; //when empty, the splitSafe removed a '-'
+ }
+
+ // Shift-(l/L) -> text-L, l/L -> text-l, (Shift-:)/: -> :
+ if (key.length == 1 && (hashId == 0 || hashId == keyUtil.KEY_MODS.shift)) {
+ if (key.toUpperCase() != key && hashId == keyUtil.KEY_MODS.shift)
+ key = key.toUpperCase();
+ hashId = -1;
+ }
+
+ return {
+ key: key,
+ hashId: hashId
+ }
+ }
+
+ function splitSafe(s, separator) {
+ return (s.trim()
+ .split(new RegExp("[\\s ]*\\-[\\s ]*", "g"), 999));
+ }
+
+ this.findKeyCommand = function findKeyCommand(hashId, keyString) {
+ var ckbr = this.commmandKeyBinding;
+ return ckbr[hashId] && ckbr[hashId][keyString];
+ }
+
+ this.handleKeyboard = function(data, hashId, keyString, keyCode) {
+ return this.findKeyCommand(hashId, keyString)
+ };
+
+}).call(HashHandler.prototype)
+
+exports.HashHandler = HashHandler;
+});
+
define("ace/tokenizer",[], function(require, exports, module) {
var Tokenizer = function(rules, flag) {
View
18 chrome/content/ace++/res/ace/mode-html.js
@@ -223,7 +223,7 @@ var HtmlHighlightRules = function() {
}, {
token : "meta.tag",
regex : "<(?=\s*style\\b)",
- next : "css"
+ next : "style"
}, {
token : "meta.tag", // opening tag
regex : "<\\/?",
@@ -262,7 +262,7 @@ var HtmlHighlightRules = function() {
};
xmlUtil.tag(this.$rules, "tag", "start");
- xmlUtil.tag(this.$rules, "css", "css-start");
+ xmlUtil.tag(this.$rules, "style", "css-start");
xmlUtil.tag(this.$rules, "script", "js-start");
this.embedRules(JavaScriptHighlightRules, "js-", [{
@@ -1214,7 +1214,7 @@ function string(state) {
token : "string", // multi line string start
merge : true,
regex : '["].*',
- next : state + "-qqstring"
+ next : state + "_qqstring"
}, {
token : "string",
regex : "'.*?'"
@@ -1222,7 +1222,7 @@ function string(state) {
token : "string", // multi line string start
merge : true,
regex : "['].*",
- next : state + "-qstring"
+ next : state + "_qstring"
}];
}
@@ -1271,17 +1271,17 @@ exports.tag = function(states, name, nextState) {
},
merge : true,
regex : "[-_a-zA-Z0-9:!]+",
- next : name + "embed-attribute-list"
+ next : name + "_embed_attribute_list"
}, {
token: "empty",
regex: "",
- next : name + "embed-attribute-list"
+ next : name + "_embed_attribute_list"
}];
- states[name + "-qstring"] = multiLineString("'", name + "embed-attribute-list");
- states[name + "-qqstring"] = multiLineString("\"", name + "embed-attribute-list");
+ states[name + "_qstring"] = multiLineString("'", name + "_embed_attribute_list");
+ states[name + "_qqstring"] = multiLineString("\"", name + "_embed_attribute_list");
- states[name + "embed-attribute-list"] = [{
+ states[name + "_embed_attribute_list"] = [{
token : "meta.tag",
merge : true,
regex : "\/?>",
View
121 chrome/content/ace++/res/beautify.js
@@ -29,9 +29,20 @@
---------------------------------
function () function()
- brace_style (default "collapse") - "collapse" | "expand" | "end-expand"
+ brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "expand-strict"
put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line.
+ expand-strict: put brace on own line even in such cases:
+
+ var a =
+ {
+ a: 5,
+ b: 6
+ }
+ This mode may break your scripts - e.g "return { a: 1 }" will be broken into two lines, so beware.
+
+ space_before_conditional: should the space before conditional statement be added, "if(true)" vs "if (true)"
+
e.g
js_beautify(js_source_text, {
@@ -62,7 +73,7 @@ function js_beautify(js_source_text, options) {
if (options.space_after_anon_function !== undefined && options.jslint_happy === undefined) {
options.jslint_happy = options.space_after_anon_function;
}
- if (options.braces_on_own_line !== undefined) { //graceful handling of depricated option
+ if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
opt_brace_style = options.braces_on_own_line ? "expand" : "collapse";
}
opt_brace_style = options.brace_style ? options.brace_style : (opt_brace_style ? opt_brace_style : "collapse");
@@ -74,6 +85,8 @@ function js_beautify(js_source_text, options) {
var opt_max_preserve_newlines = typeof options.max_preserve_newlines === 'undefined' ? false : options.max_preserve_newlines;
var opt_jslint_happy = options.jslint_happy === 'undefined' ? false : options.jslint_happy;
var opt_keep_array_indentation = typeof options.keep_array_indentation === 'undefined' ? false : options.keep_array_indentation;
+ var opt_space_before_conditional = typeof options.space_before_conditional === 'undefined' ? true : options.space_before_conditional;
+ var opt_indent_case = typeof options.indent_case === 'undefined' ? false : options.indent_case;
just_added_newline = false;
@@ -131,11 +144,20 @@ function js_beautify(js_source_text, options) {
if (flags.var_line && flags.var_line_reindented) {
output.push(indent_string); // skip space-stuffing, if indenting with a tab
}
+ if (flags.case_body) {
+ output.push(indent_string);
+ }
}
function print_single_space() {
+
+ if (last_type === 'TK_COMMENT') {
+ // no you will not print just a space after a comment
+ return print_newline(true);
+ }
+
if (flags.eat_next_space) {
flags.eat_next_space = false;
return;
@@ -180,9 +202,10 @@ function js_beautify(js_source_text, options) {
in_html_comment: false,
if_line: false,
in_case: false,
+ case_body: false,
eat_next_space: false,
indentation_baseline: -1,
- indentation_level: (flags ? flags.indentation_level + ((flags.var_line && flags.var_line_reindented) ? 1 : 0) : 0),
+ indentation_level: (flags ? flags.indentation_level + (flags.case_body?1:0) + ((flags.var_line && flags.var_line_reindented) ? 1 : 0) : 0),
ternary_depth: 0
};
}
@@ -220,6 +243,17 @@ function js_beautify(js_source_text, options) {
return false;
}
+ function look_up(exclude) {
+ var local_pos = parser_pos;
+ var c = input.charAt(local_pos);
+ while (in_array(c, whitespace) && c != exclude) {
+ local_pos++;
+ if (local_pos >= input_length) return 0;
+ c = input.charAt(local_pos);
+ }
+ return c;
+ }
+
function get_next_token() {
n_newlines = 0;
@@ -395,7 +429,7 @@ function js_beautify(js_source_text, options) {
}
}
parser_pos += 2;
- if (inline_comment) {
+ if (inline_comment && n_newlines == 0) {
return ['/*' + comment + '*/', 'TK_INLINE_COMMENT'];
} else {
return ['/*' + comment + '*/', 'TK_BLOCK_COMMENT'];
@@ -423,7 +457,7 @@ function js_beautify(js_source_text, options) {
if (c === "'" || // string
c === '"' || // string
(c === '/' &&
- ((last_type === 'TK_WORD' && in_array(last_text, ['return', 'do'])) ||
+ ((last_type === 'TK_WORD' && in_array(last_text, ['return', 'do', 'else'])) ||
(last_type === 'TK_COMMENT' || last_type === 'TK_START_EXPR' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EQUALS' || last_type === 'TK_EOF' || last_type === 'TK_SEMICOLON')))) { // regexp
var sep = c;
var esc = false;
@@ -681,7 +715,9 @@ function js_beautify(js_source_text, options) {
print_single_space();
}
} else if (in_array(last_text, line_starters) || last_text === 'catch') {
- print_single_space();
+ if (opt_space_before_conditional) {
+ print_single_space();
+ }
}
print_token();
@@ -720,16 +756,25 @@ function js_beautify(js_source_text, options) {
} else {
set_mode('BLOCK');
}
- if (opt_brace_style=="expand") {
- if (last_type !== 'TK_OPERATOR') {
- if (last_text === 'return' || last_text === '=') {
- print_single_space();
- } else {
+ if (opt_brace_style=="expand" || opt_brace_style=="expand-strict") {
+ var empty_braces = false;
+ if (opt_brace_style == "expand-strict")
+ {
+ empty_braces = (look_up() == '}');
+ if (!empty_braces) {
print_newline(true);
}
+ } else {
+ if (last_type !== 'TK_OPERATOR') {
+ if (last_text === 'return' || last_text === '=') {
+ print_single_space();
+ } else {
+ print_newline(true);
+ }
+ }
}
print_token();
- indent();
+ if (!empty_braces) indent();
} else {
if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
if (last_type === 'TK_START_BLOCK') {
@@ -756,7 +801,7 @@ function js_beautify(js_source_text, options) {
case 'TK_END_BLOCK':
restore_mode();
- if (opt_brace_style=="expand") {
+ if (opt_brace_style=="expand" || opt_brace_style == "expand-strict") {
if (last_text !== '{') {
print_newline();
}
@@ -802,7 +847,8 @@ function js_beautify(js_source_text, options) {
if (flags.var_line) {
flags.var_line_reindented = true;
}
- if ((just_added_newline || last_text === ';') && last_text !== '{') {
+ if ((just_added_newline || last_text === ';') && last_text !== '{'
+ && last_type != 'TK_BLOCK_COMMENT' && last_type != 'TK_COMMENT') {
// make sure there is a nice clean space of at least one blank line
// before a new function definition
n_newlines = just_added_newline ? n_newlines : 0;
@@ -817,17 +863,20 @@ function js_beautify(js_source_text, options) {
}
if (token_text === 'case' || token_text === 'default') {
- if (last_text === ':') {
+ if (last_text === ':' || flags.case_body) {
// switch cases following one another
remove_indent();
} else {
// case statement starts in the same line where switch
- flags.indentation_level--;
+ if (!opt_indent_case)
+ flags.indentation_level--;
print_newline();
- flags.indentation_level++;
+ if (!opt_indent_case)
+ flags.indentation_level++;
}
print_token();
flags.in_case = true;
+ flags.case_body = false;
break;
}
@@ -838,7 +887,7 @@ function js_beautify(js_source_text, options) {
if (!in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
prefix = 'NEWLINE';
} else {
- if (opt_brace_style=="expand" || opt_brace_style=="end-expand") {
+ if (opt_brace_style=="expand" || opt_brace_style=="end-expand" || opt_brace_style == "expand-strict") {
prefix = 'NEWLINE';
} else {
prefix = 'SPACE';
@@ -871,13 +920,17 @@ function js_beautify(js_source_text, options) {
} else {
prefix = 'NEWLINE';
}
+
+ if (token_text === 'function' && (last_text === 'get' || last_text === 'set')) {
+ prefix = 'SPACE';
+ }
}
if (flags.if_line && last_type === 'TK_END_EXPR') {
flags.if_line = false;
}
if (in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
- if (last_type !== 'TK_END_BLOCK' || opt_brace_style=="expand" || opt_brace_style=="end-expand") {
+ if (last_type !== 'TK_END_BLOCK' || opt_brace_style=="expand" || opt_brace_style=="end-expand" || opt_brace_style == "expand-strict") {
print_newline();
} else {
trim_output(true);
@@ -945,7 +998,7 @@ function js_beautify(js_source_text, options) {
case 'TK_STRING':
- if (last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_SEMICOLON') {
+ if (last_type == 'TK_STRING' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_SEMICOLON') {
print_newline();
} else if (last_type === 'TK_WORD') {
print_single_space();
@@ -998,6 +1051,8 @@ function js_beautify(js_source_text, options) {
}
if (token_text === ':' && flags.in_case) {
+ if (opt_indent_case)
+ flags.case_body = true;
print_token(); // colon really asks for separate treatment
print_newline();
flags.in_case = false;
@@ -1109,10 +1164,13 @@ function js_beautify(js_source_text, options) {
if (lines.length > 1) {
// multiline comment block starts with a new line
print_newline();
- trim_output();
} else {
// single-line /* comment */ stays where it is
- print_single_space();
+ if (last_type === 'TK_END_BLOCK') {
+ print_newline();
+ } else {
+ print_single_space();
+ }
}
@@ -1122,11 +1180,11 @@ function js_beautify(js_source_text, options) {
}
}
- print_newline();
+ if(look_up('\n') != '\n')
+ print_newline();
break;
case 'TK_INLINE_COMMENT':
-
print_single_space();
print_token();
if (is_expression(flags.mode)) {
@@ -1145,7 +1203,8 @@ function js_beautify(js_source_text, options) {
print_single_space();
}
print_token();
- force_newline();
+ if(look_up('\n') != '\n')
+ force_newline();
break;
case 'TK_UNKNOWN':
@@ -1817,10 +1876,12 @@ function style_html(html_source, options) {
break;
case 'TK_TAG_END':
//Print new line only if the tag has no content and has child
- if ((multi_parser.last_token === 'TK_CONTENT' && multi_parser.last_text === '')
- && (multi_parser.output[multi_parser.output.length -1]
- .indexOf(multi_parser.token_text.replace("</", "<").replace(">", " ")) !== 0))
- multi_parser.print_newline(true, multi_parser.output);
+ if (multi_parser.last_token === 'TK_CONTENT' && multi_parser.last_text === '') {
+ var tag_name = multi_parser.token_text.match(/\w+/)[0];
+ var tag_extracted_from_last_output = multi_parser.output[multi_parser.output.length -1].match(/<\s*(\w+)/);
+ if (tag_extracted_from_last_output === null || tag_extracted_from_last_output[1] !== tag_name)
+ multi_parser.print_newline(true, multi_parser.output);
+ }
multi_parser.print_token(multi_parser.token_text);
multi_parser.current_mode = 'CONTENT';
break;
@@ -1879,4 +1940,4 @@ function style_html(html_source, options) {
multi_parser.last_text = multi_parser.token_text;
}
return multi_parser.output.join('');
-}
+}
View
131 chrome/content/ace++/startup.js
@@ -1,82 +1,3 @@
-define('ace/keyboard/hash_handler', function(require, exports, module) {
-
-var keyUtil = require("ace/lib/keys");
-
-function HashHandler(config) {
- this.setConfig(config);
-}
-
-(function() {
- function splitSafe(s, separator, limit, bLowerCase) {
- return s.toLowerCase().split('-');
- }
-
- function parseKeys(keys, val, ret) {
- var key,
- hashId = 0,
- parts = splitSafe(keys, "\\-", null, true),
- i = 0,
- l = parts.length;
-
- for (; i < l; ++i) {
- if (keyUtil.KEY_MODS[parts[i]])
- hashId = hashId | keyUtil.KEY_MODS[parts[i]];
- else
- key = parts[i] || "-"; //when empty, the splitSafe removed a '-'
- }
-
- (ret[hashId] || (ret[hashId] = {}))[key] = val;
- return ret;
- }
-
- function objectReverse(obj, keySplit) {
- var i, j, l, key,
- ret = {};
- for (i in obj) {
- key = obj[i];
- if (keySplit && typeof key == "string") {
- key = key.split(keySplit);
- for (j = 0, l = key.length; j < l; ++j)
- parseKeys.call(this, key[j], i, ret);
- }
- else {
- parseKeys.call(this, key, i, ret);
- }
- }
- return ret;
- }
-
- this.setConfig = function(config) {
- this.$config = config;
- if (typeof this.$config.reverse == "undefined")
- this.$config.reverse = objectReverse.call(this, this.$config, "|");
- };
-
- /**
- * This function is called by keyBinding.
- */
- this.handleKeyboard = function(data, hashId, textOrKey, keyCode) {
- // Figure out if a commandKey was pressed or just some text was insert.
- if (hashId != 0 || keyCode != 0) {
- return {
- command: (this.$config.reverse[hashId] || {})[textOrKey]
- }
- } else {
- return {
- command: "inserttext",
- args: {
- text: textOrKey
- }
- }
- }
- }
-}).call(HashHandler.prototype);
-
-exports.HashHandler = HashHandler;
-});
-
-
-
/************************************************************************************/
define('fbace/startup', function(require, exports, module) {
@@ -98,7 +19,7 @@ exports.launch = function(env, options) {
/**************************** breakpoint handler *********************************************/
- function CStyleFolding() {
+ function SmartBreakpoints() {
this.setBreakpointsAtRows = function(rows) {
this.$breakpoints = [];
for (var i=0; i<rows.length; i++) {
@@ -182,7 +103,7 @@ exports.launch = function(env, options) {
this.doc.on('change', this.updateDataOnDocChange.bind(this));
}
};
- CStyleFolding.call(EditSession.prototype);
+ SmartBreakpoints.call(EditSession.prototype);
/**************************** initialize ****************************************************/
// global functions
@@ -276,23 +197,6 @@ exports.launch = function(env, options) {
Renderer.prototype.moveTextAreaToCursor =
require("ace/layer/text").Text.prototype.$pollSizeChanges = function(){}
// selection on first/last lines
- Renderer.prototype.screenToTextCoordinates = function(pageX, pageY) {
- var canvasPos = this.scroller.getBoundingClientRect();
-
- var col = Math.round((pageX + this.scroller.scrollLeft - canvasPos.left - this.$padding - window.pageYOffset)
- / this.characterWidth);
- var row = Math.floor((pageY + this.scrollTop - canvasPos.top - window.pageYOffset)
- / this.lineHeight);
- if (row < 0) {
- row = 0
- } else {
- var maxRow = this.layerConfig.maxHeight/this.layerConfig.lineHeight-1
- if(row > maxRow)
- row = maxRow
- }
-
- return this.session.screenToDocumentPosition(row, Math.max(col, 0));
- };
var container = document.getElementById("editor");
editor = env.editor = new Editor(new Renderer(container, options.theme));
@@ -395,19 +299,7 @@ exports.launch = function(env, options) {
// add commands
editor.addCommands({
- duplicate: function(editor, args, request) {
- var sel = editor.selection;
- var doc = editor.session;
- var range = sel.getRange();
- if (range.isEmpty()) {
- var row = range.start.row;
- doc.duplicateLines(row, row);
- //ed.copyLinesDown();
- } else {
- doc.insert(sel.selectionLead, doc.getTextRange(range), false);
- }
- },
- startAutocompleter: function(editor, args, request) {
+ startAutocompleter: function(editor) {
startAcebugAutocompleter(editor);
},
toggleStreamComment: function() {
@@ -523,12 +415,7 @@ exports.launch = function(env, options) {
}
});
- var com = canon.getCommand('removeline')
- com.bindKey.win = com.bindKey.mac = 'Alt-D'
- //canon.removeCommand('removeline')
- canon.addCommand(com)
-
- canon.addCommand({
+ canon.addCommands([{
name: "save",
bindKey: {
win: "Ctrl-S",
@@ -537,8 +424,7 @@ exports.launch = function(env, options) {
exec: function(editor) {
aceManager.saveFile(editor, "session")
}
- });
- canon.addCommand({
+ }, {
name: "save-as",
bindKey: {
win: "Ctrl-Shift-S",
@@ -547,8 +433,7 @@ exports.launch = function(env, options) {
exec: function(editor) {
aceManager.saveFile(editor, "picker")
}
- });
- canon.addCommand({
+ }, {
name: "load",
bindKey: {
win: "Ctrl-O",
@@ -557,9 +442,9 @@ exports.launch = function(env, options) {
exec: function(editor) {
aceManager.loadFile(editor)
}
- });
+ }]);
- /**************************** folding commands ***********************************************/
+ /**************************** misc ***********************************************/
canon.addCommand({
name: "newCell",
bindKey: {
View
21 chrome/content/ace++/styles.css
@@ -81,13 +81,12 @@ separator{
position: absolute;
width: 28px;
height: 28px;
- margin: -14px 0 0 -14px
+ margin: -14px 0 0 -14px;
border: 1px solid red;
z-index: 10000;
display: none;
top:50%;
left:50%;
- -moz-border-radius: 2px;
border-radius: 2px;
border: 1px solid transparent;
}
@@ -102,7 +101,6 @@ separator{
bottom: 0;
position: fixed;
z-index: 1000;
- -moz-border-radius-topright: 20px;
border-top-right-radius: 20px;
}
@@ -117,15 +115,13 @@ separator{
width: 10px;
background: lightblue;
top: 0;
- /right:4px;
position: fixed;
z-index: 1000;
- -moz-border-radius-bottomright: 20px;
border-bottom-right-radius: 20px;
}
#toggleWrap:hover{
- -moz-box-shadow: 2px -1px 5px 3px #91B6D5;
+ box-shadow: 2px -1px 5px 3px #91B6D5;
border-right: 1px solid #A1A1CF;
border-bottom: 1px solid #A1A1CF;
}
@@ -181,12 +177,6 @@ separator{
background:rgba(120,50,100,0.1);
color: darkred;
}
-.ace_filler{
- //background: none repeat scroll 0 0 rgba(100, 50, 100, 0.2);
- display: inline-block;
- border-top: 1px solid gray;
- width: 100%;
-}
.ace_firstcell{
border-top: 1px solid gray;
@@ -197,7 +187,7 @@ separator{
color: darkred;
}
.ace_filler{
- //background: none repeat scroll 0 0 rgba(100, 50, 100, 0.2);
+ /*background: none repeat scroll 0 0 rgba(100, 50, 100, 0.2);*/
display: inline-block;
border-top: 1px solid gray;
width: 100%;
@@ -215,13 +205,12 @@ separator{
.ace_gutter-cell.ace_breakpoint{
border-radius: 20px 0 0 20px;
box-shadow: 0 0 1px 1px red inset;
- -moz-box-shadow: 0 0 1px 1px gold inset;
}
.ace_gutter-cell.ace_breakpoint.invalid{
- -moz-box-shadow: 0 0 1px 1px red inset;
+ box-shadow: 0 0 1px 1px red inset;
}
.ace_gutter-cell.ace_breakpoint.valid{
- -moz-box-shadow: 0 0 1px 1px lime inset;
+ box-shadow: 0 0 1px 1px lime inset;
}
Please sign in to comment.
Something went wrong with that request. Please try again.