mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
Make always select single hint
Previously even if there was only one hit left it was subject to 'shouldSelect' and 'different' screening.
This commit is contained in:
parent
b7db91c95d
commit
966e0d0db4
1 changed files with 45 additions and 28 deletions
|
@ -263,37 +263,53 @@ export function hintPage(
|
|||
})
|
||||
}
|
||||
|
||||
if (modeState.hints.length) {
|
||||
if (! modeState.hints.length) {
|
||||
// No more hints to display
|
||||
reset()
|
||||
return
|
||||
}
|
||||
|
||||
// There are multiple hints. Normally we would just show all of them, but
|
||||
// we try to be clever here. Automatically select the first one if all the
|
||||
// conditions are true:
|
||||
// - it is <a>
|
||||
// - its href is not empty (does not point to the page itself)
|
||||
// - its href is not javascript
|
||||
// - all the remaining hints
|
||||
// - are either _not_ <a>
|
||||
// - or their href points to the sampe place as first one
|
||||
|
||||
const firstTarget = modeState.hints[0].target
|
||||
const shouldSelect =
|
||||
firstTarget instanceof HTMLAnchorElement &&
|
||||
|
||||
const firstTargetIsSelectable = (): boolean => {
|
||||
return firstTarget instanceof HTMLAnchorElement &&
|
||||
firstTarget.href !== "" &&
|
||||
!firstTarget.href.startsWith("javascript:")
|
||||
if (shouldSelect) {
|
||||
// Try to find an element that is not a link or that doesn't point
|
||||
// to the same URL as the first hint
|
||||
const different = modeState.hints.find(h => {
|
||||
}
|
||||
|
||||
const allTargetsAreEqual = (): boolean => {
|
||||
return undefined === modeState.hints.find(h => {
|
||||
return (
|
||||
!(h.target instanceof HTMLAnchorElement) ||
|
||||
h.target.href !== (firstTarget as HTMLAnchorElement).href
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
if (different === undefined) {
|
||||
if (modeState.hints.length == 1 ||
|
||||
(firstTargetIsSelectable() && allTargetsAreEqual())) {
|
||||
// There is just a single link or all the links point to the same
|
||||
// place. Select it.
|
||||
modeState.cleanUpHints()
|
||||
modeState.hints[0].select()
|
||||
reset()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("hints", modeState.hints)
|
||||
// Just focus first link
|
||||
modeState.focusedHint = modeState.hints[0]
|
||||
modeState.focusedHint.focused = true
|
||||
document.documentElement.appendChild(modeState.hintHost)
|
||||
} else {
|
||||
reset()
|
||||
}
|
||||
}
|
||||
|
||||
function defaultHintBuilder() {
|
||||
|
@ -695,6 +711,7 @@ export function hintByText(match) {
|
|||
hint => {
|
||||
let text
|
||||
if (hint instanceof HTMLInputElement) {
|
||||
// tslint:disable-next-line:no-useless-cast
|
||||
text = (hint as HTMLInputElement).value
|
||||
} else {
|
||||
text = hint.textContent
|
||||
|
|
Loading…
Add table
Reference in a new issue