1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 08:18:00 +01:00

Some 'timeout' compromises: Guess whether there are native bindings for a key, execute a timeout if so.

This commit is contained in:
Kris Maglione
2011-06-27 19:28:59 -04:00
parent b5b504f051
commit bfb111894c
3 changed files with 18 additions and 12 deletions

View File

@@ -858,7 +858,7 @@ var Editor = Module("editor", {
options: function () { options: function () {
options.add(["editor"], options.add(["editor"],
"The external text editor", "The external text editor",
"string", "gvim -f +<line> '+sil! call cursor(0, <column>)' <file>", { "string", 'gvim -f +<line> +"sil! call cursor(0, <column>)" <file>', {
format: function (obj, value) { format: function (obj, value) {
let args = commands.parseArgs(value || this.value, { argCount: "*", allowUnknownOptions: true }) let args = commands.parseArgs(value || this.value, { argCount: "*", allowUnknownOptions: true })
.map(util.compileMacro).filter(function (fmt) fmt.valid(obj)) .map(util.compileMacro).filter(function (fmt) fmt.valid(obj))

View File

@@ -47,6 +47,7 @@ var ProcessorStack = Class("ProcessorStack", {
passUnknown: Class.memoize(function () options.get("passunknown").getKey(this.modes)), passUnknown: Class.memoize(function () options.get("passunknown").getKey(this.modes)),
notify: function () { notify: function () {
events.dbg("NOTIFY()");
events.keyEvents = []; events.keyEvents = [];
events.processor = null; events.processor = null;
if (!this.execute(undefined, true)) { if (!this.execute(undefined, true)) {
@@ -62,7 +63,7 @@ var ProcessorStack = Class("ProcessorStack", {
callable(result) ? result.toSource().substr(0, 50) : result), callable(result) ? result.toSource().substr(0, 50) : result),
execute: function execute(result, force) { execute: function execute(result, force) {
events.dbg("EXECUTE " + this._result(result) + " " + force + " " + this.events.length + " " + this.processors.length); events.dbg("EXECUTE(" + this._result(result) + ", " + force + ") events:" + this.events.length + " processors:" + this.processors.length + " actions:" + this.actions.length);
let processors = this.processors; let processors = this.processors;
let length = 1; let length = 1;
@@ -72,7 +73,7 @@ var ProcessorStack = Class("ProcessorStack", {
if (this.ownsBuffer) if (this.ownsBuffer)
statusline.inputBuffer = this.processors.length ? this.buffer : ""; statusline.inputBuffer = this.processors.length ? this.buffer : "";
if (!processors.some(function (p) !p.extended) && this.actions.length) { if (!this.processors.some(function (p) !p.extended) && this.actions.length) {
// We have matching actions and no processors other than // We have matching actions and no processors other than
// those waiting on further arguments. Execute actions as // those waiting on further arguments. Execute actions as
// long as they continue to return PASS. // long as they continue to return PASS.
@@ -98,7 +99,7 @@ var ProcessorStack = Class("ProcessorStack", {
// Kill the event, set a timeout to give up waiting if applicable. // Kill the event, set a timeout to give up waiting if applicable.
result = Events.KILL; result = Events.KILL;
if (options["timeout"] && (this.actions.length || events.hasNativeKey(this.main, this.events[0]))) if (options["timeout"] && (this.actions.length || events.hasNativeKey(this.events[0], this.main, this.passUnknown)))
this.timer = services.Timer(this, options["timeoutlen"], services.Timer.TYPE_ONE_SHOT); this.timer = services.Timer(this, options["timeoutlen"], services.Timer.TYPE_ONE_SHOT);
} }
else if (result !== Events.KILL && !this.actions.length && else if (result !== Events.KILL && !this.actions.length &&
@@ -119,7 +120,7 @@ var ProcessorStack = Class("ProcessorStack", {
// pass the event. // pass the event.
result = Events.PASS; result = Events.PASS;
events.dbg("RESULT: " + length + " " + this._result(result)); events.dbg("RESULT: " + length + " " + this._result(result) + "\n\n");
if (result !== Events.PASS || this.events.length > 1) if (result !== Events.PASS || this.events.length > 1)
if (result !== Events.ABORT || !this.events[0].isReplay) if (result !== Events.ABORT || !this.events[0].isReplay)
@@ -159,7 +160,7 @@ var ProcessorStack = Class("ProcessorStack", {
let actions = []; let actions = [];
let processors = []; let processors = [];
events.dbg("KEY: " + key + " skipmap: " + event.skipmap + " macro: " + event.isMacro + " replay: " + event.isReplay); events.dbg("PROCESS(" + key + ") skipmap: " + event.skipmap + " macro: " + event.isMacro + " replay: " + event.isReplay);
for (let [i, input] in Iterator(this.processors)) { for (let [i, input] in Iterator(this.processors)) {
let res = input.process(event); let res = input.process(event);
@@ -182,7 +183,7 @@ var ProcessorStack = Class("ProcessorStack", {
events.dbg("RESULT: " + event.getPreventDefault() + " " + this._result(result)); events.dbg("RESULT: " + event.getPreventDefault() + " " + this._result(result));
events.dbg("ACTIONS: " + actions.length + " " + this.actions.length); events.dbg("ACTIONS: " + actions.length + " " + this.actions.length);
events.dbg("PROCESSORS:", processors); events.dbg("PROCESSORS:", processors, "\n");
this._actions = actions; this._actions = actions;
this.actions = actions.concat(this.actions); this.actions = actions.concat(this.actions);
@@ -1067,12 +1068,16 @@ var Events = Module("events", {
* Returns true if there's a known native key handler for the given * Returns true if there's a known native key handler for the given
* event in the given mode. * event in the given mode.
* *
* @param {Modes.Mode} mode The main mode.
* @param {Event} event A keypress event. * @param {Event} event A keypress event.
* @param {Modes.Mode} mode The main mode.
* @param {boolean} passUnknown Whether unknown keys should be passed.
*/ */
hasNativeKey: function hasNativeKey(mode, event) { hasNativeKey: function hasNativeKey(event, mode, passUnknown) {
if (mode.input) if (mode.input && event.charCode && !(event.ctrlKey || event.metaKey))
return event.charCode && !(event.ctrlKey || event.metaKey); return true;
if (!passUnknown)
return false;
var elements = document.getElementsByTagNameNS(XUL, "key"); var elements = document.getElementsByTagNameNS(XUL, "key");
var filters = []; var filters = [];

View File

@@ -478,7 +478,8 @@ var Mappings = Module("mappings", {
} }
if (args[1] && !/^<nop>$/i.test(args[1]) if (args[1] && !/^<nop>$/i.test(args[1])
&& !args["-count"] && !args["-ex"] && !args["-javascript"]) && !args["-count"] && !args["-ex"] && !args["-javascript"]
&& mapmodes.every(function (m) m.count))
args[1] = "<count>" + args[1]; args[1] = "<count>" + args[1];
let [lhs, rhs] = args; let [lhs, rhs] = args;