diff --git a/pkg/bind/trie/module.go b/pkg/bind/trie/module.go index 492ae340..1d69e25d 100644 --- a/pkg/bind/trie/module.go +++ b/pkg/bind/trie/module.go @@ -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) diff --git a/pkg/bind/trie/trie_test.go b/pkg/bind/trie/trie_test.go index 165ebe67..61e52be2 100644 --- a/pkg/bind/trie/trie_test.go +++ b/pkg/bind/trie/trie_test.go @@ -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{}{ diff --git a/pkg/cy/api/key_test.janet b/pkg/cy/api/key_test.janet new file mode 100644 index 00000000..ad6c7220 --- /dev/null +++ b/pkg/cy/api/key_test.janet @@ -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))))