mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
Fix -pipe should combine with other flags
This commit is contained in:
parent
1be771e6c1
commit
03e2f9f470
2 changed files with 25 additions and 15 deletions
|
@ -141,6 +141,15 @@ const testCases = [
|
|||
warnings: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
sources: ["-qpipe a href"],
|
||||
expected: {
|
||||
rapid: true,
|
||||
pipeAttribute: "href",
|
||||
selectors: ["a"],
|
||||
warnings: [],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
// Check all test cases
|
||||
|
|
|
@ -81,7 +81,7 @@ export class HintConfig implements HintOptions {
|
|||
}
|
||||
|
||||
const result = new HintConfig()
|
||||
const twoLetterFlags = ["fr", "wp", "br"]
|
||||
const multiLetterFlags = ["fr", "wp", "br", "pipe"]
|
||||
|
||||
// Parser state
|
||||
let state = State.Initial
|
||||
|
@ -91,34 +91,32 @@ export class HintConfig implements HintOptions {
|
|||
|
||||
switch (state) {
|
||||
case State.Initial:
|
||||
if (arg == "-pipe") {
|
||||
// Special case for -pipe, which is not a |1,2]-letter argument
|
||||
state = State.ExpectPipeSelector
|
||||
} else if (
|
||||
arg.length >= 2 &&
|
||||
arg[0] === "-" &&
|
||||
arg[1] !== "-"
|
||||
) {
|
||||
if (arg.length >= 2 && arg[0] === "-" && arg[1] !== "-") {
|
||||
// Parse short arguments, i.e. - followed by (mostly) single-letter arguments,
|
||||
// and some two-letter arguments.
|
||||
|
||||
for (let i = 1; i < arg.length; ++i) {
|
||||
const letter = arg[i]
|
||||
let flag = letter
|
||||
let flag = arg[i]
|
||||
|
||||
// Fix two-letter flags using lookahead
|
||||
if (i < arg.length - 1) {
|
||||
const twoLetterFlag = letter + arg[i + 1]
|
||||
const multiLetterFlag = multiLetterFlags.find(
|
||||
tlf =>
|
||||
arg.substring(i, i + tlf.length) ===
|
||||
tlf,
|
||||
)
|
||||
|
||||
if (twoLetterFlags.includes(twoLetterFlag)) {
|
||||
flag = twoLetterFlag
|
||||
i++
|
||||
if (multiLetterFlag !== undefined) {
|
||||
flag = multiLetterFlag
|
||||
i += multiLetterFlag.length - 1
|
||||
}
|
||||
}
|
||||
|
||||
// Process flag
|
||||
let newOpenMode: undefined | OpenMode
|
||||
let newState: undefined | State
|
||||
|
||||
// eslint-disable-next-line sonarjs/max-switch-cases
|
||||
switch (flag) {
|
||||
case "br":
|
||||
// Equivalent to -qb, but deprecated
|
||||
|
@ -152,6 +150,9 @@ export class HintConfig implements HintOptions {
|
|||
case "c":
|
||||
newState = State.ExpectSelector
|
||||
break
|
||||
case "pipe":
|
||||
newState = State.ExpectPipeSelector
|
||||
break
|
||||
case "t":
|
||||
newOpenMode = OpenMode.Tab
|
||||
break
|
||||
|
|
Loading…
Add table
Reference in a new issue