Skip to content

Commit b77ef62

Browse files
committed
force boolean
1 parent 55ce356 commit b77ef62

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

src/services/keybindingService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const useKeybindingService = () => {
3838
// TODO: Complex context key evaluation
3939
if (
4040
keybinding.condition &&
41-
!contextKeyStore.getContextKey(keybinding.condition)
41+
contextKeyStore.getContextKey(keybinding.condition) !== true
4242
) {
4343
return
4444
}

src/stores/contextKeyStore.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { defineStore } from 'pinia'
22
import { reactive } from 'vue'
33

44
export const useContextKeyStore = defineStore('contextKeys', () => {
5-
const contextKeys = reactive<Record<string, any>>({})
5+
const contextKeys = reactive<Record<string, boolean>>({})
66

77
/**
88
* Get a stored context key by path
99
* @param {string} path - The path to the context key (e.g., 'a.b.c').
10-
* @returns {any} The value of the context key, or undefined if not found.
10+
* @returns {boolean|undefined} The value of the context key, or undefined if not found.
1111
*/
12-
function getContextKey(path: string): any {
12+
function getContextKey(path: string): boolean | undefined {
1313
if (!path) return undefined
1414
const keys = path.split('.')
1515
let node: any = contextKeys
@@ -25,9 +25,9 @@ export const useContextKeyStore = defineStore('contextKeys', () => {
2525
/**
2626
* Set or update a context key value at a given path
2727
* @param {string} path - The path to the context key (e.g., 'a.b.c').
28-
* @param {any} value - The value to set for the context key.
28+
* @param {boolean} value - The value to set for the context key.
2929
*/
30-
function setContextKey(path: string, value: any) {
30+
function setContextKey(path: string, value: boolean) {
3131
if (!path) return
3232
const keys = path.split('.')
3333
const last = keys.pop()!

tests-ui/tests/store/contextKeyStore.spec.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,58 @@ describe('useContextKeyStore', () => {
1616
describe('setContextKey', () => {
1717
it('sets a top-level key', () => {
1818
const store = useContextKeyStore()
19-
store.setContextKey('foo', 'bar')
20-
expect(store.contextKeys).toEqual({ foo: 'bar' })
19+
store.setContextKey('foo', true)
20+
expect(store.contextKeys).toEqual({ foo: true })
2121
})
2222

2323
it('sets a nested key', () => {
2424
const store = useContextKeyStore()
25-
store.setContextKey('a.b.c', 123)
26-
expect(store.contextKeys).toEqual({ a: { b: { c: 123 } } })
25+
store.setContextKey('a.b.c', true)
26+
expect(store.contextKeys).toEqual({ a: { b: { c: true } } })
2727
})
2828

2929
it('overwrites an existing key', () => {
3030
const store = useContextKeyStore()
31-
store.setContextKey('foo', 'bar')
32-
store.setContextKey('foo', 'baz')
33-
expect(store.contextKeys).toEqual({ foo: 'baz' })
31+
store.setContextKey('foo', true)
32+
store.setContextKey('foo', false)
33+
expect(store.contextKeys).toEqual({ foo: false })
3434
})
3535

3636
it('overwrites an existing nested key', () => {
3737
const store = useContextKeyStore()
38-
store.setContextKey('a.b.c', 123)
39-
store.setContextKey('a.b.c', 456)
40-
expect(store.contextKeys).toEqual({ a: { b: { c: 456 } } })
38+
store.setContextKey('a.b.c', true)
39+
store.setContextKey('a.b.c', false)
40+
expect(store.contextKeys).toEqual({ a: { b: { c: false } } })
4141
})
4242

4343
it('creates intermediate objects when setting nested keys', () => {
4444
const store = useContextKeyStore()
45-
store.setContextKey('x.y', 'level2')
46-
store.setContextKey('x.z', 'another level2')
45+
store.setContextKey('x.y', true)
46+
store.setContextKey('x.z', false)
4747
expect(store.contextKeys).toEqual({
48-
x: { y: 'level2', z: 'another level2' }
48+
x: { y: true, z: false }
4949
})
5050
})
5151

5252
it('handles overwriting a non-object with an object for nested keys', () => {
5353
const store = useContextKeyStore()
54-
store.setContextKey('a', 1)
55-
store.setContextKey('a.b', 'nested')
56-
expect(store.contextKeys).toEqual({ a: { b: 'nested' } })
54+
store.setContextKey('a', true)
55+
store.setContextKey('a.b', false)
56+
expect(store.contextKeys).toEqual({ a: { b: false } })
5757
})
5858
})
5959

6060
describe('getContextKey', () => {
6161
it('gets a top-level key', () => {
6262
const store = useContextKeyStore()
63-
store.setContextKey('foo', 'bar')
64-
expect(store.getContextKey('foo')).toBe('bar')
63+
store.setContextKey('foo', true)
64+
expect(store.getContextKey('foo')).toBe(true)
6565
})
6666

6767
it('gets a nested key', () => {
6868
const store = useContextKeyStore()
69-
store.setContextKey('a.b.c', 123)
70-
expect(store.getContextKey('a.b.c')).toBe(123)
69+
store.setContextKey('a.b.c', true)
70+
expect(store.getContextKey('a.b.c')).toBe(true)
7171
})
7272

7373
it('returns undefined for a non-existent top-level key', () => {
@@ -77,53 +77,53 @@ describe('useContextKeyStore', () => {
7777

7878
it('returns undefined for a non-existent nested key', () => {
7979
const store = useContextKeyStore()
80-
store.setContextKey('a.b', {})
80+
store.setContextKey('a.b', true)
8181
expect(store.getContextKey('a.b.c')).toBeUndefined()
8282
})
8383

8484
it('returns undefined when path segment does not exist', () => {
8585
const store = useContextKeyStore()
86-
store.setContextKey('a.b', 1)
86+
store.setContextKey('a.b', true)
8787
expect(store.getContextKey('a.x.c')).toBeUndefined()
8888
})
8989
})
9090

9191
describe('removeContextKey', () => {
9292
it('removes a top-level key', () => {
9393
const store = useContextKeyStore()
94-
store.setContextKey('foo', 'bar')
95-
store.setContextKey('baz', 'qux')
94+
store.setContextKey('foo', true)
95+
store.setContextKey('baz', false)
9696
store.removeContextKey('foo')
97-
expect(store.contextKeys).toEqual({ baz: 'qux' })
97+
expect(store.contextKeys).toEqual({ baz: false })
9898
})
9999

100100
it('removes a nested key', () => {
101101
const store = useContextKeyStore()
102-
store.setContextKey('a.b.c', 123)
103-
store.setContextKey('a.b.d', 456)
102+
store.setContextKey('a.b.c', true)
103+
store.setContextKey('a.b.d', false)
104104
store.removeContextKey('a.b.c')
105-
expect(store.contextKeys).toEqual({ a: { b: { d: 456 } } })
105+
expect(store.contextKeys).toEqual({ a: { b: { d: false } } })
106106
})
107107

108108
it('prunes empty ancestor objects when removing a nested key', () => {
109109
const store = useContextKeyStore()
110-
store.setContextKey('a.b.c', 123)
110+
store.setContextKey('a.b.c', true)
111111
store.removeContextKey('a.b.c')
112-
expect(store.contextKeys).toEqual({}) // a and a.b should be pruned
112+
expect(store.contextKeys).toEqual({})
113113
})
114114

115115
it('prunes only up to the non-empty ancestor', () => {
116116
const store = useContextKeyStore()
117-
store.setContextKey('a.b.c', 123)
118-
store.setContextKey('a.x', 456) // Add another key under 'a'
117+
store.setContextKey('a.b.c', true)
118+
store.setContextKey('a.x', false)
119119
store.removeContextKey('a.b.c')
120-
expect(store.contextKeys).toEqual({ a: { x: 456 } }) // a.b pruned, but a remains
120+
expect(store.contextKeys).toEqual({ a: { x: false } })
121121
})
122122

123123
it('does nothing if the key does not exist', () => {
124124
const store = useContextKeyStore()
125-
store.setContextKey('a.b', 1)
126-
const initialState = JSON.parse(JSON.stringify(store.contextKeys)) // Deep clone
125+
store.setContextKey('a.b', true)
126+
const initialState = JSON.parse(JSON.stringify(store.contextKeys))
127127
store.removeContextKey('nonexistent')
128128
expect(store.contextKeys).toEqual(initialState)
129129
store.removeContextKey('a.c')
@@ -134,7 +134,7 @@ describe('useContextKeyStore', () => {
134134

135135
it('does nothing if the path is empty', () => {
136136
const store = useContextKeyStore()
137-
store.setContextKey('a', 1)
137+
store.setContextKey('a', true)
138138
const initialState = JSON.parse(JSON.stringify(store.contextKeys))
139139
store.removeContextKey('')
140140
expect(store.contextKeys).toEqual(initialState)
@@ -144,8 +144,8 @@ describe('useContextKeyStore', () => {
144144
describe('clearAllContextKeys', () => {
145145
it('clears all keys', () => {
146146
const store = useContextKeyStore()
147-
store.setContextKey('a', 1)
148-
store.setContextKey('b.c', 2)
147+
store.setContextKey('a', true)
148+
store.setContextKey('b.c', false)
149149
store.clearAllContextKeys()
150150
expect(store.contextKeys).toEqual({})
151151
})

0 commit comments

Comments
 (0)