Skip to content

Commit

Permalink
fix: broken (key/remap)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Jul 25, 2024
1 parent 427a059 commit d0af0af
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/bind/trie/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,12 @@ func (t *Trie[T]) Remap(from, to []interface{}) {
next = oldParent.nextRe[step.Pattern].next
}

if next == nil {
return
}

// Remove that path
t.clear(from)
oldParent.clear(from)

// Then create the path to the new parent if necessary
newParent := t.access(from[:len(to)-1], true)
Expand Down
24 changes: 24 additions & 0 deletions pkg/bind/trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ func TestTrie(t *testing.T) {
require.Equal(t, 0, len(trie.Leaves()))
}

func TestManyRemap(t *testing.T) {
trie := New[int](nil)

trie.Set([]interface{}{
"one",
"three",
}, 1)

trie.Remap([]interface{}{
"one",
}, []interface{}{
"three",
})

require.Equal(t, 1, len(trie.Leaves()))

trie.Remap([]interface{}{
"one",
}, []interface{}{
"three",
})
require.Equal(t, 1, len(trie.Leaves()))
}

func TestRegex(t *testing.T) {
trie := New[int](nil)
trie.Set([]interface{}{
Expand Down
6 changes: 6 additions & 0 deletions pkg/cy/api/key_test.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(test "(key/remap)"
(key/remap :root ["ctrl+a"] ["`"])
(def before (key/get :root))
(key/remap :root ["ctrl+a"] ["`"])
(def after (key/get :root))
(assert (deep= (length before) (length after))))

0 comments on commit d0af0af

Please sign in to comment.