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

lookup-key returns wrong entry when looking up based on :code #21

Closed
simendsjo opened this issue Oct 28, 2023 · 5 comments · Fixed by #25
Closed

lookup-key returns wrong entry when looking up based on :code #21

simendsjo opened this issue Oct 28, 2023 · 5 comments · Fixed by #25
Assignees

Comments

@simendsjo
Copy link

The problem seems to be key=, which will always check "or code-match value-match", and because the default for value is "", it will always match when supplying only the code.

(key= (make-key :code 0) (make-key :code 1)) ;; t
(key= (make-key :code 1) (make-key :code 0)) ;; t
(key= (make-key :code 1) (make-key :code 2)) ;; t

The following works:

(key= (make-key :code 2 :value "dummy-1") (make-key :code 1 :value "dummy-2")) ;; nil
(key= (make-key :code 2 :value "dummy-1") (make-key :code 2 :value "dummy-2")) ;; t

But this also pose a problem with define-key. Here I'm binding two different keys, but the size is still 1.

(let ((km (nkeymaps:make-keymap "foo")))
    (nkeymaps:define-key km "#1" (lambda ()))
    (nkeymaps:define-key km "#2" (lambda ()))
    (fset:size (nkeymaps/core::entries km))) ;; 1

Adding a dummy value when defining the key, and the lookup-key returns the correct value.

(let ((km (nkeymaps:make-keymap "foo")))
    (nkeymaps:define-key km '((:code 1 :value "dummy-1")) (lambda () (format t " 1 ")))
    (nkeymaps:define-key km '((:code 2 :value "dummy-2")) (lambda () (format t "2")))
    (fset:size (nkeymaps/core::entries km))
    (funcall (nkeymaps:lookup-key "#1" km))
    (funcall (nkeymaps:lookup-key "#2" km))) ;; 1 2

The above also let's us query based on :code

(let ((km (nkeymaps:make-keymap "foo")))
    (nkeymaps:define-key km '((:code 1 :value "dummy-1")) (lambda () (format t " 1 ")))
    (nkeymaps:define-key km '((:code 2 :value "dummy-2")) (lambda () (format t "2")))
    (fset:size (nkeymaps/core::entries km))
    (funcall (nkeymaps:lookup-key (list (nkeymaps:make-key :code 1)) km))
    (funcall (nkeymaps:lookup-key (list (nkeymaps:make-key :code 2)) km))) ;; 1 2
@Ambrevar Ambrevar self-assigned this Dec 11, 2023
@Ambrevar
Copy link
Member

Thanks for your report, I'm on it.

@Ambrevar
Copy link
Member

@simendsjo Should be fixed with #25.

@simendsjo
Copy link
Author

Works for me, and doesn't seem to break anything else. Thanks!

@Ambrevar
Copy link
Member

Thanks for reporting!

@simendsjo
Copy link
Author

Thanks for reporting!

Thanks for fixing ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants