espanso icon indicating copy to clipboard operation
espanso copied to clipboard

Add option to discard the trigger character

Open shaneknysh opened this issue 3 years ago • 19 comments

I use "eml" -> "email address" but when triggered with space I get "eml" -> "email address " That extra space at the end causes a fight between me and the backspace to undo feature when all I want to do is remove the trigger character.

shaneknysh avatar Mar 21 '21 17:03 shaneknysh

Hey @shaneknysh,

Thank you for the feedback! Not sure how we can solve it exactly, are you using the word option? In the meanwhile, a little trick you could use is pressing the "shift" key before the backspace, which disables the undo feature for that match

Cheers :)

federico-terzi avatar Mar 21 '21 17:03 federico-terzi

I'm having the same issue. I think it would be great to have an option to suppress the trigger character (space) when using the word option (I think that is how it works with autohotkey). Anyway, thanks for the great utility!

joonro avatar Jun 15 '21 17:06 joonro

@joonro Sounds good, thank you! I'll investigate, it shouldn't be too hard to implement, although I can't give you any estimate date :)

federico-terzi avatar Jun 15 '21 19:06 federico-terzi

Is this still a problem with the recent release?

smeech avatar Feb 13 '24 12:02 smeech

Yes

shaneknysh avatar Feb 13 '24 15:02 shaneknysh

Thank you for replying after so long! Does:

  - trigger: ":eml "
    replace: email address

meet your needs, or have I misunderstood the problem?

smeech avatar Feb 13 '24 16:02 smeech

No.

Adding a space to the trigger doesn't remove the trigger character after triggering it only adds an additional character to the precursor

"eml " -> "email address" when triggered with space I get "eml " -> "email address "

"eml " -> "email address "<--- this space at the end is the issue.

If I am filling in a contact form this is the desired text entry

typed text | desired result
---------------------------
 tab       | enter email field
 eml       | "eml" entered into email field
 space     | "eml" is expanded to "email address"
 tab       | leave email field

actual text entry

typed text | desired result
---------------------------
 tab       | enter email field
 eml       | "eml" entered into email field
 space     | "eml" is expanded to "email address "
 tab       | leave email field, email address displays an error as an invalid email address

actual text entry

typed text | desired result
---------------------------
 tab       | enter email field
 eml       | "eml" entered into email field
 space     | "eml" is expanded to "email address "
 backspace | "email address " is reverted to "eml"

work around text entry

typed text | desired result
---------------------------
 tab       | enter email field
 eml       | "eml" entered into email field
 space     | "eml" is expanded to "email address "
 shift     | cancels the revert option
 backspace | "email address " is corrected to "email address"
 tab       | leave email field

shaneknysh avatar Feb 13 '24 17:02 shaneknysh

Thank you. That's very helpful.

It's not what happens here with the code I posted, or if I use - regex: instead of - trigger:: ":eml " gets replaced by "email address" with no space suffix, which is what should happen, and I think is what you want?

I presume your contact form is in a specialist program? Does the same space suffix occur if you try the trigger in a plain text editor?

Have you tried changing the backend using the force_mode: trigger options?

smeech avatar Feb 13 '24 17:02 smeech

I will test again later but I was still getting the additional space this morning.

What mode are you using? I think my config is set to keys but I can't check right now.

shaneknysh avatar Feb 13 '24 17:02 shaneknysh

I will test again later but I was still getting the additional space this morning.

What mode are you using? I think my config is set to keys but I can't check right now.

My (Linux Mint Xfce) default is Clipboard except for my terminal (Auto), and LibreOffice Calc (Inject). To save repeatedly editing default.yml, the force_mode: options are useful for testing individual triggers to determine if an app-specific configuration, or global change to default.yml, might be helpful.

smeech avatar Feb 13 '24 18:02 smeech

I will test with clipboard and update.

I wrote my config and replacements long before individual trigger option was added.

shaneknysh avatar Feb 13 '24 18:02 shaneknysh

Changed my config from "keys" to "clipboard" to "auto" and I still get "email address "

also tested before and after updating from 2.1.x to 2.2.1 and I still get the trigger character.

does case matter? Keys vs keys etc

shaneknysh avatar Feb 14 '24 00:02 shaneknysh

force_mode: accepts clipboard or keys. I haven't tried changing the case. For backend: it's Clipboard, Inject or Auto but it's only worth changing this global setting if you find a general change beneficial. You could try generating an intermediate echo: variable for the email address before outputting the variable - I've seen that help once. What's your OS and the program concerned? Do you always get the extra spaces (in other editors/word-processors/terminal, etc.)?

smeech avatar Feb 14 '24 18:02 smeech

I always get the trigger character its not an space being injected

