espanso / espanso

Cross-platform Text Expander written in Rust

Home Page:https://espanso.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option to allow triggering on replaced text

formicant opened this issue · comments

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.