Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix leader mode on layers #154

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/config/layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,16 @@ describe('layer() leader mode', () => {

const ifOn = ifVar('layer-a', 1).build()
const toOff = toSetVar('layer-a', 0)
const toLayerVarOff = toSetVar('__layer', 0)
// layer keys
expect(manipulators[1].to?.[1]).toEqual(toOff)
expect(manipulators[2].to?.[1]).toEqual(toOff)
expect(manipulators[1].to?.slice(1)).toEqual([toOff, toLayerVarOff])
expect(manipulators[2].to?.slice(1)).toEqual([toOff, toLayerVarOff])
// escape keys
expect(manipulators[3].from).toEqual({ key_code: 'escape' })
expect(manipulators[3].to?.[0]).toEqual(toOff)
expect(manipulators[3].to).toEqual([toOff, toLayerVarOff])
expect(manipulators[3].conditions).toEqual([ifOn])
expect(manipulators[4].from).toEqual({ key_code: 'caps_lock' })
expect(manipulators[4].to?.[0]).toEqual(toOff)
expect(manipulators[4].to).toEqual([toOff, toLayerVarOff])
expect(manipulators[4].conditions).toEqual([ifOn])
})

Expand Down Expand Up @@ -411,10 +412,10 @@ describe('layer() leader mode', () => {

const remove = toRemoveNotificationMessage('layer-v')
// layer key
expect(manipulators[1].to?.[2]).toEqual(remove)
expect(manipulators[1].to?.[3]).toEqual(remove)
// escape keys
expect(manipulators[2].to?.[1]).toEqual(remove)
expect(manipulators[3].to?.[1]).toEqual(remove)
expect(manipulators[2].to?.[2]).toEqual(remove)
expect(manipulators[3].to?.[2]).toEqual(remove)

const rule2 = layer('b').notification('Test B').build()
const manipulators2 = rule2.manipulators as BasicManipulator[]
Expand All @@ -434,17 +435,16 @@ describe('layer() leader mode', () => {

const ifOn = ifVar('layer-a', 1).build()
const toOff = toSetVar('layer-a', 0)
const toLayerVarOff = toSetVar('__layer', 0)
const remove = toRemoveNotificationMessage('layer-layer-a')

// layer key
expect(manipulators[1].to?.length).toEqual(1)
expect(manipulators[1].conditions).toEqual([ifOn])
// escape keys
expect(manipulators[2].conditions).toEqual([ifOn])
expect(manipulators[2].to?.[0]).toEqual(toOff)
expect(manipulators[2].to?.[1]).toEqual(remove)
expect(manipulators[2].to).toEqual([toOff, toLayerVarOff, remove])
expect(manipulators[3].conditions).toEqual([ifOn])
expect(manipulators[3].to?.[0]).toEqual(toOff)
expect(manipulators[3].to?.[1]).toEqual(remove)
expect(manipulators[3].to).toEqual([toOff, toLayerVarOff, remove])
})
})
8 changes: 6 additions & 2 deletions src/config/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export function hyperLayer(
return modifierLayer('Hyper', key, varName, onValue, offValue)
}

const layerVarName = '__layer' // Shared by all layers, one layer at a time

export class LayerRuleBuilder extends BasicRuleBuilder {
private readonly keys: LayerKeyCode[]
private readonly varName: string
Expand Down Expand Up @@ -181,7 +183,10 @@ export class LayerRuleBuilder extends BasicRuleBuilder {

// Leader mode
if (this.leaderModeOptions) {
const toOff = [toSetVar(this.varName, this.offValue)]
const toOff = [
toSetVar(this.varName, this.offValue),
toSetVar(layerVarName, 0),
]
if (this.layerNotification) {
toOff.push(toRemoveNotificationMessage(notificationId(this.varName)))
}
Expand Down Expand Up @@ -319,7 +324,6 @@ export function layerToggleManipulator(
return to
}

const layerVarName = '__layer' // Shared by all layers, one layer at a time
const manipulator = map({ key_code, modifiers })
.toVar(varName, onValue)
.toVar(layerVarName)
Expand Down
Loading