mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 17:47:59 +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.itemList = commandline._completionList;
|
||||
this.itemList.setItems(this.context);
|
||||
this.reset();
|
||||
},
|
||||
|
||||
UP: {},
|
||||
@@ -1901,9 +1900,10 @@ const ItemList = Class("ItemList", {
|
||||
show: function show() { this._container.collapsed = false; },
|
||||
visible: function visible() !this._container.collapsed,
|
||||
|
||||
reset: function () {
|
||||
reset: function (brief) {
|
||||
this._startIndex = this._endIndex = this._selIndex = -1;
|
||||
this._div = null;
|
||||
if (!brief)
|
||||
this.selectItem(-1);
|
||||
},
|
||||
|
||||
@@ -1915,7 +1915,7 @@ const ItemList = Class("ItemList", {
|
||||
this._minHeight = 0;
|
||||
this._startIndex = this._endIndex = this._selIndex = -1;
|
||||
this._items = newItems;
|
||||
this.reset();
|
||||
this.reset(true);
|
||||
if (typeof selectedItem == "number") {
|
||||
this.selectItem(selectedItem);
|
||||
this.show();
|
||||
|
||||
@@ -952,7 +952,7 @@ const Dactyl = Module("dactyl", {
|
||||
* @param {function} func The function to call
|
||||
* @param {object} self The 'this' object for the function.
|
||||
*/
|
||||
trapErrors: function (func, self) {
|
||||
trapErrors: function trapErrors(func, self) {
|
||||
try {
|
||||
return func.apply(self || this, Array.slice(arguments, 2));
|
||||
}
|
||||
@@ -968,7 +968,7 @@ const Dactyl = Module("dactyl", {
|
||||
*
|
||||
* @param {Object} error The error object.
|
||||
*/
|
||||
reportError: function (error, echo) {
|
||||
reportError: function reportError(error, echo) {
|
||||
if (error instanceof FailedAssertion) {
|
||||
if (error.message)
|
||||
dactyl.echoerr(error.message);
|
||||
|
||||
@@ -115,7 +115,7 @@ const Events = Module("events", {
|
||||
*/
|
||||
wrapListener: function wrapListener(method, self) {
|
||||
self = self || this;
|
||||
return function (event) {
|
||||
return function wrappedListener(event) {
|
||||
try {
|
||||
method.apply(self, arguments);
|
||||
}
|
||||
@@ -447,7 +447,7 @@ const Events = Module("events", {
|
||||
* @param {Event} event
|
||||
* @returns {string}
|
||||
*/
|
||||
toString: function (event) {
|
||||
toString: function toString(event) {
|
||||
if (!event)
|
||||
return "[instance events]";
|
||||
|
||||
@@ -660,7 +660,7 @@ const Events = Module("events", {
|
||||
},
|
||||
|
||||
// TODO: Merge with onFocusChange
|
||||
onFocus: function (event) {
|
||||
onFocus: function onFocus(event) {
|
||||
let elem = event.originalTarget;
|
||||
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
|
||||
// access to the real focus target
|
||||
// Huh? --djk
|
||||
onFocusChange: function (event) {
|
||||
onFocusChange: function onFocusChange(event) {
|
||||
// command line has it's own focus change handler
|
||||
if (dactyl.mode == modes.COMMAND_LINE)
|
||||
return;
|
||||
@@ -737,7 +737,7 @@ const Events = Module("events", {
|
||||
// this keypress handler gets always called first, even if e.g.
|
||||
// the commandline has focus
|
||||
// TODO: ...help me...please...
|
||||
onKeyPress: function (event) {
|
||||
onKeyPress: function onKeyPress(event) {
|
||||
function isEscape(key) key == "<Esc>" || key == "<C-[>";
|
||||
|
||||
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
|
||||
onKeyUpOrDown: function (event) {
|
||||
onKeyUpOrDown: function onKeyUpOrDown(event) {
|
||||
if (!Events.isInputElemFocused() && !modes.passThrough)
|
||||
event.stopPropagation();
|
||||
},
|
||||
|
||||
onMouseDown: function (event) {
|
||||
onMouseDown: function onMouseDown(event) {
|
||||
let elem = event.target;
|
||||
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
|
||||
for (; win; win = win != win.parent && win.parent)
|
||||
win.dactylFocusAllowed = true;
|
||||
},
|
||||
|
||||
onPopupShown: function (event) {
|
||||
onPopupShown: function onPopupShown(event) {
|
||||
if (event.originalTarget.localName == "tooltip" || event.originalTarget.id == "dactyl-visualbell")
|
||||
return;
|
||||
modes.add(modes.MENU);
|
||||
},
|
||||
|
||||
onPopupHidden: function () {
|
||||
onPopupHidden: function onPopupHidden() {
|
||||
// gContextMenu is set to NULL, when a context menu is closed
|
||||
if (window.gContextMenu == null && !this._activeMenubar)
|
||||
modes.remove(modes.MENU);
|
||||
},
|
||||
|
||||
onResize: function (event) {
|
||||
onResize: function onResize(event) {
|
||||
if (window.fullScreen != this._fullscreen) {
|
||||
this._fullscreen = window.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 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;
|
||||
for (; win; win = win.parent != win && win.parent)
|
||||
if (win == window.content)
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
isInputElemFocused: function () {
|
||||
isInputElemFocused: function isInputElemFocused() {
|
||||
let elem = dactyl.focus;
|
||||
return elem instanceof HTMLInputElement && set.has(util.editableInputs, elem.type) ||
|
||||
isinstance(elem, [HTMLIsIndexElement, HTMLEmbedElement,
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/** @instance hints */
|
||||
|
||||
const Hints = Module("hints", {
|
||||
init: function () {
|
||||
init: function init() {
|
||||
const self = this;
|
||||
|
||||
this._hintMode = null;
|
||||
@@ -73,7 +73,7 @@ const Hints = Module("hints", {
|
||||
/**
|
||||
* Reset hints, so that they can be cleanly used again.
|
||||
*/
|
||||
_reset: function (slight) {
|
||||
_reset: function _reset(slight) {
|
||||
if (!slight) {
|
||||
this.__reset();
|
||||
this.prevInput = "";
|
||||
@@ -93,7 +93,7 @@ const Hints = Module("hints", {
|
||||
this._activeTimeout.cancel();
|
||||
this._activeTimeout = null;
|
||||
},
|
||||
__reset: function () {
|
||||
__reset: function __reset() {
|
||||
if (!this._usedTabKey) {
|
||||
this._hintNumber = 0;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ const Hints = Module("hints", {
|
||||
/**
|
||||
* Display the current status to the user.
|
||||
*/
|
||||
_updateStatusline: function () {
|
||||
_updateStatusline: function _updateStatusline() {
|
||||
statusline.updateInputBuffer((hints.escNumbers ? options["mapleader"] : "") +
|
||||
(this._hintNumber ? this.getHintString(this._hintNumber) : ""));
|
||||
},
|
||||
@@ -128,7 +128,7 @@ const Hints = Module("hints", {
|
||||
*
|
||||
* @returns [text, showText]
|
||||
*/
|
||||
_getInputHint: function (elem, doc) {
|
||||
_getInputHint: function _getInputHint(elem, doc) {
|
||||
// <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="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.
|
||||
* @returns [leftPos, topPos] The updated offsets.
|
||||
*/
|
||||
_getAreaOffset: function (elem, leftPos, topPos) {
|
||||
_getAreaOffset: function _getAreaOffset(elem, leftPos, topPos) {
|
||||
try {
|
||||
// Need to add the offset to the area element.
|
||||
// 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
|
||||
_getContainerOffsets: function (doc) {
|
||||
_getContainerOffsets: function _getContainerOffsets(doc) {
|
||||
let body = doc.body || doc.documentElement;
|
||||
// TODO: getComputedStyle returns null for Facebook channel_iframe doc - probable Gecko bug.
|
||||
let style = util.computedStyle(body);
|
||||
@@ -259,7 +259,7 @@ const Hints = Module("hints", {
|
||||
* @param {Window} win The window for which to generate hints.
|
||||
* @default window.content
|
||||
*/
|
||||
_generate: function (win) {
|
||||
_generate: function _generate(win) {
|
||||
if (!win)
|
||||
win = this._top;
|
||||
|
||||
@@ -327,7 +327,7 @@ const Hints = Module("hints", {
|
||||
* @param {number} newId The hint to make active.
|
||||
* @param {number} oldId The currently active hint.
|
||||
*/
|
||||
_showActiveHint: function (newId, oldId) {
|
||||
_showActiveHint: function _showActiveHint(newId, oldId) {
|
||||
let oldElem = this._validHints[oldId - 1];
|
||||
if (oldElem)
|
||||
this._setClass(oldElem, false);
|
||||
@@ -343,7 +343,7 @@ const Hints = Module("hints", {
|
||||
* @param {Object} elem The element to toggle.
|
||||
* @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") || "") + " ";
|
||||
if (active)
|
||||
elem.setAttributeNS(NS, "highlight", prefix + "HintActive");
|
||||
@@ -356,7 +356,7 @@ const Hints = Module("hints", {
|
||||
/**
|
||||
* Display the hints in pageHints that are still valid.
|
||||
*/
|
||||
_showHints: function () {
|
||||
_showHints: function _showHints() {
|
||||
let hintnum = 1;
|
||||
let validHint = this._hintMatcher(this._hintString.toLowerCase());
|
||||
let activeHint = this._hintNumber || 1;
|
||||
@@ -429,7 +429,7 @@ const Hints = Module("hints", {
|
||||
* @param {number} timeout The number of milliseconds before the active
|
||||
* 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 elem in util.evaluateXPath("//*[@dactyl:highlight='hints']", doc))
|
||||
elem.parentNode.removeChild(elem);
|
||||
@@ -451,7 +451,7 @@ const Hints = Module("hints", {
|
||||
* link (when 'followhints' is 1 or 2)
|
||||
*
|
||||
*/
|
||||
_processHints: function (followFirst) {
|
||||
_processHints: function _processHints(followFirst) {
|
||||
if (this._validHints.length == 0) {
|
||||
dactyl.beep();
|
||||
return false;
|
||||
@@ -507,7 +507,7 @@ const Hints = Module("hints", {
|
||||
return true;
|
||||
},
|
||||
|
||||
_checkUnique: function () {
|
||||
_checkUnique: function _checkUnique() {
|
||||
if (this._hintNumber == 0)
|
||||
return;
|
||||
dactyl.assert(this._hintNumber <= this._validHints.length);
|
||||
@@ -533,7 +533,7 @@ const Hints = Module("hints", {
|
||||
*
|
||||
* @param {Event} event The keypress event.
|
||||
*/
|
||||
_onInput: function (event) {
|
||||
_onInput: function _onInput(event) {
|
||||
this.prevInput = "text";
|
||||
|
||||
// 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.
|
||||
* @returns {hintMatcher}
|
||||
*/
|
||||
_hintMatcher: function (hintString) { //{{{
|
||||
_hintMatcher: function _hintMatcher(hintString) { //{{{
|
||||
/**
|
||||
* Divide a string by a regular expression.
|
||||
*
|
||||
@@ -745,7 +745,7 @@ const Hints = Module("hints", {
|
||||
* @param {number} n The number to transform.
|
||||
* @returns {string}
|
||||
*/
|
||||
getHintString: function (n) {
|
||||
getHintString: function getHintString(n) {
|
||||
let res = [], len = this.hintKeys.length;
|
||||
do {
|
||||
res.push(this.hintKeys[n % len]);
|
||||
@@ -762,9 +762,9 @@ const Hints = Module("hints", {
|
||||
* @param {string} key The key to test.
|
||||
* @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;
|
||||
commandline.input(";", null, {
|
||||
promptHighlight: "Normal",
|
||||
@@ -784,7 +784,7 @@ const Hints = Module("hints", {
|
||||
* @param {string} minor Which hint mode to use.
|
||||
* @param {Object} opts Extra options.
|
||||
*/
|
||||
show: function (minor, opts) {
|
||||
show: function show(minor, opts) {
|
||||
opts = opts || {};
|
||||
this._hintMode = this._hintModes[minor];
|
||||
dactyl.assert(this._hintMode);
|
||||
@@ -833,7 +833,7 @@ const Hints = Module("hints", {
|
||||
/**
|
||||
* Cancel all hinting.
|
||||
*/
|
||||
hide: function () {
|
||||
hide: function hide() {
|
||||
if (this._top)
|
||||
this._top.removeEventListener("resize", this._resizeTimer.closure.tell, true);
|
||||
this._top = null;
|
||||
@@ -846,7 +846,7 @@ const Hints = Module("hints", {
|
||||
*
|
||||
* @param {Event} event The event to handle.
|
||||
*/
|
||||
onEvent: function (event) {
|
||||
onEvent: function onEvent(event) {
|
||||
let key = events.toString(event);
|
||||
let followFirst = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user