mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-16 16:15:45 +01:00
Preliminary REPL mode.
This commit is contained in:
@@ -303,24 +303,29 @@ var CommandMode = Class("CommandMode", {
|
||||
this.keepCommand = userContext.hidden_option_command_afterimage;
|
||||
},
|
||||
|
||||
open: function (command) {
|
||||
this.command = command;
|
||||
get command() this.widgets.command[1],
|
||||
set command(val) this.widgets.command = val,
|
||||
|
||||
get prompt() this.widgets.prompt,
|
||||
set prompt(val) this.widgets.prompt = val,
|
||||
|
||||
open: function (command) {
|
||||
dactyl.assert(isinstance(this.mode, modes.COMMAND_LINE),
|
||||
"Not opening command line in non-command-line mode.");
|
||||
|
||||
commandline.clearMessage();
|
||||
modes.push(this.mode, null, this.closure);
|
||||
modes.push(this.mode, this.extendedMode, this.closure);
|
||||
|
||||
this.widgets.active.commandline.collapsed = false;
|
||||
this.widgets.prompt = this.prompt;
|
||||
this.widgets.command = command || "";
|
||||
|
||||
this.input = this.widgets.active.command.inputField;
|
||||
if (this.historyKey)
|
||||
this.history = CommandLine.History(commandline.widgets.active.command.inputField, this.historyKey, this);
|
||||
this.history = CommandLine.History(this.input, this.historyKey, this);
|
||||
|
||||
if (this.complete)
|
||||
this.completions = CommandLine.Completions(commandline.widgets.active.command.inputField, this);
|
||||
this.completions = CommandLine.Completions(this.input, this);
|
||||
|
||||
if (this.completions && command && commandline.commandSession === this)
|
||||
this.completions.autocompleteTimer.flush(true);
|
||||
@@ -346,6 +351,7 @@ var CommandMode = Class("CommandMode", {
|
||||
leave: function (stack) {
|
||||
if (!stack.push) {
|
||||
commandline.commandSession = null;
|
||||
this.input.dactylKeyPress = undefined;
|
||||
|
||||
if (this.completions)
|
||||
this.completions.cleanup();
|
||||
@@ -1010,6 +1016,7 @@ var CommandLine = Module("commandline", {
|
||||
this.tabTimer.reset();
|
||||
this.autocompleteTimer.reset();
|
||||
this.itemList.visible = false;
|
||||
this.input.dactylKeyPress = undefined;
|
||||
},
|
||||
|
||||
ignoredCount: 0,
|
||||
|
||||
@@ -401,7 +401,14 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
if (fileName == null)
|
||||
if (info && info.file[0] !== "[")
|
||||
({ file: fileName, line: lineNumber, context: ctxt }) = info;
|
||||
else try {
|
||||
|
||||
if (!context)
|
||||
context = _userContext || ctxt;
|
||||
|
||||
if (isinstance(context, ["Sandbox"]))
|
||||
return Cu.evalInSandbox(str, context, "1.8", fileName, lineNumber);
|
||||
else
|
||||
try {
|
||||
if (!context)
|
||||
context = userContext || ctxt;
|
||||
|
||||
@@ -424,10 +431,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
delete context[EVAL_RESULT];
|
||||
delete context[EVAL_STRING];
|
||||
}
|
||||
|
||||
if (!context)
|
||||
context = _userContext || ctxt;
|
||||
return Cu.evalInSandbox(str, context, "1.8", fileName, lineNumber);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1749,21 +1752,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
});
|
||||
});
|
||||
|
||||
commands.add(["javas[cript]", "js"],
|
||||
"Evaluate a JavaScript string",
|
||||
function (args) {
|
||||
if (args.bang) // open JavaScript console
|
||||
dactyl.open("chrome://global/content/console.xul",
|
||||
{ from: "javascript" });
|
||||
else
|
||||
dactyl.userEval(args[0]);
|
||||
}, {
|
||||
bang: true,
|
||||
completer: function (context) completion.javascript(context),
|
||||
hereDoc: true,
|
||||
literal: 0
|
||||
});
|
||||
|
||||
commands.add(["loadplugins", "lpl"],
|
||||
"Load all plugins immediately",
|
||||
function (args) {
|
||||
|
||||
@@ -31,6 +31,8 @@ var Editor = Module("editor", {
|
||||
}
|
||||
|
||||
let elem = dactyl.focusedElement;
|
||||
if (elem.inputField)
|
||||
elem = elem.inputField;
|
||||
|
||||
if (elem.setSelectionRange) {
|
||||
let text = dactyl.clipboardRead(clipboard);
|
||||
@@ -49,7 +51,8 @@ var Editor = Module("editor", {
|
||||
let value = elem.value.substring(0, start) + text + elem.value.substring(end);
|
||||
elem.value = value;
|
||||
|
||||
Editor.getEditor(elem).rootElement.firstChild.textContent = value;
|
||||
if (/^(search|text)$/.test(elem.type))
|
||||
Editor.getEditor(elem).rootElement.firstChild.textContent = value;
|
||||
|
||||
elem.selectionStart = Math.min(start + (toStart ? 0 : text.length), elem.value.length);
|
||||
elem.selectionEnd = elem.selectionStart;
|
||||
|
||||
@@ -217,7 +217,12 @@ var KeyProcessor = Class("KeyProcessor", {
|
||||
else if (map.motion)
|
||||
return KeyArgProcessor(this, map, true, "motion");
|
||||
|
||||
return this.execute(map, { count: this.count, command: this.command, events: this.events, allEvents: this.allEvents });
|
||||
return this.execute(map, {
|
||||
allEvents: this.allEvents,
|
||||
command: this.command,
|
||||
count: this.count,
|
||||
events: this.events
|
||||
});
|
||||
}
|
||||
|
||||
if (!this.waiting)
|
||||
@@ -347,7 +352,6 @@ var Events = Module("events", {
|
||||
|
||||
this._fullscreen = window.fullScreen;
|
||||
this._lastFocus = null;
|
||||
this._currentMacro = "";
|
||||
this._macroKeys = [];
|
||||
this._lastMacro = "";
|
||||
|
||||
@@ -426,8 +430,8 @@ var Events = Module("events", {
|
||||
* @param {boolean} capture When true, listen during the capture
|
||||
* phase, otherwise during the bubbling phase.
|
||||
*/
|
||||
get addSessionListener() this.builtin.closure.listen,
|
||||
get listen() this.builtin.closure.listen,
|
||||
addSessionListener: deprecated("events.listen", { get: function addSessionListener() this.listen }),
|
||||
|
||||
/**
|
||||
* Wraps an event listener to ensure that errors are reported.
|
||||
@@ -462,34 +466,33 @@ var Events = Module("events", {
|
||||
*
|
||||
* @param {string} macro The name for the macro.
|
||||
*/
|
||||
startRecording: function (macro) {
|
||||
// TODO: ignore this like Vim?
|
||||
dactyl.assert(/[a-zA-Z0-9]/.test(macro),
|
||||
_recording: null,
|
||||
get recording() this._recording,
|
||||
|
||||
set recording(macro) {
|
||||
dactyl.assert(macro == null || /[a-zA-Z0-9]/.test(macro),
|
||||
"E354: Invalid register name: '" + macro + "'");
|
||||
|
||||
modes.recording = true;
|
||||
modes.recording = !!macro;
|
||||
|
||||
if (/[A-Z]/.test(macro)) { // uppercase (append)
|
||||
this._currentMacro = macro.toLowerCase();
|
||||
this._macroKeys = events.fromString((this._macros.get(this._currentMacro) || { keys: "" }).keys, true)
|
||||
macro = macro.toLowerCase();
|
||||
this._macroKeys = events.fromString((this._macros.get(macro) || { keys: "" }).keys, true)
|
||||
.map(events.closure.toString);
|
||||
}
|
||||
else {
|
||||
this._currentMacro = macro;
|
||||
else if (macro) {
|
||||
this._macroKeys = [];
|
||||
}
|
||||
},
|
||||
else {
|
||||
this._macros.set(this.recording, {
|
||||
keys: this._macroKeys.join(""),
|
||||
timeRecorded: Date.now()
|
||||
});
|
||||
|
||||
/** Terminates the recording of the current key event macro. */
|
||||
finishRecording: function () {
|
||||
modes.recording = false;
|
||||
this._macros.set(this._currentMacro, {
|
||||
keys: this._macroKeys.join(""),
|
||||
timeRecorded: Date.now()
|
||||
});
|
||||
|
||||
dactyl.log("Recorded " + this._currentMacro + ": " + this._macroKeys.join(""), 9);
|
||||
dactyl.echomsg("Recorded macro '" + this._currentMacro + "'");
|
||||
dactyl.log("Recorded " + this.recording + ": " + this._macroKeys.join(""), 9);
|
||||
dactyl.echomsg("Recorded macro '" + this.recording + "'");
|
||||
}
|
||||
this._recording = macro || null;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1457,7 +1460,7 @@ var Events = Module("events", {
|
||||
["q", "<record-macro>"], "Record a key sequence into a macro",
|
||||
function ({ arg }) {
|
||||
events._macroKeys.pop();
|
||||
events[modes.recording ? "finishRecording" : "startRecording"](arg);
|
||||
events.recording = arg;
|
||||
},
|
||||
{ get arg() !modes.recording });
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
/** @instance hints */
|
||||
|
||||
var HintSession = Class("HintSession", CommandMode, {
|
||||
get extendedMode() modes.HINTS,
|
||||
|
||||
init: function init(mode, opts) {
|
||||
init.supercall(this);
|
||||
|
||||
@@ -465,7 +467,7 @@ var HintSession = Class("HintSession", CommandMode, {
|
||||
}
|
||||
|
||||
this.timeout(function () {
|
||||
if (isinstance(modes.main, modes.HINTS) && !this.continue)
|
||||
if ((modes.extended & modes.HINTS) && !this.continue)
|
||||
modes.pop();
|
||||
commandline.lastEcho = null; // Hack.
|
||||
dactyl.trapErrors("action", this.hintMode,
|
||||
|
||||
Reference in New Issue
Block a user