mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 17:11:40 -05:00
Merge pull request #4781 from petoncle/keep-default-hints
Add hint flag for specifying a selector that also keeps default hints
This commit is contained in:
commit
1da778ba56
2 changed files with 27 additions and 10 deletions
|
@ -5125,6 +5125,7 @@ const KILL_STACK: Element[] = []
|
|||
- -c [selector] hint links that match the css selector
|
||||
- `bind ;c hint -c [class*="expand"],[class*="togg"]` works particularly well on reddit and HN
|
||||
- this works with most other hint modes, with the caveat that if other hint mode takes arguments your selector must contain no spaces, i.e. `hint -c[yourOtherFlag] [selector] [your other flag's arguments, which may contain spaces]`
|
||||
- -C [selector] like `-c [selector]` but also hints all elements that would normally be hinted given the other options selected
|
||||
- -x [selector] exclude the matched elements from hinting
|
||||
- -f [text] hint links and inputs that display the given text
|
||||
- `bind <c-e> hint -f Edit`
|
||||
|
|
|
@ -66,6 +66,7 @@ export class HintConfig implements HintOptions {
|
|||
public pipeAttribute = null
|
||||
public selectors = []
|
||||
public selectorsExclude = []
|
||||
public includeDefaultHintables = true
|
||||
public warnings = []
|
||||
|
||||
public static parse(args: string[]): HintConfig {
|
||||
|
@ -85,6 +86,8 @@ export class HintConfig implements HintOptions {
|
|||
|
||||
const result = new HintConfig()
|
||||
const multiLetterFlags = ["fr", "wp", "br", "pipe"]
|
||||
let cFlagPresent = false
|
||||
let CFlagPresent = false
|
||||
|
||||
// Parser state
|
||||
let state = State.Initial
|
||||
|
@ -151,6 +154,13 @@ export class HintConfig implements HintOptions {
|
|||
newState = State.ExpectExcmd
|
||||
break
|
||||
case "c":
|
||||
cFlagPresent = true
|
||||
result.includeDefaultHintables = false
|
||||
newState = State.ExpectSelector
|
||||
break
|
||||
case "C":
|
||||
CFlagPresent = true
|
||||
result.includeDefaultHintables = true
|
||||
newState = State.ExpectSelector
|
||||
break
|
||||
case "x":
|
||||
|
@ -238,6 +248,14 @@ export class HintConfig implements HintOptions {
|
|||
result.openMode = newOpenMode
|
||||
}
|
||||
|
||||
if (cFlagPresent && CFlagPresent) {
|
||||
result.warnings.push(
|
||||
"mutually exclusive -c and -C flags are both specified, last wins, " +
|
||||
"default hints will " +
|
||||
(result.includeDefaultHintables ? "be" : "not be") + " included",
|
||||
)
|
||||
}
|
||||
|
||||
// Check state changes
|
||||
if (newState !== undefined) {
|
||||
// Some state transitions are dubious, specifically all the ones that go from (argument
|
||||
|
@ -402,16 +420,14 @@ export class HintConfig implements HintOptions {
|
|||
}
|
||||
|
||||
public hintables() {
|
||||
// User selectors always override default built-ins
|
||||
const hintables =
|
||||
this.selectors.length > 0
|
||||
? hinting.hintables(
|
||||
let hintables = this.includeDefaultHintables ? this.defaultHintables() : []
|
||||
if (this.selectors.length > 0) {
|
||||
hintables = hintables.concat(hinting.hintables(
|
||||
this.selectors.join(" "),
|
||||
this.jshints,
|
||||
this.includeInvisible,
|
||||
)
|
||||
: this.defaultHintables()
|
||||
|
||||
))
|
||||
}
|
||||
const textFilter = this.textFilter
|
||||
const exclude = this.selectorsExclude.join(" ")
|
||||
for (const elements of hintables) {
|
||||
|
|
Loading…
Add table
Reference in a new issue