1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 15:48:00 +01:00

Use .filter(). .filter() is awesome.

This commit is contained in:
Kris Maglione
2014-02-23 10:21:30 -08:00
parent fbed9ec4af
commit 9470e18566

View File

@@ -21,13 +21,7 @@ var Modes = Module("modes", {
this._recording = false; this._recording = false;
this._replaying = false; // playing a macro this._replaying = false; // playing a macro
this._modeStack = update([], { this._modeStack = Modes.ModeStack([]);
pop: function pop() {
if (this.length <= 1)
throw Error("Trying to pop last element in mode stack");
return pop.superapply(this, arguments);
}
});
this._modes = []; this._modes = [];
this._mainModes = []; this._mainModes = [];
@@ -275,9 +269,8 @@ var Modes = Module("modes", {
if (covert && this.topOfStack.main != mode) { if (covert && this.topOfStack.main != mode) {
util.assert(mode != this.NORMAL); util.assert(mode != this.NORMAL);
let i = this._modeStack.findIndex(m => m.main == mode); this._modeStack = Modes.ModeStack(
if (i >= 0) this._modeStack.filter(m => m.main != mode));
this._modeStack.splice(i);
} }
else if (this.stack.some(m => m.main == mode)) { else if (this.stack.some(m => m.main == mode)) {
this.pop(mode); this.pop(mode);
@@ -489,6 +482,14 @@ var Modes = Module("modes", {
}, { }, {
_id: 0 _id: 0
}), }),
ModeStack: function ModeStack(array)
update(array, {
pop: function pop() {
if (this.length <= 1)
throw Error("Trying to pop last element in mode stack");
return pop.superapply(this, arguments);
}
}),
StackElement: (function () { StackElement: (function () {
const StackElement = Struct("main", "extended", "params", "saved"); const StackElement = Struct("main", "extended", "params", "saved");
StackElement.className = "Modes.StackElement"; StackElement.className = "Modes.StackElement";