mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 23:37:59 +01:00
Improve the efficiency/bugginess of abbrev mappings.
This commit is contained in:
@@ -1161,14 +1161,16 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
|
|||||||
"<*-Home>", "<*-End>", "<*-PageUp>", "<*-PageDown>",
|
"<*-Home>", "<*-End>", "<*-PageUp>", "<*-PageDown>",
|
||||||
"<M-c>", "<M-v>", "<*-Tab>"],
|
"<M-c>", "<M-v>", "<*-Tab>"],
|
||||||
"Handled by " + config.host,
|
"Handled by " + config.host,
|
||||||
() => Events.PASS_THROUGH);
|
() => Events.PASS,
|
||||||
|
{ passThrough: true });
|
||||||
|
|
||||||
mappings.add([modes.INSERT],
|
mappings.add([modes.INSERT],
|
||||||
["<Space>", "<Return>"], "Expand Insert mode abbreviation",
|
["<Space>", "<Return>"], "Expand Insert mode abbreviation",
|
||||||
function () {
|
function () {
|
||||||
editor.expandAbbreviation(modes.INSERT);
|
editor.expandAbbreviation(modes.INSERT);
|
||||||
return Events.PASS_THROUGH;
|
return Events.PASS;
|
||||||
});
|
},
|
||||||
|
{ passThrough: true });
|
||||||
|
|
||||||
mappings.add([modes.INSERT],
|
mappings.add([modes.INSERT],
|
||||||
["<C-]>", "<C-5>"], "Expand Insert mode abbreviation",
|
["<C-]>", "<C-5>"], "Expand Insert mode abbreviation",
|
||||||
|
|||||||
@@ -784,21 +784,43 @@ var Events = Module("events", {
|
|||||||
|
|
||||||
let key = DOM.Event.stringify(event);
|
let key = DOM.Event.stringify(event);
|
||||||
|
|
||||||
let pass = this.passing && !event.isMacro ||
|
let hasCandidates = mode => {
|
||||||
DOM.Event.feedingEvent && DOM.Event.feedingEvent.isReplay ||
|
return mappings.hives.some(hive => (hive.get(mode, key, true) ||
|
||||||
event.isReplay ||
|
hive.getCandidates(mode, key, true)));
|
||||||
modes.main == modes.PASS_THROUGH ||
|
};
|
||||||
modes.main == modes.QUOTE
|
|
||||||
&& modes.getStack(1).main !== modes.PASS_THROUGH
|
let pass = (() => {
|
||||||
&& !this.shouldPass(event) ||
|
if (this.passing && !event.isMacro)
|
||||||
!modes.passThrough && this.shouldPass(event) ||
|
return true;
|
||||||
!this.processor && event.type === "keydown"
|
|
||||||
&& options.get("passunknown").getKey(modes.main.allBases)
|
if (DOM.Event.feedingEvent && DOM.Event.feedingEvent.isReplay)
|
||||||
&& !(modes.main.count && /^\d$/.test(key) ||
|
return true;
|
||||||
modes.main.allBases.some(
|
|
||||||
mode => mappings.hives
|
if (event.isReplay)
|
||||||
.some(hive => hive.get(mode, key)
|
return true;
|
||||||
|| hive.getCandidates(mode, key))));
|
|
||||||
|
if (modes.main == modes.PASS_THROUGH)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (modes.main == modes.QUOTE &&
|
||||||
|
modes.getStack(1).main !== modes.PASS_THROUGH &&
|
||||||
|
!this.shouldPass(event))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!modes.passThrough && this.shouldPass(event))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!this.processor && event.type === "keydown" &&
|
||||||
|
options.get("passunknown").getKey(modes.main.allBases)) {
|
||||||
|
if (!(modes.main.count && /^\d$/.test(key)))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (modes.main.allBases.some(hasCandidates))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
})();
|
||||||
|
|
||||||
events.dbg("ON " + event.type.toUpperCase() + " " + key +
|
events.dbg("ON " + event.type.toUpperCase() + " " + key +
|
||||||
" passing: " + this.passing + " " +
|
" passing: " + this.passing + " " +
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ var Map = Class("Map", {
|
|||||||
/** @property {boolean} Whether the RHS of the mapping should expand mappings recursively. */
|
/** @property {boolean} Whether the RHS of the mapping should expand mappings recursively. */
|
||||||
noremap: false,
|
noremap: false,
|
||||||
|
|
||||||
|
passThrough: true,
|
||||||
|
|
||||||
/** @property {function(object)} A function to be executed before this mapping. */
|
/** @property {function(object)} A function to be executed before this mapping. */
|
||||||
preExecute: function preExecute(args) {},
|
preExecute: function preExecute(args) {},
|
||||||
/** @property {function(object)} A function to be executed after this mapping. */
|
/** @property {function(object)} A function to be executed after this mapping. */
|
||||||
@@ -232,10 +234,13 @@ var MapHive = Class("MapHive", Contexts.Hive, {
|
|||||||
*
|
*
|
||||||
* @param {Modes.Mode} mode The mode to search.
|
* @param {Modes.Mode} mode The mode to search.
|
||||||
* @param {string} cmd The map name to match.
|
* @param {string} cmd The map name to match.
|
||||||
|
* @param {boolean} skipPassThrough Ignore pass-through mappings.
|
||||||
* @returns {Map|null}
|
* @returns {Map|null}
|
||||||
*/
|
*/
|
||||||
get: function (mode, cmd) {
|
get: function (mode, cmd, skipPassThrough = false) {
|
||||||
return this.getStack(mode).mappings[cmd];
|
let map = this.getStack(mode).mappings[cmd];
|
||||||
|
if (!(skipPassThrough && map.passThrough))
|
||||||
|
return map;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -244,9 +249,12 @@ var MapHive = Class("MapHive", Contexts.Hive, {
|
|||||||
*
|
*
|
||||||
* @param {Modes.Mode} mode The mode to search.
|
* @param {Modes.Mode} mode The mode to search.
|
||||||
* @param {string} prefix The map prefix string to match.
|
* @param {string} prefix The map prefix string to match.
|
||||||
|
* @param {boolean} skipPassThrough Ignore pass-through mappings.
|
||||||
* @returns {number)
|
* @returns {number)
|
||||||
*/
|
*/
|
||||||
getCandidates: function (mode, prefix) {
|
getCandidates: function (mode, prefix, skipPassThrough = false) {
|
||||||
|
if (skipPassThrough)
|
||||||
|
return this.getStack(mode).hardCandidates[prefix] || 0;
|
||||||
return this.getStack(mode).candidates[prefix] || 0;
|
return this.getStack(mode).candidates[prefix] || 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -294,9 +302,8 @@ var MapHive = Class("MapHive", Contexts.Hive, {
|
|||||||
}, {
|
}, {
|
||||||
Stack: Class("Stack", Array, {
|
Stack: Class("Stack", Array, {
|
||||||
init: function (ary) {
|
init: function (ary) {
|
||||||
let self = ary || [];
|
if (ary)
|
||||||
self.__proto__ = this.__proto__;
|
this.push(...ary);
|
||||||
return self;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"@@iterator": function () {
|
"@@iterator": function () {
|
||||||
@@ -304,6 +311,7 @@ var MapHive = Class("MapHive", Contexts.Hive, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get candidates() { return this.states.candidates; },
|
get candidates() { return this.states.candidates; },
|
||||||
|
get hardCandidates() { return this.states.hardCandidates; },
|
||||||
get mappings() { return this.states.mappings; },
|
get mappings() { return this.states.mappings; },
|
||||||
|
|
||||||
add: function (map) {
|
add: function (map) {
|
||||||
@@ -312,8 +320,9 @@ var MapHive = Class("MapHive", Contexts.Hive, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
states: Class.Memoize(function () {
|
states: Class.Memoize(function () {
|
||||||
var states = {
|
let states = {
|
||||||
candidates: {},
|
candidates: {},
|
||||||
|
hardCandidates: {},
|
||||||
mappings: {}
|
mappings: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -323,8 +332,11 @@ var MapHive = Class("MapHive", Contexts.Hive, {
|
|||||||
let state = "";
|
let state = "";
|
||||||
for (let key of DOM.Event.iterKeys(name)) {
|
for (let key of DOM.Event.iterKeys(name)) {
|
||||||
state += key;
|
state += key;
|
||||||
if (state !== name)
|
if (state !== name) {
|
||||||
states.candidates[state] = (states.candidates[state] || 0) + 1;
|
states.candidates[state] = (states.candidates[state] || 0) + 1;
|
||||||
|
if (!map.passThrough)
|
||||||
|
states.hardCandidates[state] = (states.hardCandidates[state] || 0) + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return states;
|
return states;
|
||||||
|
|||||||
Reference in New Issue
Block a user