mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 21:38:11 +01:00
Speed up hint opening a bit.
This commit is contained in:
@@ -1272,7 +1272,6 @@ const CommandLine = Module("commandline", {
|
|||||||
this.wildtypes = this.wildmode.value;
|
this.wildtypes = this.wildmode.value;
|
||||||
this.itemList = commandline._completionList;
|
this.itemList = commandline._completionList;
|
||||||
this.itemList.setItems(this.context);
|
this.itemList.setItems(this.context);
|
||||||
this.reset();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
UP: {},
|
UP: {},
|
||||||
@@ -1901,9 +1900,10 @@ const ItemList = Class("ItemList", {
|
|||||||
show: function show() { this._container.collapsed = false; },
|
show: function show() { this._container.collapsed = false; },
|
||||||
visible: function visible() !this._container.collapsed,
|
visible: function visible() !this._container.collapsed,
|
||||||
|
|
||||||
reset: function () {
|
reset: function (brief) {
|
||||||
this._startIndex = this._endIndex = this._selIndex = -1;
|
this._startIndex = this._endIndex = this._selIndex = -1;
|
||||||
this._div = null;
|
this._div = null;
|
||||||
|
if (!brief)
|
||||||
this.selectItem(-1);
|
this.selectItem(-1);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1915,7 +1915,7 @@ const ItemList = Class("ItemList", {
|
|||||||
this._minHeight = 0;
|
this._minHeight = 0;
|
||||||
this._startIndex = this._endIndex = this._selIndex = -1;
|
this._startIndex = this._endIndex = this._selIndex = -1;
|
||||||
this._items = newItems;
|
this._items = newItems;
|
||||||
this.reset();
|
this.reset(true);
|
||||||
if (typeof selectedItem == "number") {
|
if (typeof selectedItem == "number") {
|
||||||
this.selectItem(selectedItem);
|
this.selectItem(selectedItem);
|
||||||
this.show();
|
this.show();
|
||||||
|
|||||||
@@ -952,7 +952,7 @@ const Dactyl = Module("dactyl", {
|
|||||||
* @param {function} func The function to call
|
* @param {function} func The function to call
|
||||||
* @param {object} self The 'this' object for the function.
|
* @param {object} self The 'this' object for the function.
|
||||||
*/
|
*/
|
||||||
trapErrors: function (func, self) {
|
trapErrors: function trapErrors(func, self) {
|
||||||
try {
|
try {
|
||||||
return func.apply(self || this, Array.slice(arguments, 2));
|
return func.apply(self || this, Array.slice(arguments, 2));
|
||||||
}
|
}
|
||||||
@@ -968,7 +968,7 @@ const Dactyl = Module("dactyl", {
|
|||||||
*
|
*
|
||||||
* @param {Object} error The error object.
|
* @param {Object} error The error object.
|
||||||
*/
|
*/
|
||||||
reportError: function (error, echo) {
|
reportError: function reportError(error, echo) {
|
||||||
if (error instanceof FailedAssertion) {
|
if (error instanceof FailedAssertion) {
|
||||||
if (error.message)
|
if (error.message)
|
||||||
dactyl.echoerr(error.message);
|
dactyl.echoerr(error.message);
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ const Events = Module("events", {
|
|||||||
*/
|
*/
|
||||||
wrapListener: function wrapListener(method, self) {
|
wrapListener: function wrapListener(method, self) {
|
||||||
self = self || this;
|
self = self || this;
|
||||||
return function (event) {
|
return function wrappedListener(event) {
|
||||||
try {
|
try {
|
||||||
method.apply(self, arguments);
|
method.apply(self, arguments);
|
||||||
}
|
}
|
||||||
@@ -447,7 +447,7 @@ const Events = Module("events", {
|
|||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
toString: function (event) {
|
toString: function toString(event) {
|
||||||
if (!event)
|
if (!event)
|
||||||
return "[instance events]";
|
return "[instance events]";
|
||||||
|
|
||||||
@@ -660,7 +660,7 @@ const Events = Module("events", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// TODO: Merge with onFocusChange
|
// TODO: Merge with onFocusChange
|
||||||
onFocus: function (event) {
|
onFocus: function onFocus(event) {
|
||||||
let elem = event.originalTarget;
|
let elem = event.originalTarget;
|
||||||
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
|
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
|
||||||
|
|
||||||
@@ -672,7 +672,7 @@ const Events = Module("events", {
|
|||||||
// argument "event" is deliberately not used, as i don't seem to have
|
// argument "event" is deliberately not used, as i don't seem to have
|
||||||
// access to the real focus target
|
// access to the real focus target
|
||||||
// Huh? --djk
|
// Huh? --djk
|
||||||
onFocusChange: function (event) {
|
onFocusChange: function onFocusChange(event) {
|
||||||
// command line has it's own focus change handler
|
// command line has it's own focus change handler
|
||||||
if (dactyl.mode == modes.COMMAND_LINE)
|
if (dactyl.mode == modes.COMMAND_LINE)
|
||||||
return;
|
return;
|
||||||
@@ -737,7 +737,7 @@ const Events = Module("events", {
|
|||||||
// this keypress handler gets always called first, even if e.g.
|
// this keypress handler gets always called first, even if e.g.
|
||||||
// the commandline has focus
|
// the commandline has focus
|
||||||
// TODO: ...help me...please...
|
// TODO: ...help me...please...
|
||||||
onKeyPress: function (event) {
|
onKeyPress: function onKeyPress(event) {
|
||||||
function isEscape(key) key == "<Esc>" || key == "<C-[>";
|
function isEscape(key) key == "<Esc>" || key == "<C-[>";
|
||||||
|
|
||||||
function killEvent() {
|
function killEvent() {
|
||||||
@@ -940,31 +940,31 @@ const Events = Module("events", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// this is need for sites like msn.com which focus the input field on keydown
|
// this is need for sites like msn.com which focus the input field on keydown
|
||||||
onKeyUpOrDown: function (event) {
|
onKeyUpOrDown: function onKeyUpOrDown(event) {
|
||||||
if (!Events.isInputElemFocused() && !modes.passThrough)
|
if (!Events.isInputElemFocused() && !modes.passThrough)
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
},
|
},
|
||||||
|
|
||||||
onMouseDown: function (event) {
|
onMouseDown: function onMouseDown(event) {
|
||||||
let elem = event.target;
|
let elem = event.target;
|
||||||
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
|
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
|
||||||
for (; win; win = win != win.parent && win.parent)
|
for (; win; win = win != win.parent && win.parent)
|
||||||
win.dactylFocusAllowed = true;
|
win.dactylFocusAllowed = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
onPopupShown: function (event) {
|
onPopupShown: function onPopupShown(event) {
|
||||||
if (event.originalTarget.localName == "tooltip" || event.originalTarget.id == "dactyl-visualbell")
|
if (event.originalTarget.localName == "tooltip" || event.originalTarget.id == "dactyl-visualbell")
|
||||||
return;
|
return;
|
||||||
modes.add(modes.MENU);
|
modes.add(modes.MENU);
|
||||||
},
|
},
|
||||||
|
|
||||||
onPopupHidden: function () {
|
onPopupHidden: function onPopupHidden() {
|
||||||
// gContextMenu is set to NULL, when a context menu is closed
|
// gContextMenu is set to NULL, when a context menu is closed
|
||||||
if (window.gContextMenu == null && !this._activeMenubar)
|
if (window.gContextMenu == null && !this._activeMenubar)
|
||||||
modes.remove(modes.MENU);
|
modes.remove(modes.MENU);
|
||||||
},
|
},
|
||||||
|
|
||||||
onResize: function (event) {
|
onResize: function onResize(event) {
|
||||||
if (window.fullScreen != this._fullscreen) {
|
if (window.fullScreen != this._fullscreen) {
|
||||||
this._fullscreen = window.fullScreen;
|
this._fullscreen = window.fullScreen;
|
||||||
dactyl.triggerObserver("fullscreen", this._fullscreen);
|
dactyl.triggerObserver("fullscreen", this._fullscreen);
|
||||||
@@ -972,7 +972,7 @@ const Events = Module("events", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onSelectionChange: function (event) {
|
onSelectionChange: function onSelectionChange(event) {
|
||||||
let controller = document.commandDispatcher.getControllerForCommand("cmd_copy");
|
let controller = document.commandDispatcher.getControllerForCommand("cmd_copy");
|
||||||
let couldCopy = controller && controller.isCommandEnabled("cmd_copy");
|
let couldCopy = controller && controller.isCommandEnabled("cmd_copy");
|
||||||
|
|
||||||
@@ -988,14 +988,14 @@ const Events = Module("events", {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
isContentNode: function (node) {
|
isContentNode: function isContentNode(node) {
|
||||||
let win = (node.ownerDocument || node).defaultView;
|
let win = (node.ownerDocument || node).defaultView;
|
||||||
for (; win; win = win.parent != win && win.parent)
|
for (; win; win = win.parent != win && win.parent)
|
||||||
if (win == window.content)
|
if (win == window.content)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
isInputElemFocused: function () {
|
isInputElemFocused: function isInputElemFocused() {
|
||||||
let elem = dactyl.focus;
|
let elem = dactyl.focus;
|
||||||
return elem instanceof HTMLInputElement && set.has(util.editableInputs, elem.type) ||
|
return elem instanceof HTMLInputElement && set.has(util.editableInputs, elem.type) ||
|
||||||
isinstance(elem, [HTMLIsIndexElement, HTMLEmbedElement,
|
isinstance(elem, [HTMLIsIndexElement, HTMLEmbedElement,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/** @instance hints */
|
/** @instance hints */
|
||||||
|
|
||||||
const Hints = Module("hints", {
|
const Hints = Module("hints", {
|
||||||
init: function () {
|
init: function init() {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
this._hintMode = null;
|
this._hintMode = null;
|
||||||
@@ -73,7 +73,7 @@ const Hints = Module("hints", {
|
|||||||
/**
|
/**
|
||||||
* Reset hints, so that they can be cleanly used again.
|
* Reset hints, so that they can be cleanly used again.
|
||||||
*/
|
*/
|
||||||
_reset: function (slight) {
|
_reset: function _reset(slight) {
|
||||||
if (!slight) {
|
if (!slight) {
|
||||||
this.__reset();
|
this.__reset();
|
||||||
this.prevInput = "";
|
this.prevInput = "";
|
||||||
@@ -93,7 +93,7 @@ const Hints = Module("hints", {
|
|||||||
this._activeTimeout.cancel();
|
this._activeTimeout.cancel();
|
||||||
this._activeTimeout = null;
|
this._activeTimeout = null;
|
||||||
},
|
},
|
||||||
__reset: function () {
|
__reset: function __reset() {
|
||||||
if (!this._usedTabKey) {
|
if (!this._usedTabKey) {
|
||||||
this._hintNumber = 0;
|
this._hintNumber = 0;
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ const Hints = Module("hints", {
|
|||||||
/**
|
/**
|
||||||
* Display the current status to the user.
|
* Display the current status to the user.
|
||||||
*/
|
*/
|
||||||
_updateStatusline: function () {
|
_updateStatusline: function _updateStatusline() {
|
||||||
statusline.updateInputBuffer((hints.escNumbers ? options["mapleader"] : "") +
|
statusline.updateInputBuffer((hints.escNumbers ? options["mapleader"] : "") +
|
||||||
(this._hintNumber ? this.getHintString(this._hintNumber) : ""));
|
(this._hintNumber ? this.getHintString(this._hintNumber) : ""));
|
||||||
},
|
},
|
||||||
@@ -128,7 +128,7 @@ const Hints = Module("hints", {
|
|||||||
*
|
*
|
||||||
* @returns [text, showText]
|
* @returns [text, showText]
|
||||||
*/
|
*/
|
||||||
_getInputHint: function (elem, doc) {
|
_getInputHint: function _getInputHint(elem, doc) {
|
||||||
// <input type="submit|button|reset"/> Always use the value
|
// <input type="submit|button|reset"/> Always use the value
|
||||||
// <input type="radio|checkbox"/> Use the value if it is not numeric or label or name
|
// <input type="radio|checkbox"/> Use the value if it is not numeric or label or name
|
||||||
// <input type="password"/> Never use the value, use label or name
|
// <input type="password"/> Never use the value, use label or name
|
||||||
@@ -184,7 +184,7 @@ const Hints = Module("hints", {
|
|||||||
* @param {number} topPos The top offset of the image.
|
* @param {number} topPos The top offset of the image.
|
||||||
* @returns [leftPos, topPos] The updated offsets.
|
* @returns [leftPos, topPos] The updated offsets.
|
||||||
*/
|
*/
|
||||||
_getAreaOffset: function (elem, leftPos, topPos) {
|
_getAreaOffset: function _getAreaOffset(elem, leftPos, topPos) {
|
||||||
try {
|
try {
|
||||||
// Need to add the offset to the area element.
|
// Need to add the offset to the area element.
|
||||||
// Always try to find the top-left point, as per dactyl default.
|
// Always try to find the top-left point, as per dactyl default.
|
||||||
@@ -238,7 +238,7 @@ const Hints = Module("hints", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// the containing block offsets with respect to the viewport
|
// the containing block offsets with respect to the viewport
|
||||||
_getContainerOffsets: function (doc) {
|
_getContainerOffsets: function _getContainerOffsets(doc) {
|
||||||
let body = doc.body || doc.documentElement;
|
let body = doc.body || doc.documentElement;
|
||||||
// TODO: getComputedStyle returns null for Facebook channel_iframe doc - probable Gecko bug.
|
// TODO: getComputedStyle returns null for Facebook channel_iframe doc - probable Gecko bug.
|
||||||
let style = util.computedStyle(body);
|
let style = util.computedStyle(body);
|
||||||
@@ -259,7 +259,7 @@ const Hints = Module("hints", {
|
|||||||
* @param {Window} win The window for which to generate hints.
|
* @param {Window} win The window for which to generate hints.
|
||||||
* @default window.content
|
* @default window.content
|
||||||
*/
|
*/
|
||||||
_generate: function (win) {
|
_generate: function _generate(win) {
|
||||||
if (!win)
|
if (!win)
|
||||||
win = this._top;
|
win = this._top;
|
||||||
|
|
||||||
@@ -327,7 +327,7 @@ const Hints = Module("hints", {
|
|||||||
* @param {number} newId The hint to make active.
|
* @param {number} newId The hint to make active.
|
||||||
* @param {number} oldId The currently active hint.
|
* @param {number} oldId The currently active hint.
|
||||||
*/
|
*/
|
||||||
_showActiveHint: function (newId, oldId) {
|
_showActiveHint: function _showActiveHint(newId, oldId) {
|
||||||
let oldElem = this._validHints[oldId - 1];
|
let oldElem = this._validHints[oldId - 1];
|
||||||
if (oldElem)
|
if (oldElem)
|
||||||
this._setClass(oldElem, false);
|
this._setClass(oldElem, false);
|
||||||
@@ -343,7 +343,7 @@ const Hints = Module("hints", {
|
|||||||
* @param {Object} elem The element to toggle.
|
* @param {Object} elem The element to toggle.
|
||||||
* @param {boolean} active Whether it is the currently active hint or not.
|
* @param {boolean} active Whether it is the currently active hint or not.
|
||||||
*/
|
*/
|
||||||
_setClass: function (elem, active) {
|
_setClass: function _setClass(elem, active) {
|
||||||
let prefix = (elem.getAttributeNS(NS, "class") || "") + " ";
|
let prefix = (elem.getAttributeNS(NS, "class") || "") + " ";
|
||||||
if (active)
|
if (active)
|
||||||
elem.setAttributeNS(NS, "highlight", prefix + "HintActive");
|
elem.setAttributeNS(NS, "highlight", prefix + "HintActive");
|
||||||
@@ -356,7 +356,7 @@ const Hints = Module("hints", {
|
|||||||
/**
|
/**
|
||||||
* Display the hints in pageHints that are still valid.
|
* Display the hints in pageHints that are still valid.
|
||||||
*/
|
*/
|
||||||
_showHints: function () {
|
_showHints: function _showHints() {
|
||||||
let hintnum = 1;
|
let hintnum = 1;
|
||||||
let validHint = this._hintMatcher(this._hintString.toLowerCase());
|
let validHint = this._hintMatcher(this._hintString.toLowerCase());
|
||||||
let activeHint = this._hintNumber || 1;
|
let activeHint = this._hintNumber || 1;
|
||||||
@@ -429,7 +429,7 @@ const Hints = Module("hints", {
|
|||||||
* @param {number} timeout The number of milliseconds before the active
|
* @param {number} timeout The number of milliseconds before the active
|
||||||
* hint disappears.
|
* hint disappears.
|
||||||
*/
|
*/
|
||||||
_removeHints: function (timeout, slight) {
|
_removeHints: function _removeHints(timeout, slight) {
|
||||||
for (let [,{ doc: doc, start: start, end: end }] in Iterator(this._docs)) {
|
for (let [,{ doc: doc, start: start, end: end }] in Iterator(this._docs)) {
|
||||||
for (let elem in util.evaluateXPath("//*[@dactyl:highlight='hints']", doc))
|
for (let elem in util.evaluateXPath("//*[@dactyl:highlight='hints']", doc))
|
||||||
elem.parentNode.removeChild(elem);
|
elem.parentNode.removeChild(elem);
|
||||||
@@ -451,7 +451,7 @@ const Hints = Module("hints", {
|
|||||||
* link (when 'followhints' is 1 or 2)
|
* link (when 'followhints' is 1 or 2)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
_processHints: function (followFirst) {
|
_processHints: function _processHints(followFirst) {
|
||||||
if (this._validHints.length == 0) {
|
if (this._validHints.length == 0) {
|
||||||
dactyl.beep();
|
dactyl.beep();
|
||||||
return false;
|
return false;
|
||||||
@@ -507,7 +507,7 @@ const Hints = Module("hints", {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
_checkUnique: function () {
|
_checkUnique: function _checkUnique() {
|
||||||
if (this._hintNumber == 0)
|
if (this._hintNumber == 0)
|
||||||
return;
|
return;
|
||||||
dactyl.assert(this._hintNumber <= this._validHints.length);
|
dactyl.assert(this._hintNumber <= this._validHints.length);
|
||||||
@@ -533,7 +533,7 @@ const Hints = Module("hints", {
|
|||||||
*
|
*
|
||||||
* @param {Event} event The keypress event.
|
* @param {Event} event The keypress event.
|
||||||
*/
|
*/
|
||||||
_onInput: function (event) {
|
_onInput: function _onInput(event) {
|
||||||
this.prevInput = "text";
|
this.prevInput = "text";
|
||||||
|
|
||||||
// clear any timeout which might be active after pressing a number
|
// clear any timeout which might be active after pressing a number
|
||||||
@@ -556,7 +556,7 @@ const Hints = Module("hints", {
|
|||||||
* @param {string} hintString The currently typed hint.
|
* @param {string} hintString The currently typed hint.
|
||||||
* @returns {hintMatcher}
|
* @returns {hintMatcher}
|
||||||
*/
|
*/
|
||||||
_hintMatcher: function (hintString) { //{{{
|
_hintMatcher: function _hintMatcher(hintString) { //{{{
|
||||||
/**
|
/**
|
||||||
* Divide a string by a regular expression.
|
* Divide a string by a regular expression.
|
||||||
*
|
*
|
||||||
@@ -745,7 +745,7 @@ const Hints = Module("hints", {
|
|||||||
* @param {number} n The number to transform.
|
* @param {number} n The number to transform.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
getHintString: function (n) {
|
getHintString: function getHintString(n) {
|
||||||
let res = [], len = this.hintKeys.length;
|
let res = [], len = this.hintKeys.length;
|
||||||
do {
|
do {
|
||||||
res.push(this.hintKeys[n % len]);
|
res.push(this.hintKeys[n % len]);
|
||||||
@@ -762,9 +762,9 @@ const Hints = Module("hints", {
|
|||||||
* @param {string} key The key to test.
|
* @param {string} key The key to test.
|
||||||
* @returns {boolean} Whether the key represents a hint number.
|
* @returns {boolean} Whether the key represents a hint number.
|
||||||
*/
|
*/
|
||||||
isHintKey: function (key) this.hintKeys.indexOf(key) >= 0,
|
isHintKey: function isHintKey(key) this.hintKeys.indexOf(key) >= 0,
|
||||||
|
|
||||||
open: function (mode, opts) {
|
open: function open(mode, opts) {
|
||||||
this._extendedhintCount = opts.count;
|
this._extendedhintCount = opts.count;
|
||||||
commandline.input(";", null, {
|
commandline.input(";", null, {
|
||||||
promptHighlight: "Normal",
|
promptHighlight: "Normal",
|
||||||
@@ -784,7 +784,7 @@ const Hints = Module("hints", {
|
|||||||
* @param {string} minor Which hint mode to use.
|
* @param {string} minor Which hint mode to use.
|
||||||
* @param {Object} opts Extra options.
|
* @param {Object} opts Extra options.
|
||||||
*/
|
*/
|
||||||
show: function (minor, opts) {
|
show: function show(minor, opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
this._hintMode = this._hintModes[minor];
|
this._hintMode = this._hintModes[minor];
|
||||||
dactyl.assert(this._hintMode);
|
dactyl.assert(this._hintMode);
|
||||||
@@ -833,7 +833,7 @@ const Hints = Module("hints", {
|
|||||||
/**
|
/**
|
||||||
* Cancel all hinting.
|
* Cancel all hinting.
|
||||||
*/
|
*/
|
||||||
hide: function () {
|
hide: function hide() {
|
||||||
if (this._top)
|
if (this._top)
|
||||||
this._top.removeEventListener("resize", this._resizeTimer.closure.tell, true);
|
this._top.removeEventListener("resize", this._resizeTimer.closure.tell, true);
|
||||||
this._top = null;
|
this._top = null;
|
||||||
@@ -846,7 +846,7 @@ const Hints = Module("hints", {
|
|||||||
*
|
*
|
||||||
* @param {Event} event The event to handle.
|
* @param {Event} event The event to handle.
|
||||||
*/
|
*/
|
||||||
onEvent: function (event) {
|
onEvent: function onEvent(event) {
|
||||||
let key = events.toString(event);
|
let key = events.toString(event);
|
||||||
let followFirst = false;
|
let followFirst = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user