commit
f9d580d106
10 changed files with 132 additions and 43 deletions
|
|
@ -47,6 +47,8 @@ var env = {};
|
||||||
|
|
||||||
var dom = require("ace/lib/dom");
|
var dom = require("ace/lib/dom");
|
||||||
var net = require("ace/lib/net");
|
var net = require("ace/lib/net");
|
||||||
|
var lang = require("ace/lib/lang");
|
||||||
|
var useragent = require("ace/lib/useragent");
|
||||||
|
|
||||||
var event = require("ace/lib/event");
|
var event = require("ace/lib/event");
|
||||||
var theme = require("ace/theme/textmate");
|
var theme = require("ace/theme/textmate");
|
||||||
|
|
@ -739,10 +741,41 @@ function singleLineEditor(el) {
|
||||||
editor.setHighlightActiveLine(false);
|
editor.setHighlightActiveLine(false);
|
||||||
editor.setShowPrintMargin(false);
|
editor.setShowPrintMargin(false);
|
||||||
editor.renderer.setShowGutter(false);
|
editor.renderer.setShowGutter(false);
|
||||||
// editor.renderer.setHighlightGutterLine(false);
|
editor.renderer.setHighlightGutterLine(false);
|
||||||
return editor;
|
return editor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/** simple statusbar **/
|
||||||
|
var editor = env.editor;
|
||||||
|
var statusBarEl = dom.createElement("div");
|
||||||
|
statusBarEl.style.cssText = "color:gray;position:absolute;right:0;border-left:1px solid";
|
||||||
|
cmdLine.container.appendChild(statusBarEl);
|
||||||
|
var statusUpdate = lang.deferredCall(function() {
|
||||||
|
var status = [];
|
||||||
|
function add(s, sep) {s && status.push(s, sep || "|")}
|
||||||
|
if (editor.$vimModeHandler)
|
||||||
|
add(editor.$vimModeHandler.getStatusText());
|
||||||
|
else if (editor.commands.recording)
|
||||||
|
add("REC");
|
||||||
|
|
||||||
|
var c = editor.selection.lead;
|
||||||
|
add(c.row + ":" + c.column, " ");
|
||||||
|
if (!editor.selection.isEmpty()) {
|
||||||
|
var r = editor.getSelectionRange()
|
||||||
|
add("(" + (r.end.row - r.start.row) + ":" +(r.end.column - r.start.column) + ")");
|
||||||
|
}
|
||||||
|
status.pop();
|
||||||
|
statusBarEl.textContent = status.join("");
|
||||||
|
});
|
||||||
|
|
||||||
|
env.editor.on("changeStatus", function() {
|
||||||
|
statusUpdate.schedule(50);
|
||||||
|
});
|
||||||
|
env.editor.on("changeSelection", function() {
|
||||||
|
statusUpdate.schedule(50);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,11 @@ oop.inherits(CommandManager, HashHandler);
|
||||||
return retvalue === false ? false : true;
|
return retvalue === false ? false : true;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.toggleRecording = function() {
|
this.toggleRecording = function(editor) {
|
||||||
if (this.$inReplay)
|
if (this.$inReplay)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
editor && editor._emit("changeStatus");
|
||||||
if (this.recording) {
|
if (this.recording) {
|
||||||
this.macro.pop();
|
this.macro.pop();
|
||||||
this.removeEventListener("exec", this.$addCommandToMacro);
|
this.removeEventListener("exec", this.$addCommandToMacro);
|
||||||
|
|
@ -74,8 +76,8 @@ oop.inherits(CommandManager, HashHandler);
|
||||||
}
|
}
|
||||||
if (!this.$addCommandToMacro) {
|
if (!this.$addCommandToMacro) {
|
||||||
this.$addCommandToMacro = function(e) {
|
this.$addCommandToMacro = function(e) {
|
||||||
this.macro.push([e.command, e.args]);
|
this.macro.push([e.command, e.args]);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.oldMacro = this.macro;
|
this.oldMacro = this.macro;
|
||||||
|
|
@ -89,7 +91,7 @@ oop.inherits(CommandManager, HashHandler);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.recording)
|
if (this.recording)
|
||||||
return this.toggleRecording();
|
return this.toggleRecording(editor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.$inReplay = true;
|
this.$inReplay = true;
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ module.exports = {
|
||||||
var called = "";
|
var called = "";
|
||||||
this.cm.addCommands({
|
this.cm.addCommands({
|
||||||
togglerecording: function(editor) {
|
togglerecording: function(editor) {
|
||||||
editor.cm.toggleRecording();
|
editor.cm.toggleRecording(editor);
|
||||||
},
|
},
|
||||||
replay: function(editor) {
|
replay: function(editor) {
|
||||||
editor.cm.replay();
|
editor.cm.replay();
|
||||||
|
|
@ -141,8 +141,13 @@ module.exports = {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var statusUpdateEmitted = false;
|
||||||
|
this._emit = function() {statusUpdateEmitted = true};
|
||||||
|
|
||||||
this.cm.exec("togglerecording", this);
|
this.cm.exec("togglerecording", this);
|
||||||
assert.ok(this.cm.recording);
|
assert.ok(this.cm.recording);
|
||||||
|
assert.ok(statusUpdateEmitted);
|
||||||
|
|
||||||
this.cm.exec("cm1", this, "-");
|
this.cm.exec("cm1", this, "-");
|
||||||
this.cm.exec("cm2");
|
this.cm.exec("cm2");
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,7 @@ exports.commands = [{
|
||||||
}, {
|
}, {
|
||||||
name: "togglerecording",
|
name: "togglerecording",
|
||||||
bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
|
bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
|
||||||
exec: function(editor) { editor.commands.toggleRecording(); },
|
exec: function(editor) { editor.commands.toggleRecording(editor); },
|
||||||
readOnly: true
|
readOnly: true
|
||||||
}, {
|
}, {
|
||||||
name: "replaymacro",
|
name: "replaymacro",
|
||||||
|
|
|
||||||
|
|
@ -475,6 +475,7 @@ var Editor = function(renderer, session) {
|
||||||
|
|
||||||
this.$highlightBrackets();
|
this.$highlightBrackets();
|
||||||
this.$updateHighlightActiveLine();
|
this.$updateHighlightActiveLine();
|
||||||
|
this._emit("changeSelection");
|
||||||
};
|
};
|
||||||
|
|
||||||
/** internal, hide
|
/** internal, hide
|
||||||
|
|
@ -531,6 +532,8 @@ var Editor = function(renderer, session) {
|
||||||
|
|
||||||
var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp()
|
var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp()
|
||||||
this.session.highlight(re);
|
this.session.highlight(re);
|
||||||
|
|
||||||
|
this._emit("changeSelection");
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$getSelectionHighLightRegexp = function() {
|
this.$getSelectionHighLightRegexp = function() {
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,10 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var keyUtil = require("../lib/keys");
|
|
||||||
var cmds = require("./vim/commands");
|
var cmds = require("./vim/commands");
|
||||||
var coreCommands = cmds.coreCommands;
|
var coreCommands = cmds.coreCommands;
|
||||||
var util = require("./vim/maps/util");
|
var util = require("./vim/maps/util");
|
||||||
|
var useragent = require("../lib/useragent");
|
||||||
|
|
||||||
var startCommands = {
|
var startCommands = {
|
||||||
"i": {
|
"i": {
|
||||||
|
|
@ -66,6 +66,28 @@ var startCommands = {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.handler = {
|
exports.handler = {
|
||||||
|
// workaround for j not repeating with `defaults write -g ApplePressAndHoldEnabled -bool true`
|
||||||
|
handleMacRepeat: function(data, hashId, key) {
|
||||||
|
if (hashId == -1) {
|
||||||
|
// record key
|
||||||
|
data.inputChar = key;
|
||||||
|
data.lastEvent = "input";
|
||||||
|
} else if (data.inputChar && data.$lastHash == hashId && data.$lastKey == key) {
|
||||||
|
// check for repeated keypress
|
||||||
|
if (data.lastEvent == "input") {
|
||||||
|
data.lastEvent = "input1";
|
||||||
|
} else if (data.lastEvent == "input1") {
|
||||||
|
// simulate textinput
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// reset
|
||||||
|
data.$lastHash = hashId;
|
||||||
|
data.$lastKey = key;
|
||||||
|
data.lastEvent = "keypress";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
handleKeyboard: function(data, hashId, key, keyCode, e) {
|
handleKeyboard: function(data, hashId, key, keyCode, e) {
|
||||||
// ignore command keys (shift, ctrl etc.)
|
// ignore command keys (shift, ctrl etc.)
|
||||||
if (hashId != 0 && (key == "" || key == "\x00"))
|
if (hashId != 0 && (key == "" || key == "\x00"))
|
||||||
|
|
@ -75,17 +97,23 @@ exports.handler = {
|
||||||
key = "ctrl-" + key;
|
key = "ctrl-" + key;
|
||||||
|
|
||||||
if (data.state == "start") {
|
if (data.state == "start") {
|
||||||
|
if (useragent.isMac && this.handleMacRepeat(data, hashId, key)) {
|
||||||
|
hashId = -1;
|
||||||
|
key = data.inputChar;
|
||||||
|
}
|
||||||
|
|
||||||
if (hashId == -1 || hashId == 1) {
|
if (hashId == -1 || hashId == 1) {
|
||||||
if (cmds.inputBuffer.idle && startCommands[key])
|
if (cmds.inputBuffer.idle && startCommands[key])
|
||||||
return startCommands[key];
|
return startCommands[key];
|
||||||
|
return {
|
||||||
return { command: {
|
command: {
|
||||||
exec: function(editor) {cmds.inputBuffer.push(editor, key);}
|
exec: function(editor) {cmds.inputBuffer.push(editor, key);}
|
||||||
} };
|
}
|
||||||
} // wait for input
|
};
|
||||||
else if (key.length == 1 && (hashId == 0 || hashId == 4)) { //no modifier || shift
|
} // if no modifier || shift: wait for input.
|
||||||
|
else if (key.length == 1 && (hashId == 0 || hashId == 4)) {
|
||||||
return {command: "null", passEvent: true};
|
return {command: "null", passEvent: true};
|
||||||
} else if (key == "esc") {
|
} else if (key == "esc" && hashId == 0) {
|
||||||
return {command: coreCommands.stop};
|
return {command: coreCommands.stop};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -102,6 +130,7 @@ exports.handler = {
|
||||||
editor.on("click", exports.onCursorMove);
|
editor.on("click", exports.onCursorMove);
|
||||||
if (util.currentMode !== "insert")
|
if (util.currentMode !== "insert")
|
||||||
cmds.coreCommands.stop.exec(editor);
|
cmds.coreCommands.stop.exec(editor);
|
||||||
|
editor.$vimModeHandler = this;
|
||||||
},
|
},
|
||||||
|
|
||||||
detach: function(editor) {
|
detach: function(editor) {
|
||||||
|
|
@ -110,7 +139,14 @@ exports.handler = {
|
||||||
util.currentMode = "normal";
|
util.currentMode = "normal";
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: cmds.actions
|
actions: cmds.actions,
|
||||||
|
getStatusText: function() {
|
||||||
|
if (util.currentMode == "insert")
|
||||||
|
return "INSERT";
|
||||||
|
if (util.onVisualMode)
|
||||||
|
return (util.onVisualLineMode ? "VISUAL LINE " : "VISUAL ") + cmds.inputBuffer.status;
|
||||||
|
return cmds.inputBuffer.status;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -304,6 +304,7 @@ var inputBuffer = exports.inputBuffer = {
|
||||||
currentCmd: null,
|
currentCmd: null,
|
||||||
//currentMode: 0,
|
//currentMode: 0,
|
||||||
currentCount: "",
|
currentCount: "",
|
||||||
|
status: "",
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
operator: null,
|
operator: null,
|
||||||
|
|
@ -378,6 +379,17 @@ var inputBuffer = exports.inputBuffer = {
|
||||||
else {
|
else {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.waitingForParam || this.motion || this.operator) {
|
||||||
|
this.status += char;
|
||||||
|
} else if (this.currentCount) {
|
||||||
|
this.status = this.currentCount;
|
||||||
|
} else if (this.status) {
|
||||||
|
this.status = "";
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editor._emit("changeStatus");
|
||||||
},
|
},
|
||||||
|
|
||||||
waitForParam: function(cmd) {
|
waitForParam: function(cmd) {
|
||||||
|
|
@ -462,6 +474,7 @@ var inputBuffer = exports.inputBuffer = {
|
||||||
this.operator = null;
|
this.operator = null;
|
||||||
this.motion = null;
|
this.motion = null;
|
||||||
this.currentCount = "";
|
this.currentCount = "";
|
||||||
|
this.status = "";
|
||||||
this.accepting = [NUMBER, OPERATOR, MOTION, ACTION];
|
this.accepting = [NUMBER, OPERATOR, MOTION, ACTION];
|
||||||
this.idle = true;
|
this.idle = true;
|
||||||
this.waitingForParam = null;
|
this.waitingForParam = null;
|
||||||
|
|
|
||||||
|
|
@ -390,10 +390,9 @@ module.exports = {
|
||||||
param: true,
|
param: true,
|
||||||
handlesCount: true,
|
handlesCount: true,
|
||||||
nav: function(editor, range, count, param) {
|
nav: function(editor, range, count, param) {
|
||||||
count = parseInt(count, 10) || 1;
|
|
||||||
var ed = editor;
|
var ed = editor;
|
||||||
var cursor = ed.getCursorPosition();
|
var cursor = ed.getCursorPosition();
|
||||||
var column = util.getLeftNthChar(editor, cursor, param, count);
|
var column = util.getLeftNthChar(editor, cursor, param, count || 1);
|
||||||
|
|
||||||
if (typeof column === "number") {
|
if (typeof column === "number") {
|
||||||
ed.selection.clearSelection(); // Why does it select in the first place?
|
ed.selection.clearSelection(); // Why does it select in the first place?
|
||||||
|
|
@ -473,16 +472,9 @@ module.exports = {
|
||||||
editor.selection.selectLineEnd();
|
editor.selection.selectLineEnd();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"0": {
|
"0": new Motion(function(ed) {
|
||||||
nav: function(editor) {
|
return {row: ed.selection.lead.row, column: 0};
|
||||||
var ed = editor;
|
}),
|
||||||
ed.navigateTo(ed.selection.selectionLead.row, 0);
|
|
||||||
},
|
|
||||||
sel: function(editor) {
|
|
||||||
var ed = editor;
|
|
||||||
ed.selectTo(ed.selection.selectionLead.row, 0);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"G": {
|
"G": {
|
||||||
nav: function(editor, range, count, param) {
|
nav: function(editor, range, count, param) {
|
||||||
if (!count && count !== 0) { // Stupid JS
|
if (!count && count !== 0) { // Stupid JS
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ module.exports = {
|
||||||
editor.unsetStyle('insert-mode');
|
editor.unsetStyle('insert-mode');
|
||||||
editor.unsetStyle('normal-mode');
|
editor.unsetStyle('normal-mode');
|
||||||
if (editor.commands.recording)
|
if (editor.commands.recording)
|
||||||
editor.commands.toggleRecording();
|
editor.commands.toggleRecording(editor);
|
||||||
editor.setOverwrite(false);
|
editor.setOverwrite(false);
|
||||||
},
|
},
|
||||||
insertMode: function(editor) {
|
insertMode: function(editor) {
|
||||||
|
|
@ -43,10 +43,10 @@ module.exports = {
|
||||||
this.onInsertReplaySequence = null;
|
this.onInsertReplaySequence = null;
|
||||||
this.normalMode(editor);
|
this.normalMode(editor);
|
||||||
} else {
|
} else {
|
||||||
editor._emit("vimMode", "insert");
|
editor._emit("changeStatus");
|
||||||
// Record any movements, insertions in insert mode
|
// Record any movements, insertions in insert mode
|
||||||
if(!editor.commands.recording)
|
if(!editor.commands.recording)
|
||||||
editor.commands.toggleRecording();
|
editor.commands.toggleRecording(editor);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
normalMode: function(editor) {
|
normalMode: function(editor) {
|
||||||
|
|
@ -69,10 +69,10 @@ module.exports = {
|
||||||
editor.keyBinding.$data.state = "start";
|
editor.keyBinding.$data.state = "start";
|
||||||
this.onVisualMode = false;
|
this.onVisualMode = false;
|
||||||
this.onVisualLineMode = false;
|
this.onVisualLineMode = false;
|
||||||
editor._emit("changeVimMode", "normal");
|
editor._emit("changeStatus");
|
||||||
// Save recorded keystrokes
|
// Save recorded keystrokes
|
||||||
if (editor.commands.recording) {
|
if (editor.commands.recording) {
|
||||||
editor.commands.toggleRecording();
|
editor.commands.toggleRecording(editor);
|
||||||
return editor.commands.macro;
|
return editor.commands.macro;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -91,7 +91,7 @@ module.exports = {
|
||||||
editor.setStyle('insert-mode');
|
editor.setStyle('insert-mode');
|
||||||
editor.unsetStyle('normal-mode');
|
editor.unsetStyle('normal-mode');
|
||||||
|
|
||||||
editor._emit("changeVimMode", "visual");
|
editor._emit("changeStatus");
|
||||||
if (lineMode) {
|
if (lineMode) {
|
||||||
this.onVisualLineMode = true;
|
this.onVisualLineMode = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -525,8 +525,8 @@ var Selection = function(session) {
|
||||||
|
|
||||||
// Determ the line
|
// Determ the line
|
||||||
var beforeCursor = this.session.getDisplayLine(
|
var beforeCursor = this.session.getDisplayLine(
|
||||||
row, null,
|
row, null, firstColumnPosition.row,
|
||||||
firstColumnPosition.row, firstColumnPosition.column
|
firstColumnPosition.column
|
||||||
);
|
);
|
||||||
|
|
||||||
var leadingSpace = beforeCursor.match(/^\s*/);
|
var leadingSpace = beforeCursor.match(/^\s*/);
|
||||||
|
|
@ -550,12 +550,17 @@ var Selection = function(session) {
|
||||||
**/
|
**/
|
||||||
this.moveCursorLineEnd = function() {
|
this.moveCursorLineEnd = function() {
|
||||||
var lead = this.lead;
|
var lead = this.lead;
|
||||||
var lastRowColumnPosition =
|
var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
|
||||||
this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
|
if (this.lead.column == lineEnd.column) {
|
||||||
this.moveCursorTo(
|
var line = this.session.getLine(lineEnd.row);
|
||||||
lastRowColumnPosition.row,
|
if (lineEnd.column == line.length) {
|
||||||
lastRowColumnPosition.column
|
var textEnd = line.search(/\s+$/);
|
||||||
);
|
if (textEnd > 0)
|
||||||
|
lineEnd.column = textEnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.moveCursorTo(lineEnd.row, lineEnd.column);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue