input-remapper icon indicating copy to clipboard operation
input-remapper copied to clipboard

Debounce syntax check while typing macro

Open jose1711 opened this issue 3 years ago • 13 comments

obrázok

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.

jose1711 avatar Feb 08 '22 09:02 jose1711

if_single(key(KEY_SPACE), key(LEFT_ALT))

sezanzeb avatar Feb 08 '22 09:02 sezanzeb

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

jose1711 avatar Feb 08 '22 10:02 jose1711

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

sezanzeb avatar Feb 08 '22 10:02 sezanzeb

Hello @sezanzeb , can I get assigned for this issue ?

kearkyle avatar Feb 27 '22 17:02 kearkyle

Sure! Looking forward to your changes

sezanzeb avatar Feb 27 '22 18:02 sezanzeb

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?

kearkyle avatar Feb 28 '22 16:02 kearkyle

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

sezanzeb avatar Feb 28 '22 16:02 sezanzeb

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

sezanzeb avatar Feb 28 '22 16:02 sezanzeb

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

kearkyle avatar Mar 03 '22 23:03 kearkyle

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.

sezanzeb avatar Mar 06 '22 13:03 sezanzeb

I moved debounce to utils and called them inside user_interface.py and autocompletion.py here https://github.com/kearkyle/input-remapper/commit/549101968ad274c545b489f84615f9532d254886.

kearkyle avatar Mar 06 '22 21:03 kearkyle

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

sezanzeb avatar Mar 07 '22 19:03 sezanzeb

I just did it here https://github.com/sezanzeb/input-remapper/pull/331

kearkyle avatar Mar 07 '22 20:03 kearkyle

seems to be working fine on beta.

jonasBoss avatar Feb 20 '23 20:02 jonasBoss