1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-04-10 09:33:32 +02:00

Add preliminary mode inheritance and BASE/INSERT modes.

This commit is contained in:
Kris Maglione
2011-01-18 18:37:38 -05:00
parent b836cc8110
commit 551f777c22
4 changed files with 38 additions and 7 deletions

View File

@@ -606,7 +606,7 @@ var CommandLine = Module("commandline", {
if (params.pop) if (params.pop)
commandline.leave(); commandline.leave();
}, },
mainMode: this.currentExtendedMode keyModes: [this.currentExtendedMode]
}); });
this._keepCommand = false; this._keepCommand = false;

View File

@@ -959,7 +959,7 @@ var Events = Module("events", {
if (overrideMode) if (overrideMode)
processors = [Events.KeyProcessor(overrideMode, mode.extended)]; processors = [Events.KeyProcessor(overrideMode, mode.extended)];
else { else {
let keyModes = array(mode.params.keyModes || []).concat([mode.params.mainMode, mode.main]).compact(); let keyModes = array([mode.params.keyModes, mode.main, mode.main.allBases]).flatten().compact();
let hives = mappings.hives.slice(event.noremap ? -1 : 0); let hives = mappings.hives.slice(event.noremap ? -1 : 0);
@@ -972,7 +972,7 @@ var Events = Module("events", {
input.preExecute = mode.params.preExecute; input.preExecute = mode.params.preExecute;
if (mode.params.postExecute) if (mode.params.postExecute)
input.postExecute = mode.params.postExecute; input.postExecute = mode.params.postExecute;
if (mode.params.onEvent && i == processors.length - 1) if (mode.params.onEvent && input.hive === mappings.builtinHive)
input.fallthrough = function (event) { input.fallthrough = function (event) {
// Bloody hell. // Bloody hell.
if (events.toString(event) === "<C-h>") if (events.toString(event) === "<C-h>")

View File

@@ -35,12 +35,19 @@ var Modes = Module("modes", {
this.boundProperties = {}; this.boundProperties = {};
// main modes, only one should ever be active this.addMode("BASE", {
char: "b",
description: "The base mode for most other modes"
});
this.addMode("NORMAL", { this.addMode("NORMAL", {
char: "n", char: "n",
description: "Active when nothing is focused", description: "Active when nothing is focused",
display: function () null display: function () null
}); });
this.addMode("INPUT", {
char: "I",
description: "The base mode for input modes, including Insert and Command Line"
});
this.addMode("INSERT", { this.addMode("INSERT", {
char: "i", char: "i",
description: "Active when an input element is focused", description: "Active when an input element is focused",
@@ -101,12 +108,14 @@ var Modes = Module("modes", {
}); });
this.addMode("PASS_THROUGH", { this.addMode("PASS_THROUGH", {
description: "All keys but <C-v> are ignored by " + config.appName, description: "All keys but <C-v> are ignored by " + config.appName,
bases: [],
hidden: true hidden: true
}); });
this.addMode("QUOTE", { this.addMode("QUOTE", {
hidden: true, hidden: true,
description: "The next key sequence is ignored by " + config.appName + ", unless in Pass Through mode", description: "The next key sequence is ignored by " + config.appName + ", unless in Pass Through mode",
bases: [],
display: function () modes.getStack(1).main == modes.PASS_THROUGH display: function () modes.getStack(1).main == modes.PASS_THROUGH
? (modes.getStack(2).main.display() || modes.getStack(2).main.name) + " (next)" ? (modes.getStack(2).main.display() || modes.getStack(2).main.name) + " (next)"
: "PASS THROUGH (next)" : "PASS THROUGH (next)"
@@ -151,7 +160,8 @@ var Modes = Module("modes", {
input: true input: true
}); });
this.addMode("IGNORE", { hidden: true }, { this.addMode("IGNORE", { hidden: true }, {
onEvent: function (event) false onEvent: function (event) false,
bases: []
}); });
this.push(this.NORMAL, 0, { this.push(this.NORMAL, 0, {
@@ -387,6 +397,21 @@ var Modes = Module("modes", {
}, options); }, options);
}, },
isinstance: function (obj)
this.allBases.indexOf(obj >= 0) || callable(obj) && this instanceof obj,
allBases: Class.memoize(function () {
let seen = {}, res = [], queue = this.bases;
for (let mode in array.iterValues(queue))
if (!set.add(seen, mode)) {
res.push(mode);
queue.push.apply(queue, mode.bases);
}
return res;
}),
get bases() this.input ? [modes.INPUT] : [modes.BASE],
get toStringParams() [this.name], get toStringParams() [this.name],
valueOf: function () this.id, valueOf: function () this.id,

View File

@@ -417,12 +417,19 @@ var isinstance_types = {
number: Number number: Number
}; };
function isinstance(targ, src) { function isinstance(targ, src) {
if (targ == null)
return false;
src = Array.concat(src); src = Array.concat(src);
for (var i = 0; i < src.length; i++) { for (var i = 0; i < src.length; i++) {
if (typeof src[i] === "string") { if (typeof src[i] === "string") {
if (objproto.toString.call(targ) === "[object " + src[i] + "]") if (objproto.toString.call(targ) === "[object " + src[i] + "]")
return true; return true;
} }
else if ("isinstance" in targ) {
if (targ.isinstance(src[i]))
return true;
}
else { else {
if (targ instanceof src[i]) if (targ instanceof src[i])
return true; return true;
@@ -1317,8 +1324,7 @@ var array = Class("array", Array, {
* @returns {Iterator(Object)} * @returns {Iterator(Object)}
*/ */
iterValues: function iterValues(ary) { iterValues: function iterValues(ary) {
let length = ary.length; for (let i = 0; i < ary.length; i++)
for (let i = 0; i < length; i++)
yield ary[i]; yield ary[i];
}, },