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

Add option to allow triggering on replaced text #1943

Open
1 task
formicant opened this issue Apr 13, 2024 · 0 comments
Open
1 task

Add option to allow triggering on replaced text #1943

formicant opened this issue Apr 13, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@formicant
Copy link

formicant commented Apr 13, 2024

Description

Now, triggers work with text typed on the keyboard, but don’t work with text already replaced by Espanso.

Consider the following match file:

matches:
  - trigger: "<-"
    replace: ""
  
  - trigger: "←>"
    replace: ""

When I type ‘<’, then, ‘-’, the first match is triggered replacing the characters with a left arrow ‘←’.
If I add ‘>’ afterwards, nothing happens, despite the presence of the trigger sequence of the second match.
It would be great if the second match could also work.

I think, this behavior could be switched by a global option (off by default to prevent breaking of existing configurations).

Also, max_recursion_depth parameter should be defined to prevent infinite recursions like this:

matches:
  - trigger: "!"
    replace: "!!"

(Maybe, just max_recursion_depth = 0 by default, and no need for a separate on/off option.)

Ideally, a static analyzer could warn the user about an infinite recursion in the config.

Motivation

I think, the left-right arrow example above is a legitimate use case.

Also, in my keyboard layout, I have combining diacritical characters.
I use Espanso to replace letter+diacritic combination with a precombined character.
Now, I cannot get precombined characters with two or more diacritics,

matches:
  - trigger: "a\u0302" # LATIN SMALL LETTER A, COMBINING CIRCUMFLEX ACCENT
    replace: "â" # LATIN SMALL LETTER A WITH CIRCUMFLEX
  
  - trigger: "â\u0301" # LATIN SMALL LETTER A WITH CIRCUMFLEX, COMBINING ACUTE ACCENT
    replace: "" # LATIN SMALL LETTER A WITH CIRCUMFLEX AND ACUTE

Alternatives

Alternatively, similar results could be achieved by allowing trigger backtracking — making Espanso remember previous keyboard input even after replacing and cancel previous replacements when a larger one matches:

matches:
  - trigger: "<-"
    replace: ""

  - trigger: "<->" # original characters here
    replace: ""

I think, however, that this approach is a bit more complicated.

Have you tried building it? Or would you like it?

  • I'd be willing to contribute this feature to Espanso myself.
@smeech smeech added the enhancement New feature or request label Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants