better support for editor status
This commit is contained in:
parent
e6655172ef
commit
4946158dc7
8 changed files with 78 additions and 16 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");
|
||||||
|
|
@ -737,10 +739,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(200);
|
||||||
|
});
|
||||||
|
env.editor.on("changeSelection", function() {
|
||||||
|
statusUpdate.schedule(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
@ -140,9 +140,14 @@ module.exports = {
|
||||||
called += "2";
|
called += "2";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
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",
|
||||||
|
|
|
||||||
|
|
@ -531,6 +531,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,7 +39,6 @@
|
||||||
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");
|
||||||
|
|
@ -88,7 +87,7 @@ exports.handler = {
|
||||||
data.lastEvent = "keypress";
|
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"))
|
||||||
|
|
@ -131,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) {
|
||||||
|
|
@ -139,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;
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue