Browse files

update ace

  • Loading branch information...
1 parent 3485dbe commit 114724ffca043bcc52226d6dc88b2578429e64af @nightwing nightwing committed Jul 19, 2012
Showing with 8,169 additions and 3,724 deletions.
  1. +6,464 −2,394 chrome/content/ace++/res/ace/ace.js
  2. +293 −297 chrome/content/ace++/res/ace/keybinding-emacs.js
  3. +535 −601 chrome/content/ace++/res/ace/keybinding-vim.js
  4. +19 −15 chrome/content/ace++/res/ace/theme-chrome.js
  5. +25 −11 chrome/content/ace++/res/ace/theme-clouds.js
  6. +27 −13 chrome/content/ace++/res/ace/theme-clouds_midnight.js
  7. +35 −13 chrome/content/ace++/res/ace/theme-cobalt.js
  8. +19 −15 chrome/content/ace++/res/ace/theme-crimson_editor.js
  9. +33 −11 chrome/content/ace++/res/ace/theme-dawn.js
  10. +20 −12 chrome/content/ace++/res/ace/theme-eclipse.js
  11. +36 −14 chrome/content/ace++/res/ace/theme-idle_fingers.js
  12. +35 −13 chrome/content/ace++/res/ace/theme-kr_theme.js
  13. +34 −12 chrome/content/ace++/res/ace/theme-merbivore.js
  14. +35 −13 chrome/content/ace++/res/ace/theme-merbivore_soft.js
  15. +34 −12 chrome/content/ace++/res/ace/theme-mono_industrial.js
  16. +25 −12 chrome/content/ace++/res/ace/theme-monokai.js
  17. +35 −13 chrome/content/ace++/res/ace/theme-pastel_on_dark.js
  18. +26 −12 chrome/content/ace++/res/ace/theme-solarized_dark.js
  19. +25 −11 chrome/content/ace++/res/ace/theme-solarized_light.js
  20. +27 −13 chrome/content/ace++/res/ace/theme-tomorrow.js
  21. +27 −13 chrome/content/ace++/res/ace/theme-tomorrow_night.js
  22. +27 −13 chrome/content/ace++/res/ace/theme-tomorrow_night_blue.js
  23. +27 −13 chrome/content/ace++/res/ace/theme-tomorrow_night_bright.js
  24. +27 −13 chrome/content/ace++/res/ace/theme-tomorrow_night_eighties.js
  25. +35 −13 chrome/content/ace++/res/ace/theme-twilight.js
  26. +35 −13 chrome/content/ace++/res/ace/theme-vibrant_ink.js
  27. +201 −135 chrome/content/ace++/res/beautify.js
  28. +2 −2 chrome/content/ace++/res/coffee-script.js
  29. +5 −1 chrome/content/ace++/startup.js
  30. +1 −1 chrome/content/ace++/styles.css
View
8,858 chrome/content/ace++/res/ace/ace.js
6,464 additions, 2,394 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
590 chrome/content/ace++/res/ace/keybinding-emacs.js
@@ -1,333 +1,329 @@
define("ace/keyboard/emacs",[], function(require, exports, module) {
-var StateHandler = require("ace/keyboard/state_handler").StateHandler;
-var matchCharacterOnly = require("ace/keyboard/state_handler").matchCharacterOnly;
-
-var emacsState = {
- start: [
- {
- key: "ctrl-x",
- then: "c-x"
- },
- {
- regex: [ "(?:command-([0-9]*))*", "(down|ctrl-n)" ],
- exec: "golinedown",
- params: [
- {
- name: "times",
- match: 1,
- type: "number",
- defaultValue: 1
- }
- ]
- },
- {
- regex: [ "(?:command-([0-9]*))*", "(right|ctrl-f)" ],
- exec: "gotoright",
- params: [
- {
- name: "times",
- match: 1,
- type: "number",
- defaultValue: 1
- }
- ]
- },
- {
- regex: [ "(?:command-([0-9]*))*", "(up|ctrl-p)" ],
- exec: "golineup",
- params: [
- {
- name: "times",
- match: 1,
- type: "number",
- defaultValue: 1
- }
- ]
- },
- {
- regex: [ "(?:command-([0-9]*))*", "(left|ctrl-b)" ],
- exec: "gotoleft",
- params: [
- {
- name: "times",
- match: 1,
- type: "number",
- defaultValue: 1
- }
- ]
- },
- {
- comment: "This binding matches all printable characters except numbers as long as they are no numbers and print them n times.",
- regex: [ "(?:command-([0-9]*))", "([^0-9]+)*" ],
- match: matchCharacterOnly,
- exec: "inserttext",
- params: [
- {
- name: "times",
- match: 1,
- type: "number",
- defaultValue: "1"
- },
- {
- name: "text",
- match: 2
- }
- ]
- },
- {
- comment: "This binding matches numbers as long as there is no meta_number in the buffer.",
- regex: [ "(command-[0-9]*)*", "([0-9]+)" ],
- match: matchCharacterOnly,
- disallowMatches: [ 1 ],
- exec: "inserttext",
- params: [
- {
- name: "text",
- match: 2,
- type: "text"
- }
- ]
- },
- {
- regex: [ "command-([0-9]*)", "(command-[0-9]|[0-9])" ],
- comment: "Stops execution if the regex /meta_[0-9]+/ matches to avoid resetting the buffer."
- }
- ],
- "c-x": [
- {
- key: "ctrl-g",
- then: "start"
- },
- {
- key: "ctrl-s",
- exec: "save",
- then: "start"
- }
- ]
+var dom = require("ace/lib/dom");
+
+var screenToTextBlockCoordinates = function(pageX, pageY) {
+ var canvasPos = this.scroller.getBoundingClientRect();
+
+ var col = Math.floor(
+ (pageX + this.scrollLeft - canvasPos.left - this.$padding - dom.getPageScrollLeft()) / this.characterWidth
+ );
+ var row = Math.floor(
+ (pageY + this.scrollTop - canvasPos.top - dom.getPageScrollTop()) / this.lineHeight
+ );
+
+ return this.session.screenToDocumentPosition(row, col);
};
-exports.handler = new StateHandler(emacsState);
+var HashHandler = require("ace/keyboard/hash_handler").HashHandler;
+exports.handler = new HashHandler();
+
+var initialized = false;
+exports.handler.attach = function(editor) {
+ if (!initialized) {
+ initialized = true;
+ dom.importCssString('\
+ .emacs-mode .ace_cursor{\
+ border: 2px rgba(50,250,50,0.8) solid!important;\
+ -moz-box-sizing: border-box!important;\
+ box-sizing: border-box!important;\
+ background-color: rgba(0,250,0,0.9);\
+ opacity: 0.5;\
+ }\
+ .emacs-mode .ace_cursor.ace_hidden{\
+ opacity: 1;\
+ background-color: transparent;\
+ }\
+ .emacs-mode .ace_cursor.ace_overwrite {\
+ opacity: 1;\
+ background-color: transparent;\
+ border-width: 0 0 2px 2px !important;\
+ }\
+ .emacs-mode .ace_text-layer {\
+ z-index: 4\
+ }\
+ .emacs-mode .ace_cursor-layer {\
+ z-index: 2\
+ }', 'emacsMode'
+ );
+ }
+
+ editor.renderer.screenToTextCoordinates = screenToTextBlockCoordinates;
+ editor.setStyle("emacs-mode");
+};
+
+exports.handler.detach = function(editor) {
+ delete editor.renderer.screenToTextCoordinates;
+ editor.unsetStyle("emacs-mode");
+};
+
+var keys = require("ace/lib/keys").KEY_MODS;
+var eMods = {
+ C: "ctrl", S: "shift", M: "alt"
+};
+["S-C-M", "S-C", "S-M", "C-M", "S", "C", "M"].forEach(function(c) {
+ var hashId = 0;
+ c.split("-").forEach(function(c){
+ hashId = hashId | keys[eMods[c]];
+ });
+ eMods[hashId] = c.toLowerCase() + "-";
});
-define("ace/keyboard/state_handler",[], function(require, exports, module) {
-
-// If you're developing a new keymapping and want to get an idea what's going
-// on, then enable debugging.
-var DEBUG = false;
-
-function StateHandler(keymapping) {
- this.keymapping = this.$buildKeymappingRegex(keymapping);
-}
-
-StateHandler.prototype = {
- /**
- * Build the RegExp from the keymapping as RegExp can't stored directly
- * in the metadata JSON and as the RegExp used to match the keys/buffer
- * need to be adapted.
- */
- $buildKeymappingRegex: function(keymapping) {
- for (var state in keymapping) {
- this.$buildBindingsRegex(keymapping[state]);
- }
- return keymapping;
- },
+exports.handler.bindKey = function(key, command) {
+ if (!key)
+ return;
+
+ var ckb = this.commmandKeyBinding;
+ key.split("|").forEach(function(keyPart) {
+ keyPart = keyPart.toLowerCase();
+ ckb[keyPart] = command;
+ keyPart = keyPart.split(" ")[0];
+ if (!ckb[keyPart])
+ ckb[keyPart] = "null";
+ }, this);
+};
- $buildBindingsRegex: function(bindings) {
- // Escape a given Regex string.
- bindings.forEach(function(binding) {
- if (binding.key) {
- binding.key = new RegExp('^' + binding.key + '$');
- } else if (Array.isArray(binding.regex)) {
- if (!('key' in binding))
- binding.key = new RegExp('^' + binding.regex[1] + '$');
- binding.regex = new RegExp(binding.regex.join('') + '$');
- } else if (binding.regex) {
- binding.regex = new RegExp(binding.regex + '$');
- }
- });
- },
- $composeBuffer: function(data, hashId, key, e) {
- // Initialize the data object.
- if (data.state == null || data.buffer == null) {
- data.state = "start";
- data.buffer = "";
+exports.handler.handleKeyboard = function(data, hashId, key, keyCode) {
+ if (hashId == -1) {
+ if (data.count) {
+ var str = Array(data.count + 1).join(key);
+ data.count = null;
+ return {command: "insertstring", args: str};
}
+ }
- var keyArray = [];
- if (hashId & 1) keyArray.push("ctrl");
- if (hashId & 8) keyArray.push("command");
- if (hashId & 2) keyArray.push("option");
- if (hashId & 4) keyArray.push("shift");
- if (key) keyArray.push(key);
-
- var symbolicName = keyArray.join("-");
- var bufferToUse = data.buffer + symbolicName;
-
- // Don't add the symbolic name to the key buffer if the alt_ key is
- // part of the symbolic name. If it starts with alt_, this means
- // that the user hit an alt keycombo and there will be a single,
- // new character detected after this event, which then will be
- // added to the buffer (e.g. alt_j will result in ∆).
- //
- // We test for 2 and not for & 2 as we only want to exclude the case where
- // the option key is pressed alone.
- if (hashId != 2) {
- data.buffer = bufferToUse;
+ if (key == "\x00")
+ return;
+
+ var modifier = eMods[hashId];
+ if (modifier == "c-" || data.universalArgument) {
+ var count = parseInt(key[key.length - 1]);
+ if (count) {
+ data.count = count;
+ return {command: "null"};
}
+ }
+ data.universalArgument = false;
- var bufferObj = {
- bufferToUse: bufferToUse,
- symbolicName: symbolicName,
- };
+ if (modifier)
+ key = modifier + key;
- if (e) {
- bufferObj.keyIdentifier = e.keyIdentifier
- }
+ if (data.keyChain)
+ key = data.keyChain += " " + key;
- return bufferObj;
- },
+ var command = this.commmandKeyBinding[key];
+ data.keyChain = command == "null" ? key : "";
- $find: function(data, buffer, symbolicName, hashId, key, keyIdentifier) {
- // Holds the command to execute and the args if a command matched.
- var result = {};
+ if (!command)
+ return;
- // Loop over all the bindings of the keymap until a match is found.
- this.keymapping[data.state].some(function(binding) {
- var match;
+ if (command == "null")
+ return {command: "null"};
- // Check if the key matches.
- if (binding.key && !binding.key.test(symbolicName)) {
- return false;
- }
+ if (command == "universalArgument") {
+ data.universalArgument = true;
+ return {command: "null"};
+ }
- // Check if the regex matches.
- if (binding.regex && !(match = binding.regex.exec(buffer))) {
- return false;
- }
+ if (typeof command != "string") {
+ var args = command.args;
+ command = command.command;
+ }
- // Check if the match function matches.
- if (binding.match && !binding.match(buffer, hashId, key, symbolicName, keyIdentifier)) {
- return false;
- }
+ if (typeof command == "string") {
+ command = this.commands[command] || data.editor.commands.commands[command];
+ }
- // Check for disallowed matches.
- if (binding.disallowMatches) {
- for (var i = 0; i < binding.disallowMatches.length; i++) {
- if (!!match[binding.disallowMatches[i]]) {
- return false;
- }
+ if (!command.readonly && !command.isYank)
+ data.lastCommand = null;
+
+ if (data.count) {
+ var count = data.count;
+ data.count = 0;
+ return {
+ args: args,
+ command: {
+ exec: function(editor, args) {
+ for (var i = 0; i < count; i++)
+ command.exec(editor, args);
}
}
+ };
+ }
- // If there is a command to execute, then figure out the
- // command and the arguments.
- if (binding.exec) {
- result.command = binding.exec;
-
- // Build the arguments.
- if (binding.params) {
- var value;
- result.args = {};
- binding.params.forEach(function(param) {
- if (param.match != null && match != null) {
- value = match[param.match] || param.defaultValue;
- } else {
- value = param.defaultValue;
- }
-
- if (param.type === 'number') {
- value = parseInt(value);
- }
-
- result.args[param.name] = value;
- });
- }
- data.buffer = "";
- }
+ return {command: command, args: args};
+};
- // Handle the 'then' property.
- if (binding.then) {
- data.state = binding.then;
- data.buffer = "";
- }
+exports.emacsKeys = {
+ // movement
+ "Up|C-p" : "golineup",
+ "Down|C-n" : "golinedown",
+ "Left|C-b" : "gotoleft",
+ "Right|C-f" : "gotoright",
+ "C-Left|M-b" : "gotowordleft",
+ "C-Right|M-f" : "gotowordright",
+ "Home|C-a" : "gotolinestart",
+ "End|C-e" : "gotolineend",
+ "C-Home|S-M-,": "gotostart",
+ "C-End|S-M-." : "gotoend",
+
+ // selection
+ "S-Up|S-C-p" : "selectup",
+ "S-Down|S-C-n" : "selectdown",
+ "S-Left|S-C-b" : "selectleft",
+ "S-Right|S-C-f" : "selectright",
+ "S-C-Left|S-M-b" : "selectwordleft",
+ "S-C-Right|S-M-f" : "selectwordright",
+ "S-Home|S-C-a" : "selecttolinestart",
+ "S-End|S-C-e" : "selecttolineend",
+ "S-C-Home" : "selecttostart",
+ "S-C-End" : "selecttoend",
+
+ "C-l|M-s" : "centerselection",
+ "M-g": "gotoline",
+ "C-x C-p": "selectall",
+
+ // todo fix these
+ "C-Down": "gotopagedown",
+ "C-Up": "gotopageup",
+ "PageDown|C-v": "gotopagedown",
+ "PageUp|M-v": "gotopageup",
+ "S-C-Down": "selectpagedown",
+ "S-C-Up": "selectpageup",
+ "C-s": "findnext",
+ "C-r": "findprevious",
+ "M-C-s": "findnext",
+ "M-C-r": "findprevious",
+ "S-M-5": "replace",
+
+ // basic editing
+ "Backspace": "backspace",
+ "Delete|C-d": "del",
+ "Return|C-m": {command: "insertstring", args: "\n"}, // "newline"
+ "C-o": "splitline",
+
+ "M-d|C-Delete": {command: "killWord", args: "right"},
+ "C-Backspace|M-Backspace|M-Delete": {command: "killWord", args: "left"},
+ "C-k": "killLine",
+
+ "C-y|S-Delete": "yank",
+ "M-y": "yankRotate",
+ "C-g": "keyboardQuit",
+
+ "C-w": "killRegion",
+ "M-w": "killRingSave",
+
+ "C-Space": "setMark",
+ "C-x C-x": "exchangePointAndMark",
+
+ "C-t": "transposeletters",
+
+ "M-u": "touppercase",
+ "M-l": "tolowercase",
+ "M-/": "autocomplete",
+ "C-u": "universalArgument",
+ "M-;": "togglecomment",
+
+ "C-/|C-x u|S-C--|C-z": "undo",
+ "S-C-/|S-C-x u|C--|S-C-z": "redo", //infinite undo?
+ // vertical editing
+ "C-x r": "selectRectangularRegion"
+
+ // todo
+ // "M-x" "C-x C-t" "M-t" "M-c" "F11" "C-M- "M-q"
+};
- // If no command is set, then execute the "null" fake command.
- if (result.command == null) {
- result.command = "null";
- }
- if (DEBUG) {
- console.log("KeyboardStateMapper#find", binding);
- }
- return true;
- });
-
- if (result.command) {
- return result;
- } else {
- data.buffer = "";
- return false;
- }
- },
+exports.handler.bindKeys(exports.emacsKeys);
- /**
- * This function is called by keyBinding.
- */
- handleKeyboard: function(data, hashId, key, keyCode, e) {
- if (hashId == -1)
- hashId = 0
- // If we pressed any command key but no other key, then ignore the input.
- // Otherwise "shift-" is added to the buffer, and later on "shift-g"
- // which results in "shift-shift-g" which doesn't make sense.
- if (hashId != 0 && (key == "" || key == String.fromCharCode(0))) {
- return null;
- }
+exports.handler.addCommands({
+ selectRectangularRegion: function(editor) {
+ editor.multiSelect.toggleBlockSelection();
+ },
+ setMark: function() {
+ },
+ exchangePointAndMark: {
+ exec: function(editor) {
+ var range = editor.selection.getRange();
+ editor.selection.setSelectionRange(range, !editor.selection.isBackwards());
+ },
+ readonly: true,
+ multiselectAction: "forEach"
+ },
+ killWord: {
+ exec: function(editor, dir) {
+ editor.clearSelection();
+ if (dir == "left")
+ editor.selection.selectWordLeft();
+ else
+ editor.selection.selectWordRight();
+
+ var range = editor.getSelectionRange();
+ var text = editor.session.getTextRange(range);
+ exports.killRing.add(text);
+
+ editor.session.remove(range);
+ editor.clearSelection();
+ },
+ multiselectAction: "forEach"
+ },
+ killLine: function(editor) {
+ editor.selection.selectLine();
+ var range = editor.getSelectionRange();
+ var text = editor.session.getTextRange(range);
+ exports.killRing.add(text);
+
+ editor.session.remove(range);
+ editor.clearSelection();
+ },
+ yank: function(editor) {
+ editor.onPaste(exports.killRing.get());
+ editor.keyBinding.$data.lastCommand = "yank";
+ },
+ yankRotate: function(editor) {
+ if (editor.keyBinding.$data.lastCommand != "yank")
+ return;
- // Compute the current value of the keyboard input buffer.
- var r = this.$composeBuffer(data, hashId, key, e);
- var buffer = r.bufferToUse;
- var symbolicName = r.symbolicName;
- var keyId = r.keyIdentifier;
+ editor.undo();
+ editor.onPaste(exports.killRing.rotate());
+ editor.keyBinding.$data.lastCommand = "yank";
+ },
+ killRegion: function(editor) {
+ exports.killRing.add(editor.getCopyText());
+ editor.cut();
+ },
+ killRingSave: function(editor) {
+ exports.killRing.add(editor.getCopyText());
+ }
+});
- r = this.$find(data, buffer, symbolicName, hashId, key, keyId);
- if (DEBUG) {
- console.log("KeyboardStateMapper#match", buffer, symbolicName, r);
- }
+var commands = exports.handler.commands;
+commands.yank.isYank = true;
+commands.yankRotate.isYank = true;
- return r;
- }
-}
-
-/**
- * This is a useful matching function and therefore is defined here so that
- * users of KeyboardStateMapper can use it.
- *
- * @return boolean
- * If no command key (Command|Option|Shift|Ctrl) is pressed, it
- * returns true. If the only the Shift key is pressed + a character
- * true is returned as well. Otherwise, false is returned.
- * Summing up, the function returns true whenever the user typed
- * a normal character on the keyboard and no shortcut.
- */
-exports.matchCharacterOnly = function(buffer, hashId, key, symbolicName) {
- // If no command keys are pressed, then catch the input.
- if (hashId == 0) {
- return true;
- }
- // If only the shift key is pressed and a character key, then
- // catch that input as well.
- else if ((hashId == 4) && key.length == 1) {
- return true;
- }
- // Otherwise, we let the input got through.
- else {
- return false;
+exports.killRing = {
+ $data: [],
+ add: function(str) {
+ str && this.$data.push(str);
+ if (this.$data.length > 30)
+ this.$data.shift();
+ },
+ get: function() {
+ return this.$data[this.$data.length - 1] || "";
+ },
+ pop: function() {
+ if (this.$data.length > 1)
+ this.$data.pop();
+ return this.get();
+ },
+ rotate: function() {
+ this.$data.unshift(this.$data.pop());
+ return this.get();
}
};
-exports.StateHandler = StateHandler;
+
});
View
1,136 chrome/content/ace++/res/ace/keybinding-vim.js
@@ -1,27 +1,83 @@
define("ace/keyboard/vim",[], function(require, exports, module) {
-"never use strict";
-
-var commands = require("ace/keyboard/vim/commands");
+var keyUtil = require("ace/lib/keys");
+var cmds = require("ace/keyboard/vim/commands");
+var coreCommands = cmds.coreCommands;
var util = require("ace/keyboard/vim/maps/util");
-exports.handler = require("ace/keyboard/vim/keyboard").handler;
-
-exports.onCursorMove = function(e) {
- commands.onCursorMove(e.editor, e);
- exports.onCursorMove.scheduled = false;
+var startCommands = {
+ "i": {
+ command: coreCommands.start
+ },
+ "I": {
+ command: coreCommands.startBeginning
+ },
+ "a": {
+ command: coreCommands.append
+ },
+ "A": {
+ command: coreCommands.appendEnd
+ },
+ "ctrl-f": {
+ command: "gotopagedown"
+ },
+ "ctrl-b": {
+ command: "gotopageup"
+ },
};
-exports.handler.attach = function(editor) {
- editor.on("click", exports.onCursorMove);
- if (util.currentMode !== "insert")
- commands.coreCommands.stop.exec(editor);
+exports.handler = {
+ handleKeyboard: function(data, hashId, key, keyCode, e) {
+ // ignore command keys (shift, ctrl etc.)
+ if (hashId != 0 && (key == "" || key == "\x00"))
+ return null;
+
+ if (hashId == 1)
+ key = "ctrl-" + key;
+
+ if (data.state == "start") {
+ if (hashId == -1 || hashId == 1) {
+ if (cmds.inputBuffer.idle && startCommands[key])
+ return startCommands[key];
+
+ return { command: {
+ exec: function(editor) {cmds.inputBuffer.push(editor, key);}
+ } };
+ } // wait for input
+ else if (key.length == 1 && (hashId == 0 || hashId == 4)) { //no modifier || shift
+ return {command: "null", passEvent: true};
+ } else if (key == "esc") {
+ return {command: coreCommands.stop};
+ }
+ } else {
+ if (key == "esc" || key == "ctrl-[") {
+ data.state = "start";
+ return {command: coreCommands.stop};
+ } else if (key == "ctrl-w") {
+ return {command: "removewordleft"};
+ }
+ }
+ },
+
+ attach: function(editor) {
+ editor.on("click", exports.onCursorMove);
+ if (util.currentMode !== "insert")
+ cmds.coreCommands.stop.exec(editor);
+ },
+
+ detach: function(editor) {
+ editor.removeListener("click", exports.onCursorMove);
+ util.noMode(editor);
+ util.currentMode = "normal";
+ },
+
+ actions: cmds.actions
};
-exports.handler.detach = function(editor) {
- editor.removeListener("click", exports.onCursorMove);
- util.noMode(editor);
- util.currentMode = "normal";
+
+exports.onCursorMove = function(e) {
+ cmds.onCursorMove(e.editor, e);
+ exports.onCursorMove.scheduled = false;
};
});
@@ -42,62 +98,43 @@ var MOTION = 3;
var ACTION = 4;
var HMARGIN = 8; // Minimum amount of line separation between margins;
-exports.searchStore = {
- current: "",
- options: {
- needle: "",
- backwards: false,
- wrap: true,
- caseSensitive: false,
- wholeWord: false,
- regExp: false
- }
-};
-
var repeat = function repeat(fn, count, args) {
while (0 < count--)
fn.apply(this, args);
};
-var toggleCase = function toggleCase(str) {
- if (str[0].toUpperCase() === str[0])
- return str.toLowerCase();
- else
- return str.toUpperCase();
-};
-
var ensureScrollMargin = function(editor) {
- var renderer = editor.renderer
- var pos = renderer.$cursorLayer.getPixelPosition();
-
- var top = pos.top;
-
- var margin = HMARGIN * renderer.layerConfig.lineHeight;
- if (2 * margin > renderer.$size.scrollerHeight)
- margin = renderer.$size.scrollerHeight / 2
-
- if (renderer.scrollTop > top - margin) {
- renderer.session.setScrollTop(top - margin);
- }
-
- if (renderer.scrollTop + renderer.$size.scrollerHeight < top + margin + renderer.lineHeight) {
- renderer.session.setScrollTop(top + margin + renderer.lineHeight - renderer.$size.scrollerHeight);
- }
+ var renderer = editor.renderer;
+ var pos = renderer.$cursorLayer.getPixelPosition();
+
+ var top = pos.top;
+
+ var margin = HMARGIN * renderer.layerConfig.lineHeight;
+ if (2 * margin > renderer.$size.scrollerHeight)
+ margin = renderer.$size.scrollerHeight / 2;
+
+ if (renderer.scrollTop > top - margin) {
+ renderer.session.setScrollTop(top - margin);
+ }
+
+ if (renderer.scrollTop + renderer.$size.scrollerHeight < top + margin + renderer.lineHeight) {
+ renderer.session.setScrollTop(top + margin + renderer.lineHeight - renderer.$size.scrollerHeight);
+ }
};
-var actions = {
+var actions = exports.actions = {
"z": {
param: true,
fn: function(editor, range, count, param) {
- switch (param) {
+ switch (param) {
case "z":
editor.alignCursor(null, 0.5);
break;
case "t":
editor.alignCursor(null, 0);
break;
case "b":
- editor.alignCursor(null, 1);
+ editor.alignCursor(null, 1);
break;
}
}
@@ -111,37 +148,43 @@ var actions = {
}
}
},
+ "R": {
+ fn: function(editor, range, count, param) {
+ util.insertMode(editor);
+ editor.setOverwrite(true);
+ }
+ },
"~": {
fn: function(editor, range, count) {
repeat(function() {
var range = editor.selection.getRange();
- if (range.isEmpty())
- range.end.column++
- var text = editor.session.getTextRange(range)
- var toggled = text.toUpperCase()
- if (toggled == text)
- editor.navigateRight()
- else
- editor.session.replace(range, toggled);
+ if (range.isEmpty())
+ range.end.column++;
+ var text = editor.session.getTextRange(range);
+ var toggled = text.toUpperCase();
+ if (toggled == text)
+ editor.navigateRight();
+ else
+ editor.session.replace(range, toggled);
}, count || 1);
}
},
"*": {
fn: function(editor, range, count, param) {
editor.selection.selectWord();
editor.findNext();
- ensureScrollMargin(editor);
- var r = editor.selection.getRange();
- editor.selection.setSelectionRange(r, true);
+ ensureScrollMargin(editor);
+ var r = editor.selection.getRange();
+ editor.selection.setSelectionRange(r, true);
}
},
"#": {
fn: function(editor, range, count, param) {
editor.selection.selectWord();
editor.findPrevious();
- ensureScrollMargin(editor);
- var r = editor.selection.getRange();
- editor.selection.setSelectionRange(r, true);
+ ensureScrollMargin(editor);
+ var r = editor.selection.getRange();
+ editor.selection.setSelectionRange(r, true);
}
},
"n": {
@@ -150,14 +193,14 @@ var actions = {
options.backwards = false;
editor.selection.moveCursorRight();
- editor.selection.clearSelection();
+ editor.selection.clearSelection();
editor.findNext(options);
-
+
ensureScrollMargin(editor);
var r = editor.selection.getRange();
- r.end.row = r.start.row;
- r.end.column = r.start.column
- editor.selection.setSelectionRange(r, true);
+ r.end.row = r.start.row;
+ r.end.column = r.start.column;
+ editor.selection.setSelectionRange(r, true);
}
},
"N": {
@@ -168,17 +211,17 @@ var actions = {
editor.findPrevious(options);
ensureScrollMargin(editor);
var r = editor.selection.getRange();
- r.end.row = r.start.row;
- r.end.column = r.start.column
- editor.selection.setSelectionRange(r, true);
+ r.end.row = r.start.row;
+ r.end.column = r.start.column;
+ editor.selection.setSelectionRange(r, true);
}
},
"v": {
fn: function(editor, range, count, param) {
editor.selection.selectRight();
util.visualMode(editor, false);
},
- acceptsMotion: true
+ acceptsMotion: true
},
"V": {
fn: function(editor, range, count, param) {
@@ -189,10 +232,10 @@ var actions = {
editor.selection.moveCursorTo(row, 0);
editor.selection.selectLineEnd();
editor.selection.visualLineStart = row;
-
+
util.visualMode(editor, true);
},
- acceptsMotion: true
+ acceptsMotion: true
},
"Y": {
fn: function(editor, range, count, param) {
@@ -239,23 +282,23 @@ var actions = {
},
"J": {
fn: function(editor, range, count, param) {
- var session = editor.session
- range = editor.getSelectionRange();
+ var session = editor.session;
+ range = editor.getSelectionRange();
var pos = {row: range.start.row, column: range.start.column};
- count = count || range.end.row - range.start.row;
- var maxRow = Math.min(pos.row + (count || 1), session.getLength() - 1);
-
- range.start.column = session.getLine(pos.row).length;
- range.end.column = session.getLine(maxRow).length;
- range.end.row = maxRow;
-
- var text = ""
- for (var i = pos.row; i < maxRow; i++) {
- var nextLine = session.getLine(i + 1);
- text += " " + /^\s*(.*)$/.exec(nextLine)[1] || "";
- }
-
- session.replace(range, text);
+ count = count || range.end.row - range.start.row;
+ var maxRow = Math.min(pos.row + (count || 1), session.getLength() - 1);
+
+ range.start.column = session.getLine(pos.row).length;
+ range.end.column = session.getLine(maxRow).length;
+ range.end.row = maxRow;
+
+ var text = "";
+ for (var i = pos.row; i < maxRow; i++) {
+ var nextLine = session.getLine(i + 1);
+ text += " " + /^\s*(.*)$/.exec(nextLine)[1] || "";
+ }
+
+ session.replace(range, text);
editor.moveCursorTo(pos.row, pos.column);
}
},
@@ -279,16 +322,17 @@ var actions = {
},
":": {
fn: function(editor, range, count, param) {
- editor.blur();
- txtConsoleInput.focus();
- txtConsoleInput.setValue(":");
+ // not implemented
}
},
"/": {
fn: function(editor, range, count, param) {
- editor.blur();
- txtConsoleInput.focus();
- txtConsoleInput.setValue("/");
+ // not implemented
+ }
+ },
+ "?": {
+ fn: function(editor, range, count, param) {
+ // not implemented
}
},
".": {
@@ -370,9 +414,9 @@ var inputBuffer = exports.inputBuffer = {
else {
this.exec(editor, actionObj);
}
-
- if (actions[char].acceptsMotion)
- this.idle = false;
+
+ if (actions[char].acceptsMotion)
+ this.idle = false;
}
else if (this.operator) {
this.exec(editor, { operator: this.operator }, char);
@@ -396,9 +440,9 @@ var inputBuffer = exports.inputBuffer = {
var m = action.motion;
var o = action.operator;
var a = action.action;
-
- if (!param)
- param = action.param;
+
+ if (!param)
+ param = action.param;
if (o) {
this.previous = {
@@ -541,11 +585,11 @@ var handleCursorMove = exports.onCursorMove = function(editor, e) {
return;
}
else {
- if (e && (util.onVisualLineMode || util.onVisualMode)) {
- editor.selection.clearSelection();
- util.normalMode(editor)
- }
-
+ if (e && (util.onVisualLineMode || util.onVisualMode)) {
+ editor.selection.clearSelection();
+ util.normalMode(editor);
+ }
+
handleCursorMove.running = true;
var pos = editor.getCursorPosition();
var lineLen = editor.session.getLine(pos.row).length;
@@ -562,50 +606,51 @@ var registers = require("ace/keyboard/vim/registers");
var dom = require("ace/lib/dom");
dom.importCssString('.insert-mode. ace_cursor{\
- border-left: 2px solid #333333;\
+ border-left: 2px solid #333333;\
}\
.ace_dark.insert-mode .ace_cursor{\
- border-left: 2px solid #eeeeee;\
+ border-left: 2px solid #eeeeee;\
}\
.normal-mode .ace_cursor{\
- border: 0!important;\
- background-color: red;\
+ border: 0!important;\
+ background-color: red;\
opacity: 0.5;\
-}', 'vimMode')
+}', 'vimMode');
module.exports = {
onVisualMode: false,
onVisualLineMode: false,
currentMode: 'normal',
- noMode: function(editor) {
- editor.unsetStyle('insert-mode');
- editor.unsetStyle('normal-mode');
- if (editor.commands.recording)
+ noMode: function(editor) {
+ editor.unsetStyle('insert-mode');
+ editor.unsetStyle('normal-mode');
+ if (editor.commands.recording)
editor.commands.toggleRecording();
- },
+ editor.setOverwrite(false);
+ },
insertMode: function(editor) {
- this.currentMode = 'insert';
- // Switch editor to insert mode
- editor.setStyle('insert-mode');
- editor.unsetStyle('normal-mode');
-
-
- editor.setOverwrite(false);
- editor.keyBinding.$data.buffer = "";
- editor.keyBinding.$data.state = "insertMode";
- this.onVisualMode = false;
- this.onVisualLineMode = false;
- if(this.onInsertReplaySequence) {
- // Ok, we're apparently replaying ("."), so let's do it
- editor.commands.macro = this.onInsertReplaySequence;
- editor.commands.replay(editor);
- this.onInsertReplaySequence = null;
- this.normalMode(editor);
- } else {
- // Record any movements, insertions in insert mode
- if(!editor.commands.recording)
- editor.commands.toggleRecording();
- }
+ this.currentMode = 'insert';
+ // Switch editor to insert mode
+ editor.setStyle('insert-mode');
+ editor.unsetStyle('normal-mode');
+
+ editor.setOverwrite(false);
+ editor.keyBinding.$data.buffer = "";
+ editor.keyBinding.$data.state = "insertMode";
+ this.onVisualMode = false;
+ this.onVisualLineMode = false;
+ if(this.onInsertReplaySequence) {
+ // Ok, we're apparently replaying ("."), so let's do it
+ editor.commands.macro = this.onInsertReplaySequence;
+ editor.commands.replay(editor);
+ this.onInsertReplaySequence = null;
+ this.normalMode(editor);
+ } else {
+ editor._emit("vimMode", "insert");
+ // Record any movements, insertions in insert mode
+ if(!editor.commands.recording)
+ editor.commands.toggleRecording();
+ }
},
normalMode: function(editor) {
// Switch editor to normal mode
@@ -621,10 +666,13 @@ module.exports = {
if (pos.column > 0)
editor.navigateLeft();
}
+
+ editor.setOverwrite(true);
editor.keyBinding.$data.buffer = "";
editor.keyBinding.$data.state = "start";
this.onVisualMode = false;
this.onVisualLineMode = false;
+ editor._emit("changeVimMode", "normal");
// Save recorded keystrokes
if (editor.commands.recording) {
editor.commands.toggleRecording();
@@ -634,25 +682,26 @@ module.exports = {
return [];
}
},
- visualMode: function(editor, lineMode) {
- if (
- (this.onVisualLineMode && lineMode)
- || (this.onVisualMode && !lineMode)
- ) {
- this.normalMode(editor);
- return;
- }
-
- editor.setStyle('insert-mode');
+ visualMode: function(editor, lineMode) {
+ if (
+ (this.onVisualLineMode && lineMode)
+ || (this.onVisualMode && !lineMode)
+ ) {
+ this.normalMode(editor);
+ return;
+ }
+
+ editor.setStyle('insert-mode');
editor.unsetStyle('normal-mode');
-
- if (lineMode) {
- this.onVisualLineMode = true;
- } else {
- this.onVisualMode = true;
- this.onVisualLineMode = false;
- }
- },
+
+ editor._emit("changeVimMode", "visual");
+ if (lineMode) {
+ this.onVisualLineMode = true;
+ } else {
+ this.onVisualMode = true;
+ this.onVisualLineMode = false;
+ }
+ },
getRightNthChar: function(editor, cursor, char, n) {
var line = editor.getSession().getLine(cursor.row);
var matches = line.substr(cursor.column + 1).split(char);
@@ -687,69 +736,7 @@ module.exports = {
};
});
-define("ace/keyboard/vim/keyboard",[], function(require, exports, module) {
-
-
-var keyUtil = require("ace/lib/keys");
-var cmds = require("ace/keyboard/vim/commands");
-var coreCommands = cmds.coreCommands;
-
-
-var startCommands = {
- 'i': {
- command: coreCommands.start
- },
- 'I': {
- command: coreCommands.startBeginning,
- },
- 'a': {
- command: coreCommands.append
- },
- 'A': {
- command: coreCommands.appendEnd
- }
-};
-
-exports.handler = {
- handleKeyboard: function(data, hashId, key, keyCode, e) {
- // ignore command keys (shift, ctrl etc.)
- // Otherwise "shift-" is added to the buffer, and later on "shift-g"
- // which results in "shift-shift-g" which doesn't make sense.
- if (hashId != 0 && (key == "" || key == String.fromCharCode(0)))
- return null;
-
- if (hashId == 1)
- key = 'ctrl-' + key;
-
- if (data.state == 'start') {
- if (hashId == -1 || hashId == 1) {
- if (cmds.inputBuffer.idle && startCommands[key])
- return startCommands[key];
-
- return {exec: function(editor) {
- cmds.inputBuffer.push(editor, key);
- }
- }
- } // wait for input
- else if (key.length === 1 && (hashId == 0 || hashId === 4)) { //no modifier || shift
- return {isSuccessCode: true, stopEvent: false}
- } else if (key == 'esc') {
- return {command: coreCommands.stop}
- }
- } else {
- if (key == 'esc' || key == 'ctrl-[') {
- data.state = 'start'
- return {command: coreCommands.stop}
- }
- }
- }
-}
-
-
-
-});
-
-"never use strict"
+"use strict"
define("ace/keyboard/vim/maps/motions",[], function(require, exports, module) {
@@ -762,263 +749,199 @@ var keepScrollPosition = function(editor, fn) {
fn && fn.call(editor);
editor.renderer.scrollToRow(editor.getCursorPosition().row - diff);
};
+
function Motion(getRange, type){
- if (type == 'extend')
- var extend = true
- else
- var reverse = type
-
- this.nav = function(editor) {
- var r = getRange(editor);
- if (!r)
- return
- if (!r.end)
- var a = r
- else if (reverse)
- var a = r.start
- else
- var a = r.end
-
- editor.clearSelection()
- editor.moveCursorTo(a.row, a.column);
- }
- this.sel = function(editor){
- var r = getRange(editor);
- if (!r)
- return
- if (extend)
- return editor.selection.setSelectionRange(r);
-
- if (!r.end)
- var a = r
- else if (reverse)
- var a = r.start
- else
- var a = r.end
-
- editor.selection.selectTo(a.row, a.column);
- }
+ if (type == 'extend')
+ var extend = true;
+ else
+ var reverse = type;
+
+ this.nav = function(editor) {
+ var r = getRange(editor);
+ if (!r)
+ return;
+ if (!r.end)
+ var a = r;
+ else if (reverse)
+ var a = r.start;
+ else
+ var a = r.end;
+
+ editor.clearSelection();
+ editor.moveCursorTo(a.row, a.column);
+ }
+ this.sel = function(editor){
+ var r = getRange(editor);
+ if (!r)
+ return;
+ if (extend)
+ return editor.selection.setSelectionRange(r);
+
+ if (!r.end)
+ var a = r;
+ else if (reverse)
+ var a = r.start;
+ else
+ var a = r.end;
+
+ editor.selection.selectTo(a.row, a.column);
+ }
}
-var nonWordRe = /[\s.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/
-var wordSeparatorRe = /[.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/
-var whiteRe = /\s/
+var nonWordRe = /[\s.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/;
+var wordSeparatorRe = /[.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/;
+var whiteRe = /\s/;
var StringStream = function(editor, cursor) {
- var sel = editor.selection
- this.range = sel.getRange()
- cursor = cursor || sel.selectionLead
- this.row = cursor.row;
- this.col = cursor.column;
- var line = editor.session.getLine(this.row);
- var maxRow = editor.session.getLength()
- this.ch = line[this.col] || '\n'
- this.skippedLines = 0
-
- this.next = function() {
- this.ch = line[++this.col] || this.handleNewLine(1)
+ var sel = editor.selection;
+ this.range = sel.getRange();
+ cursor = cursor || sel.selectionLead;
+ this.row = cursor.row;
+ this.col = cursor.column;
+ var line = editor.session.getLine(this.row);
+ var maxRow = editor.session.getLength()
+ this.ch = line[this.col] || '\n'
+ this.skippedLines = 0;
+
+ this.next = function() {
+ this.ch = line[++this.col] || this.handleNewLine(1);
//this.debug()
- return this.ch
- }
- this.prev = function() {
- this.ch = line[--this.col] || this.handleNewLine(-1)
+ return this.ch;
+ }
+ this.prev = function() {
+ this.ch = line[--this.col] || this.handleNewLine(-1);
//this.debug()
- return this.ch
- }
+ return this.ch;
+ }
this.peek = function(dir) {
- var ch = line[this.col + dir]
- if (ch)
- return ch
- if (dir == -1)
- return '\n'
- if (this.col == line.length - 1)
- return '\n'
- return editor.session.getLine(this.row + 1)[0] || '\n'
- }
-
- this.handleNewLine = function(dir) {
- if (dir == 1){
- if (this.col == line.length)
- return '\n'
- if (this.row == maxRow - 1)
- return ''
- this.col = 0
- this.row ++
- line = editor.session.getLine(this.row)
- this.skippedLines++
- return line[0] || '\n'
- }
- if (dir == -1) {
- if (this.row == 0)
- return ''
- this.row --
- line = editor.session.getLine(this.row)
- this.col = line.length;
- this.skippedLines--
- return '\n'
- }
- }
- this.debug = function() {
- console.log(line.substring(0, this.col)+'|'+this.ch+'\''+this.col+'\''+line.substr(this.col+1))
- }
+ var ch = line[this.col + dir];
+ if (ch)
+ return ch;
+ if (dir == -1)
+ return '\n';
+ if (this.col == line.length - 1)
+ return '\n';
+ return editor.session.getLine(this.row + 1)[0] || '\n';
+ }
+
+ this.handleNewLine = function(dir) {
+ if (dir == 1){
+ if (this.col == line.length)
+ return '\n';
+ if (this.row == maxRow - 1)
+ return '';
+ this.col = 0;
+ this.row ++;
+ line = editor.session.getLine(this.row);
+ this.skippedLines++;
+ return line[0] || '\n';
+ }
+ if (dir == -1) {
+ if (this.row == 0)
+ return '';
+ this.row --;
+ line = editor.session.getLine(this.row);
+ this.col = line.length;
+ this.skippedLines--;
+ return '\n';
+ }
+ }
+ this.debug = function() {
+ console.log(line.substring(0, this.col)+'|'+this.ch+'\''+this.col+'\''+line.substr(this.col+1));
+ }
}
-var Search = require("ace/search").Search
-var search = new Search
+var Search = require("ace/search").Search;
+var search = new Search();
function find(editor, needle, dir) {
- search.$options.needle = needle
- search.$options.backwards = dir == -1
- return search.find(editor.session)
+ search.$options.needle = needle;
+ search.$options.backwards = dir == -1;
+ return search.find(editor.session);
}
-var lang = require("ace/lib/lang");
-var Range = require("ace/range").Range;
-
- var moveCursorWordRight = function(editor) {
- var sel = editor.selection
- var range = sel.getRange()
- var row = sel.selectionLead.row;
- var col = sel.selectionLead.column;
- var line = editor.session.getLine(row);
- var ch = line[col]
-
- var fold;
- if (fold = this.session.getFoldAt(row, column, 1)) {
- this.moveCursorTo(fold.end.row, fold.end.column);
- return;
- } else if (column == line.length) {
- this.moveCursorRight();
- return;
- }
- else if (match = this.session.nonTokenRe.exec(rightOfCursor)) {
- column += this.session.nonTokenRe.lastIndex;
- this.session.nonTokenRe.lastIndex = 0;
- }
- else if (match = this.session.tokenRe.exec(rightOfCursor)) {
- column += this.session.tokenRe.lastIndex;
- this.session.tokenRe.lastIndex = 0;
- }
-
- };
-
- this.moveCursorWordLeft = function() {
- var row = this.selectionLead.row;
- var column = this.selectionLead.column;
-
- var fold;
- if (fold = this.session.getFoldAt(row, column, -1)) {
- this.moveCursorTo(fold.start.row, fold.start.column);
- return;
- }
-
- if (column == 0) {
- this.moveCursorLeft();
- return;
- }
-
- var str = this.session.getFoldStringAt(row, column, -1);
- if (str == null) {
- str = this.doc.getLine(row).substring(0, column)
- }
- var leftOfCursor = lang.stringReverse(str);
-
- var match;
- this.session.nonTokenRe.lastIndex = 0;
- this.session.tokenRe.lastIndex = 0;
-
- if (match = this.session.nonTokenRe.exec(leftOfCursor)) {
- column -= this.session.nonTokenRe.lastIndex;
- this.session.nonTokenRe.lastIndex = 0;
- }
- else if (match = this.session.tokenRe.exec(leftOfCursor)) {
- column -= this.session.tokenRe.lastIndex;
- this.session.tokenRe.lastIndex = 0;
- }
-
- this.moveCursorTo(row, column);
- };
+var Range = require("ace/range").Range;
module.exports = {
"w": new Motion(function(editor) {
- var str = new StringStream(editor)
-
- if (str.ch && wordSeparatorRe.test(str.ch)) {
- while (str.ch && wordSeparatorRe.test(str.ch))
- str.next()
- } else {
- while (str.ch && !nonWordRe.test(str.ch))
- str.next()
- }
- while (str.ch && whiteRe.test(str.ch) && str.skippedLines < 2)
- str.next()
-
- str.skippedLines == 2 && str.prev()
- return {column: str.col, row: str.row}
- }),
- "W": new Motion(function(editor) {
- var str = new StringStream(editor)
- while(str.ch && !(whiteRe.test(str.ch) && !whiteRe.test(str.peek(1))) && str.skippedLines < 2)
- str.next()
- if (str.skippedLines == 2)
- str.prev()
- else
- str.next()
-
- return {column: str.col, row: str.row}
- }),
+ var str = new StringStream(editor);
+
+ if (str.ch && wordSeparatorRe.test(str.ch)) {
+ while (str.ch && wordSeparatorRe.test(str.ch))
+ str.next();
+ } else {
+ while (str.ch && !nonWordRe.test(str.ch))
+ str.next();
+ }
+ while (str.ch && whiteRe.test(str.ch) && str.skippedLines < 2)
+ str.next();
+
+ str.skippedLines == 2 && str.prev();
+ return {column: str.col, row: str.row};
+ }),
+ "W": new Motion(function(editor) {
+ var str = new StringStream(editor);
+ while(str.ch && !(whiteRe.test(str.ch) && !whiteRe.test(str.peek(1))) && str.skippedLines < 2)
+ str.next();
+ if (str.skippedLines == 2)
+ str.prev();
+ else
+ str.next();
+
+ return {column: str.col, row: str.row}
+ }),
"b": new Motion(function(editor) {
- var str = new StringStream(editor)
-
- str.prev()
- while (str.ch && whiteRe.test(str.ch) && str.skippedLines > -2)
- str.prev()
-
- if (str.ch && wordSeparatorRe.test(str.ch)) {
- while (str.ch && wordSeparatorRe.test(str.ch))
- str.prev()
- } else {
- while (str.ch && !nonWordRe.test(str.ch))
- str.prev()
- }
- str.ch && str.next();
- return {column: str.col, row: str.row}
- }),
- "B": new Motion(function(editor) {
- var str = new StringStream(editor)
- str.prev()
- while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(-1))) && str.skippedLines > -2)
- str.prev()
-
- if (str.skippedLines == -2)
- str.next()
-
- return {column: str.col, row: str.row}
- }, true),
+ var str = new StringStream(editor);
+
+ str.prev();
+ while (str.ch && whiteRe.test(str.ch) && str.skippedLines > -2)
+ str.prev();
+
+ if (str.ch && wordSeparatorRe.test(str.ch)) {
+ while (str.ch && wordSeparatorRe.test(str.ch))
+ str.prev();
+ } else {
+ while (str.ch && !nonWordRe.test(str.ch))
+ str.prev();
+ }
+ str.ch && str.next();
+ return {column: str.col, row: str.row};
+ }),
+ "B": new Motion(function(editor) {
+ var str = new StringStream(editor)
+ str.prev();
+ while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(-1))) && str.skippedLines > -2)
+ str.prev();
+
+ if (str.skippedLines == -2)
+ str.next();
+
+ return {column: str.col, row: str.row};
+ }, true),
"e": new Motion(function(editor) {
- var str = new StringStream(editor)
-
- str.next()
- while (str.ch && whiteRe.test(str.ch))
- str.next()
-
- if (str.ch && wordSeparatorRe.test(str.ch)) {
- while (str.ch && wordSeparatorRe.test(str.ch))
- str.next()
- } else {
- while (str.ch && !nonWordRe.test(str.ch))
- str.next()
- }
- str.ch && str.prev()
- return {column: str.col, row: str.row}
- }),
- "E": new Motion(function(editor) {
- var str = new StringStream(editor)
- str.next()
- while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(1))))
- str.next()
-
- return {column: str.col, row: str.row}
- }),
+ var str = new StringStream(editor);
+
+ str.next();
+ while (str.ch && whiteRe.test(str.ch))
+ str.next();
+
+ if (str.ch && wordSeparatorRe.test(str.ch)) {
+ while (str.ch && wordSeparatorRe.test(str.ch))
+ str.next();
+ } else {
+ while (str.ch && !nonWordRe.test(str.ch))
+ str.next();
+ }
+ str.ch && str.prev();
+ return {column: str.col, row: str.row};
+ }),
+ "E": new Motion(function(editor) {
+ var str = new StringStream(editor);
+ str.next();
+ while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(1))))
+ str.next();
+
+ return {column: str.col, row: str.row};
+ }),
"l": {
nav: function(editor) {
@@ -1069,35 +992,35 @@ module.exports = {
sel: function(editor, range, count, param) {
switch (param) {
case "w":
- editor.selection.selectWord();
- break;
- case "W":
+ editor.selection.selectWord();
+ break;
+ case "W":
editor.selection.selectAWord();
- break;
- case "(":
- case "{":
- case "[":
- var cursor = editor.getCursorPosition()
- var end = editor.session.$findClosingBracket(param, cursor, /paren/)
- if (!end)
- return
- var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/)
- if (!start)
- return
- start.column ++;
- editor.selection.setSelectionRange(Range.fromPoints(start, end))
- break
- case "'":
- case "\"":
- case "/":
- var end = find(editor, param, 1)
- if (!end)
- return
- var start = find(editor, param, -1)
- if (!start)
- return
- editor.selection.setSelectionRange(Range.fromPoints(start.end, end.start))
- break
+ break;
+ case "(":
+ case "{":
+ case "[":
+ var cursor = editor.getCursorPosition();
+ var end = editor.session.$findClosingBracket(param, cursor, /paren/);
+ if (!end)
+ return;
+ var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/);
+ if (!start)
+ return;
+ start.column ++;
+ editor.selection.setSelectionRange(Range.fromPoints(start, end));
+ break;
+ case "'":
+ case '"':
+ case "/":
+ var end = find(editor, param, 1);
+ if (!end)
+ return;
+ var start = find(editor, param, -1);
+ if (!start)
+ return;
+ editor.selection.setSelectionRange(Range.fromPoints(start.end, end.start));
+ break;
}
}
},
@@ -1106,43 +1029,43 @@ module.exports = {
sel: function(editor, range, count, param) {
switch (param) {
case "w":
- editor.selection.selectAWord();
- break;
- case "W":
editor.selection.selectAWord();
- break;
- case "(":
- case "{":
- case "[":
- var cursor = editor.getCursorPosition()
- var end = editor.session.$findClosingBracket(param, cursor, /paren/)
- if (!end)
- return
- var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/)
- if (!start)
- return
- end.column ++;
- editor.selection.setSelectionRange(Range.fromPoints(start, end))
- break
- case "'":
- case "\"":
- case "/":
- var end = find(editor, param, 1)
- if (!end)
- return
- var start = find(editor, param, -1)
- if (!start)
- return
- end.column ++;
- editor.selection.setSelectionRange(Range.fromPoints(start.start, end.end))
- break
+ break;
+ case "W":
+ editor.selection.selectAWord();
+ break;
+ case "(":
+ case "{":
+ case "[":
+ var cursor = editor.getCursorPosition();
+ var end = editor.session.$findClosingBracket(param, cursor, /paren/);
+ if (!end)
+ return;
+ var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/);
+ if (!start)
+ return;
+ end.column ++;
+ editor.selection.setSelectionRange(Range.fromPoints(start, end));
+ break;
+ case "'":
+ case "\"":
+ case "/":
+ var end = find(editor, param, 1);
+ if (!end)
+ return;
+ var start = find(editor, param, -1);
+ if (!start)
+ return;
+ end.column ++;
+ editor.selection.setSelectionRange(Range.fromPoints(start.start, end.end));
+ break;
}
}
},
"f": {
param: true,
- handlesCount: true,
+ handlesCount: true,
nav: function(editor, range, count, param) {
var ed = editor;
var cursor = ed.getCursorPosition();
@@ -1165,7 +1088,7 @@ module.exports = {
},
"F": {
param: true,
- handlesCount: true,
+ handlesCount: true,
nav: function(editor, range, count, param) {
count = parseInt(count, 10) || 1;
var ed = editor;
@@ -1189,7 +1112,7 @@ module.exports = {
},
"t": {
param: true,
- handlesCount: true,
+ handlesCount: true,
nav: function(editor, range, count, param) {
var ed = editor;
var cursor = ed.getCursorPosition();
@@ -1212,7 +1135,7 @@ module.exports = {
},
"T": {
param: true,
- handlesCount: true,
+ handlesCount: true,
nav: function(editor, range, count, param) {
var ed = editor;
var cursor = ed.getCursorPosition();
@@ -1286,9 +1209,9 @@ module.exports = {
break;
case "g":
editor.gotoLine(count || 0);
- case "u":
+ case "u":
editor.gotoLine(count || 0);
- case "U":
+ case "U":
editor.gotoLine(count || 0);
}
},
@@ -1341,23 +1264,23 @@ module.exports = {
}
},
"%": new Motion(function(editor){
- var brRe = /[\[\]{}()]/g;
- var cursor = editor.getCursorPosition();
- var ch = editor.session.getLine(cursor.row)[cursor.column]
- if (!brRe.test(ch)){
- var range = find(editor, brRe)
- if (!range)
- return
- cursor = range.start
- }
- var match = editor.session.findMatchingBracket({
- row: cursor.row,
- column: cursor.column + 1
- });
-
- return match
- }),
- "ctrl-d": {
+ var brRe = /[\[\]{}()]/g;
+ var cursor = editor.getCursorPosition();
+ var ch = editor.session.getLine(cursor.row)[cursor.column];
+ if (!brRe.test(ch)) {
+ var range = find(editor, brRe);
+ if (!range)
+ return;
+ cursor = range.start;
+ }
+ var match = editor.session.findMatchingBracket({
+ row: cursor.row,
+ column: cursor.column + 1
+ });
+
+ return match;
+ }),
+ "ctrl-d": {
nav: function(editor, range, count, param) {
editor.selection.clearSelection();
keepScrollPosition(editor, editor.gotoPageDown);
@@ -1396,66 +1319,75 @@ var registers = require("ace/keyboard/vim/registers");
module.exports = {
"d": {
- selFn: function(editor, range, count, param) {
- registers._default.text = editor.getCopyText();
- registers._default.isLine = util.onVisualLineMode;
- if(util.onVisualLineMode)
- editor.removeLines();
- else
- editor.session.remove(range);
- util.normalMode(editor);
- },
- fn: function(editor, range, count, param) {
+ selFn: function(editor, range, count, param) {
+ registers._default.text = editor.getCopyText();
+ registers._default.isLine = util.onVisualLineMode;
+ if(util.onVisualLineMode)
+ editor.removeLines();
+ else
+ editor.session.remove(range);
+ util.normalMode(editor);
+ },
+ fn: function(editor, range, count, param) {
count = count || 1;
- switch (param) {
- case "d":
- registers._default.text = "";
- registers._default.isLine = true;
- for (var i = 0; i < count; i++) {
- editor.selection.selectLine();
- registers._default.text += editor.getCopyText();
- var selRange = editor.getSelectionRange();
- editor.session.remove(selRange);
- editor.selection.clearSelection();
- }
- registers._default.text = registers._default.text.replace(/\n$/, "");
- break;
- default:
- if (range) {
- editor.selection.setSelectionRange(range);
- registers._default.text = editor.getCopyText();
- registers._default.isLine = false;
- editor.session.remove(range);
- editor.selection.clearSelection();
- }
- }
- }
+ switch (param) {
+ case "d":
+ registers._default.text = "";
+ registers._default.isLine = true;
+ for (var i = 0; i < count; i++) {
+ editor.selection.selectLine();
+ registers._default.text += editor.getCopyText();
+ var selRange = editor.getSelectionRange();
+ // check if end of the document was reached
+ if (!selRange.isMultiLine()) {
+ lastLineReached = true
+ var row = selRange.start.row - 1;
+ var col = editor.session.getLine(row).length
+ selRange.setStart(row, col);
+ editor.session.remove(selRange);
+ editor.selection.clearSelection();
+ break;
+ }
+ editor.session.remove(selRange);
+ editor.selection.clearSelection();
+ }
+ registers._default.text = registers._default.text.replace(/\n$/, "");
+ break;
+ default:
+ if (range) {
+ editor.selection.setSelectionRange(range);
+ registers._default.text = editor.getCopyText();
+ registers._default.isLine = false;
+ editor.session.remove(range);
+ editor.selection.clearSelection();
+ }
+ }
+ }
},
"c": {
- selFn: function(editor, range, count, param) {
- editor.session.remove(range);
- util.insertMode(editor);
- },
- fn: function(editor, range, count, param) {
+ selFn: function(editor, range, count, param) {
+ editor.session.remove(range);
+ util.insertMode(editor);
+ },
+ fn: function(editor, range, count, param) {
count = count || 1;
- switch (param) {
- case "c":
- for (var i = 0; i < count; i++) {
- editor.removeLines();
- util.insertMode(editor);
- }
-
- break;
- default:
- console.log(param)
- if (range) {
-
- // range.end.column ++;
- editor.session.remove(range);
- util.insertMode(editor);
- }
- }
- }
+ switch (param) {
+ case "c":
+ for (var i = 0; i < count; i++) {
+ editor.removeLines();
+ util.insertMode(editor);
+ }
+
+ break;
+ default:
+ if (range) {
+
+ // range.end.column ++;
+ editor.session.remove(range);
+ util.insertMode(editor);
+ }
+ }
+ }
},
"y": {
selFn: function(editor, range, count, param) {
@@ -1545,7 +1477,7 @@ module.exports = {
};
});
-"never use strict"
+"use strict"
define("ace/keyboard/vim/maps/aliases",[], function(require, exports, module) {
module.exports = {
@@ -1611,6 +1543,8 @@ module.exports = {
define("ace/keyboard/vim/registers",[], function(require, exports, module) {
+"never use strict";
+
module.exports = {