Skip to content

Commit

Permalink
📝 [docs] Simplify leader key example conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-liu committed Feb 14, 2025
1 parent 5500fac commit 5456bb0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions examples/vim/nested-leader-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Nested leader key

To nest leader keys, use a variables:

- Set the variable on the leader key
- Set the variable to different value on each nested leader key
- Set the variable on the leader key (Default value 1; 0 when unset)
- Set the variable to different value on each nested leader key (other than 1 or 0)
- Unset the variable on all action keys and escape key(s)
- (optional) Use notification for hints
53 changes: 27 additions & 26 deletions examples/vim/nested-leader-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,37 @@ let escape = [toUnsetVar('leader'), toRemoveNotificationMessage('leader')]

let rules = [
rule('Leader Key').manipulators([
// Leader key
map('l', 'Hyper') // Or mapSimultaneous(['l', ';']) ...
.toVar('leader')
.toNotificationMessage('leader', 'Leader Key: Open, Raycast, ...'),
.toVar('leader', 1)
.toNotificationMessage('leader', 'Leader Key: Open, Raycast, ...')
.condition(ifVar('leader', 0)),

withCondition(ifVar('leader', 0).unless())([
// Escape key(s)
map('escape').to(escape),
// Escape key(s)
map('escape').to(escape).condition(ifVar('leader', 0).unless()),

// Nested leader keys
withMapper(['o', 'r'])((x) =>
map(x)
.toVar('leader', x)
.toNotificationMessage('leader', `leader ${x}`),
),
// Nested leader keys
withMapper(['o', 'r'])((x) =>
map(x)
.toVar('leader', x)
.toNotificationMessage('leader', `leader ${x}`)
.condition(ifVar('leader', 1)),
),

// o - Open
withCondition(ifVar('leader', 'o'))(
[
map('f').toApp('Finder'),
// f - Finder, ...
].map((x) => x.to(escape)),
),
// leader o - Open
withCondition(ifVar('leader', 'o'))(
[
map('f').toApp('Finder'),
// f - Finder, ...
].map((x) => x.to(escape)),
),

// r - Raycast
withCondition(ifVar('leader', 'r'))(
[
map('e').to$(`open raycast://extensions/${raycastEmoji}`),
// e - Emoji, ...
].map((x) => x.to(escape)),
),
]),
// leader r - Raycast
withCondition(ifVar('leader', 'r'))(
[
map('e').to$(`open raycast://extensions/${raycastEmoji}`),
// e - Emoji, ...
].map((x) => x.to(escape)),
),
]),
]

0 comments on commit 5456bb0

Please sign in to comment.