pviswanathan / ChromeAutoTextExpander

Google Chrome Extension : Auto Text Expander - listens for keypresses on pages that support it and will auto-replace text as you type. Keywords: javascript jquery chrome text expander replacement.
MIT License
156 stars 45 forks source link

Pattern matching #15

Open eliangcs opened 9 years ago

eliangcs commented 9 years ago

Thank you for this awesome extension!

I'd like to propose a feature where we can trigger a shortcut when a pattern (e.g., regular expression) is matched.

I often need to refer to a JIRA ticket link when writing an email. A JIRA ticket number looks like ABC-1234. When I type "ABC-1234 ", I wanted it to be expanded to <a href="http://jira.server.url/ABC-1234">ABC-1234</a>.

To do this, I think users can add a shortcut with a regex, such as ABC-(?<match>\d+). The syntax uses named capture as in http://xregexp.com/syntax/#namedCapture. On the expansion field, they can fill in something like <a href="http://jira.server.url/ABC-%match%">ABC-%match%</a>.

I can send a pull request implementing this feature if you think it's a good idea.

carlinyuen commented 9 years ago

Hey Chang-Hung, that's an interesting idea!

There will have to be some delimiter for the expander to know when to expand, otherwise the moment you type ABC-1 it will fire off. Hit me with a proposal and let's see how it looks.

. Carlin ............................................ Product . Design . Development e : email.me@carlinyuen.com

: +1 (234) 567-9763

On Wed, May 13, 2015 at 5:57 AM, Chang-Hung Liang notifications@github.com wrote:

Thank you for this awesome extension!

I'd like to propose a feature where we can trigger a shortcut when a pattern (e.g., regular expression) is matched.

I often need to refer to a JIRA ticket link when writing an email. A JIRA ticket number looks like ABC-1234. When I type "ABC-1234", I wanted it to be expanded to ABC-1234.

To do this, I think users can add a shortcut with a regex, such as "ABC-(\d+)". And on the expansion field, they can fill in something like <a href="http://jira.server.url/ABC-%match%">ABC-%match%.

I can send a pull request implementing this feature if you think it's a good idea.

— Reply to this email directly or view it on GitHub https://github.com/carlinyuen/ChromeAutoTextExpander/issues/15.

eliangcs commented 9 years ago

I think users will have to add a special trailing character to prevent the "early fire". For example, you can add a space at the end the pattern, so the shortcut won't be triggered until you hit space.

eliangcs commented 9 years ago

Any thoughts? @carlinyuen

carlinyuen commented 9 years ago

Hey sorry about that! That sounds good to me, submit a proposed change and pull request and lets review!

On Sat, May 16, 2015, 02:45 Chang-Hung Liang notifications@github.com wrote:

Any thoughts? @carlinyuen https://github.com/carlinyuen

— Reply to this email directly or view it on GitHub https://github.com/carlinyuen/ChromeAutoTextExpander/issues/15#issuecomment-102579732 .

GrayedFox commented 5 years ago

I think users will have to add a special trailing character to prevent the "early fire". For example, you can add a space at the end the pattern, so the shortcut won't be triggered until you hit space.

Why not just update your regex pattern to actually match 4 digits instead of any amount of digits? If you allow the user to specify the full regex pattern, it's up to them to figure out what regex works best. I.e in your case if you want it to match four digits instead of any amount of digits, just create that regex: ABC-\d{4}.

The problem comes when you want to match strings with a variable amount of digits, i.e. between 4 and 6 digits (i.e. ABC-1234, ABC-12345, and ABC-123456, but not ABC-1234567), using something like this: regexr.com/3vr9j

Now we have an implementation problem. If the app triggers on every keystroke - then it would expand ABC-1234 before it waits for ABC-1234567 to be written by the user, which we don't want to match.

This would involve changing the expansion behaviour to be different for reg-ex patterns, for example, rather than on every key stroke, it should perhaps wait until the user has stopped typing (use defined: can be in milliseconds) - and only then attempt the expansion.

Happy to help with the implementation here :wink: