mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -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
|
- -c [selector] hint links that match the css selector
|
||||||
- `bind ;c hint -c [class*="expand"],[class*="togg"]` works particularly well on reddit and HN
|
- `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]`
|
- 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
|
- -x [selector] exclude the matched elements from hinting
|
||||||
- -f [text] hint links and inputs that display the given text
|
- -f [text] hint links and inputs that display the given text
|
||||||
- `bind <c-e> hint -f Edit`
|
- `bind <c-e> hint -f Edit`
|
||||||
|
|
|
@ -66,6 +66,7 @@ export class HintConfig implements HintOptions {
|
||||||
public pipeAttribute = null
|
public pipeAttribute = null
|
||||||
public selectors = []
|
public selectors = []
|
||||||
public selectorsExclude = []
|
public selectorsExclude = []
|
||||||
|
public includeDefaultHintables = true
|
||||||
public warnings = []
|
public warnings = []
|
||||||
|
|
||||||
public static parse(args: string[]): HintConfig {
|
public static parse(args: string[]): HintConfig {
|
||||||
|
@ -85,6 +86,8 @@ export class HintConfig implements HintOptions {
|
||||||
|
|
||||||
const result = new HintConfig()
|
const result = new HintConfig()
|
||||||
const multiLetterFlags = ["fr", "wp", "br", "pipe"]
|
const multiLetterFlags = ["fr", "wp", "br", "pipe"]
|
||||||
|
let cFlagPresent = false
|
||||||
|
let CFlagPresent = false
|
||||||
|
|
||||||
// Parser state
|
// Parser state
|
||||||
let state = State.Initial
|
let state = State.Initial
|
||||||
|
@ -151,6 +154,13 @@ export class HintConfig implements HintOptions {
|
||||||
newState = State.ExpectExcmd
|
newState = State.ExpectExcmd
|
||||||
break
|
break
|
||||||
case "c":
|
case "c":
|
||||||
|
cFlagPresent = true
|
||||||
|
result.includeDefaultHintables = false
|
||||||
|
newState = State.ExpectSelector
|
||||||
|
break
|
||||||
|
case "C":
|
||||||
|
CFlagPresent = true
|
||||||
|
result.includeDefaultHintables = true
|
||||||
newState = State.ExpectSelector
|
newState = State.ExpectSelector
|
||||||
break
|
break
|
||||||
case "x":
|
case "x":
|
||||||
|
@ -238,6 +248,14 @@ export class HintConfig implements HintOptions {
|
||||||
result.openMode = newOpenMode
|
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
|
// Check state changes
|
||||||
if (newState !== undefined) {
|
if (newState !== undefined) {
|
||||||
// Some state transitions are dubious, specifically all the ones that go from (argument
|
// Some state transitions are dubious, specifically all the ones that go from (argument
|
||||||
|
@ -402,16 +420,14 @@ export class HintConfig implements HintOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public hintables() {
|
public hintables() {
|
||||||
// User selectors always override default built-ins
|
let hintables = this.includeDefaultHintables ? this.defaultHintables() : []
|
||||||
const hintables =
|
if (this.selectors.length > 0) {
|
||||||
this.selectors.length > 0
|
hintables = hintables.concat(hinting.hintables(
|
||||||
? hinting.hintables(
|
|
||||||
this.selectors.join(" "),
|
this.selectors.join(" "),
|
||||||
this.jshints,
|
this.jshints,
|
||||||
this.includeInvisible,
|
this.includeInvisible,
|
||||||
)
|
))
|
||||||
: this.defaultHintables()
|
}
|
||||||
|
|
||||||
const textFilter = this.textFilter
|
const textFilter = this.textFilter
|
||||||
const exclude = this.selectorsExclude.join(" ")
|
const exclude = this.selectorsExclude.join(" ")
|
||||||
for (const elements of hintables) {
|
for (const elements of hintables) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue