Debounce syntax check while typing macro

ERROR: Failed to parse macro "if_single(KEY_SPACE,LEFT_ALT)": TypeError("Expected parameter 1 for if_single to be one of [<class 'inputremapper.injection.macros.macro.Macro'>, None], but got KEY_SPACE")
$ pacman -Q input-remapper-git
input-remapper-git 1.4.0.r12.gee6b48a-1
# current master
Not sure if I am doing something wrong or there's anything broken on my system.
if_single(key(KEY_SPACE), key(LEFT_ALT))
Oh, thank you (facepalm). Also the correct one is
if_single(key(KEY_SPACE), key(KEY_LEFTALT))
LEFT_ALT is not a recognized key-name. Normally the syntax checker would notify me but check briefly it flashes (you won't have a chance to see that unless you're in a debug mode).
https://user-images.githubusercontent.com/1406222/152965838-d70bcc0f-e7b2-455e-a15a-df2b921fe960.mp4
Syntax errors are checked when the cursor leaves the text input. An improvement might be to debounce a call to check_macro_syntax while typing, similar to how autocompletion is debounced
Hello @sezanzeb , can I get assigned for this issue ?
Sure! Looking forward to your changes
Hi @sezanzeb, so in order to debounce to check_macho_syntax, would it be correct if I import debounce function from autocompletion and then use that within consume_newest_keycode or is there another function where you would suggest to implement the debounce?
If debouncing is used in two unrelated modules, then it should be moved into its own file.
consume_newest_keycode is the wrong place. syntax checking should happen when typing the macro, not when recording keys
connect the "changed" signal (see https://lazka.github.io/pgi-docs/#Gtk-3.0/classes/TextBuffer.html#signals) to the text buffer of the sourceview and do it there
Hi @sezanzeb can you take a look at this and could give me some feedback if this is right? https://github.com/kearkyle/input-remapper/commit/68a6900a63081e04da2197db0622ead7e2b615b7
nice
Right now the debounce decorator is defined twice, and it is a very good practice to reduce code duplication to a minimum. The worst case with duplicates is, that if there is a bug in the existing debounce code, maybe we will forget updating the copy as well. This principle also has a wikipedia article: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
So it would be best to put both debouncing decorators into some util file. maybe inputremapper/utils.py.
I moved debounce to utils and called them inside user_interface.py and autocompletion.py here https://github.com/kearkyle/input-remapper/commit/549101968ad274c545b489f84615f9532d254886.
You should make a pull request, it will be easier to track changes, commits and reviews and there will be some automatic checks for your code
I just did it here https://github.com/sezanzeb/input-remapper/pull/331
seems to be working fine on beta.