atom / snippets

Atom snippets package
MIT License
204 stars 102 forks source link

Snippets do not work after punctuation #151

Open djpowers opened 9 years ago

djpowers commented 9 years ago

Hello,

I noticed that when trying to tab-complete an ERB tag, it does not work if the cursor is directly after HTML tags with no whitespace, and seemingly any other punctuation. I wasn't sure if this was intentional, or a limitation of some sort.

I'm using Atom 0.210.0 on Mac OS X 10.10.3.

To reproduce:

  1. Open a new document and set the syntax to HTML (Rails).
  2. Autocomplete a span tag, which places the cursor in between: <span></span>
  3. Type = and then press tab to trigger the snippet.

Expected behavior: An ERB tag would be created inside the span, like so:

<span><%=  %></span>

Actual behavior: The cursor jumps ahead to after the closing tag without creating the ERB tag:

<span>=</span>

Triggering this snippet works if it directly follows whitespace or an alphanumeric character, so I wasn't sure if following symbols should work the same.

Please let me know if I missed some documentation, or if this should be reported elsewhere. Thank you.

Oblik-Design commented 7 years ago

works for letters now, but still no love for a snippet like $$,I would love to have this fixed.

dankimio commented 7 years ago

Having the same issue in Atom 1.20.

savetheclocktower commented 6 years ago

This is a complex issue that arises when a snippet’s prefix begins with punctuation rather than a letter. When the user hits Tab and the cursor is preceded by several punctuation marks in a row (>= in this example), the snippets package looks for snippets whose prefixes start with > instead of = because there’s no obvious “word” boundary to help it out.

It looks for such a boundary because if a snippet has a prefix ff, we don't want it to get invoked if the user types off and then presses Tab. But when the entire “word” is just a string of non-word characters, we shouldn’t really care about this potential false positive, so I think I’ve got an idea of how we’d fix this.