-
Notifications
You must be signed in to change notification settings - Fork 0
/
performJump.js
55 lines (45 loc) · 1.34 KB
/
performJump.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import * as P from 'process'
const jumpLabels =
JSON.parse(P.env.kak_opt_jumpLabelsPositions)
const targetLabel =
jumpLabels.find(label => label.label === P.env.kak_text)
// This case is not a failure, it simply means that either not all of the characters of the label
// have yet been entered, or there was a typo and the user could correct themselves, so we
// just wait for a matching label.
if (targetLabel === undefined)
P.exit()
const onDiscard =
`
execute-keys <esc>
select -display-column ${ targetLabel.selectionDescription }
execute-keys <semicolon>he
`
const onAdd =
`
execute-keys <esc>
eval -draft %{
select -display-column ${ targetLabel.selectionDescription }
exec <a-i>w
set window jumpAddSelectionDesc %val{selection_desc}
}
select %opt{jumpAddSelectionDesc} %val{selections_desc}
unset window jumpAddSelectionDesc
`
const onExtend =
`
execute-keys <esc>
select -display-column ${ targetLabel.selectionDescription }
${ targetLabel.jumpOrientationForward ? 'execute-keys HE' : '' }
`
const onUnrecognized =
`
execute-keys <esc>
fail "jumpJump: unrecognized switch '${ P.env.jumpMode }'"
`
const jumpModeMap =
{ '': onDiscard
, '-discard': onDiscard
, '-add': onAdd
, '-extend': onExtend
}
console.log(jumpModeMap[P.env.jumpMode] || onUnrecognized)