typed text | result
---------------------------
 space     | "eml" is expanded to "email address "
 ,         | "eml" is expanded to "email address,"
 .         | "eml" is expanded to "email address."

The trigger character is inserted by design but there are cases when it is not wanted

shaneknysh avatar Feb 14 '24 18:02 shaneknysh

Only if you're using word: true should it leave the word_separator (it's useful for entering triggers within blocks of text) but if you're not (and you don't need it for a single-field input) you shouldn't. I'd need to see your actual trigger code.

smeech avatar Feb 15 '24 00:02 smeech

default.yml

# Automatically generated by espanso migration tool
# Original file: default.yml

backend: Clipboard
toggle_key: RIGHT_ALT
auto_restart: true
undo_backspace: true

contact.yml

matches:
  - trigger: eml
    replace: email address
    word: true

shaneknysh avatar Feb 15 '24 00:02 shaneknysh

If you take out word: true it should work as you want, but you may wish to add a disambiguation character on the beginning of your trigger to prevent it expanding in general text (not that there are any words in common use that ChatGPT could come up with in this instance).

smeech avatar Feb 15 '24 10:02 smeech

I have tested word: true / false but that was quite some time ago.

I don't want to turn off undo I use it when I get an expansion I don't want like if I am typing eml in this response.

Where did you use -regex I'm not familiar with that setting?

shaneknysh avatar Feb 15 '24 15:02 shaneknysh

I didn't use - regex: here but did mention that it works. Apologies for mentioning undo_backspace - I misread your code. When I noticed, I edited my addition in the GitHub Issue thread, but you won't have seen it if you're relying on the emails.

smeech avatar Feb 15 '24 15:02 smeech

Adding a space character works for me. However, I prefer to stick with word: true and add $|$ at the end of the replacement text.

stewcam avatar Jul 02 '24 03:07 stewcam

This still keeps the trigger character but moves the cursor to be in front of the trigger character

So instead of replaced word | you get replaced word|

so instead of having to hit [backspace] to remove the trigger character you need to hit [delete]

On Mon, Jul 1, 2024, 9:39 PM StewCam @.***> wrote:

Adding a space character works for me although for a more "pure" Espanso solution I prefer sticking with word: true and adding $|$ at the end of the replacement text.

— Reply to this email directly, view it on GitHub https://github.com/espanso/espanso/issues/626#issuecomment-2201817973, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABGVGNFI6NNOOQBB37PQ4LZKIOFPAVCNFSM4ZRYJUM2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMRQGE4DCNZZG4ZQ . You are receiving this because you were mentioned.Message ID: @.***>

shaneknysh avatar Jul 02 '24 04:07 shaneknysh

@shaneknysh Yes, although it does allow you to avoid that fight between backspace and undo!

stewcam avatar Jul 02 '24 05:07 stewcam

@shaneknysh If you want to avoid the trailing space altogether you add $ to your word separators and then enter your replacement text as ending in $|. On triggering with $ you should then get the desired replacement text without either $| or a trailing space (tested).

stewcam avatar Jul 02 '24 06:07 stewcam

It's not a trailing space it's a trailing replacement character.

On Tue, Jul 2, 2024, 12:07 AM StewCam @.***> wrote:

@shaneknysh https://github.com/shaneknysh If you want to avoid the trailing space altogether you add $ to your word separators and then enter your replacement text as ending in $|. On triggering with $ you should then get the desired replacement text without either $| or a trailing space (tested).

— Reply to this email directly, view it on GitHub https://github.com/espanso/espanso/issues/626#issuecomment-2202012060, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABGVGKJUKM2FD5NLI7VAZLZKI7R7AVCNFSM4ZRYJUM2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMRQGIYDCMRQGYYA . You are receiving this because you were mentioned.Message ID: @.***>

shaneknysh avatar Jul 02 '24 06:07 shaneknysh

@shaneknysh Yes, but you should find that the replacement character (word separator) $ will combine with the replacement text ending in $| to give you what you want. The strings $| and $ eat each other when they meet.

stewcam avatar Jul 02 '24 07:07 stewcam

Still occuring.

shaneknysh avatar Aug 17 '24 14:08 shaneknysh

I think Espanso is working as it should, and you may need to adjust your code, along the lines discussed, to make it do what you want. Espanso doesn't have trigger characters, by the way.

smeech avatar Aug 17 '24 18:08 smeech

I'm glad espanso doesn't have trigger characters.

How would you like me to refer to the character I type to trigger a replacement with espanso?

You can close this as won't fix or working as intended but it is not fixed. The behavior is still present. The solutions presented are workarounds and do not repress the inclusion on the "character typed that triggers a replacement."

the $| "fix" only works if the "character typed to trigger replacement" is a space and I found it did not work at all in online forms asking for email address.

shaneknysh avatar Aug 17 '24 19:08 shaneknysh