espanso icon indicating copy to clipboard operation
espanso copied to clipboard

Not to delete trigger when it doesn't appear on-screen

Open xxmaomao opened this issue 8 months ago • 3 comments

Description

Is it possible to support not automatically deleting after completing input? In certain cases, there are no letters entered in the input box. In this case, the content that should be retained will be deleted by mistake

Motivation

No response

Alternatives

No response

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

  • [ ] I'd be willing to contribute this feature to Espanso myself.

xxmaomao avatar Apr 15 '25 06:04 xxmaomao

Mmm, I don't understand you. Can you explain a bit further? In case you didn't know, espanso tracks around the last 10 key presses, and backspaces also count. If you trigger an expansion (for example with :espanso that gives you Hi there!) and then press Backspace, espanso rolls back the expansion and returns you the trigger again (:espanso in this case). Did I point to your problem? or is it not related to matches?

AucaCoyan avatar Apr 16 '25 11:04 AucaCoyan

Mmm, I don't understand you. Can you explain a bit further? In case you didn't know, espanso tracks around the last 10 key presses, and backspaces also count. If you trigger an expansion (for example with :espanso that gives you Hi there!) and then press Backspace, espanso rolls back the expansion and returns you the trigger again (:espanso in this case). Did I point to your problem? or is it not related to matches?

I think I understand what the original author was trying to describe.

Imagine we have an input box that only accepts numbers, like this MWE:

<input type="number" value="1234567890">

Now suppose the user has a trigger defined as:

- trigger: ":number"
  replace: "1234"

When the user tries to type :number inside this numeric-only input, the browser doesn’t actually insert the trigger characters into the field (because it only accepts digits). However, Espanso still detects the trigger sequence and then performs its default behavior: it backspaces to remove the trigger text. Since the trigger was never really shown in the input box, what gets deleted are the existing digits instead.

So for example:

  • Initial input value: 1234567890
  • User types :number (not visible in the field except for the letter e, due to numeric-only restriction)
  • Expected result: 12345678901234
  • Actual result: 12341234 (the existing digits get erased)

Even worse, because input[type=number] actually allows the letter e to be entered, the e in :number does get inserted into the field. As a result, the number of original digits removed isn’t consistent: in this case is 6 characters instead of 7, making Espanso’s behavior even more unpredictable.

This is the kind of case where having an option to not automatically delete the trigger text (or at least to disable deletion when nothing was actually inserted) would solve the problem.

alumik avatar Sep 22 '25 06:09 alumik

Possibly related: https://github.com/espanso/espanso/issues/1933

smeech avatar Sep 22 '25 09:09 smeech