atom / snippets

Atom snippets package
MIT License
205 stars 100 forks source link

Tab stop markers are not removed correctly after reaching last tab stop #248

Closed 50Wliu closed 6 years ago

50Wliu commented 6 years ago

Prerequisites

Description

Snippet tab stop markers are not removed correctly after reaching the last tab stop and typing. The last tab stop should be treated differently than all the rest. After any whitespace is entered, the tab stop markers should be invalidated. Instead, as long as you are at the final tab stop, the only way that I can find to invalidate the tab stops is to edit the previous tab stops. This essentially means that the number of markers will never stop growing as long as the last tab stop is always reached and previous tab stops are not touched.

Steps to Reproduce

  1. Open an untitled editor
  2. Set language to CoffeeScript
  3. Trigger the fora snippet
  4. Go to the last tab stop, which is when # body... is highlighted
  5. Do anything you want as long as your cursor is not placed within a previous tab stop, which can include typing, creating other snippets, copy/pasting in text, deleting everything (editor:select-all followed by backspace), etc.
  6. In dev tools: let editor = atom.workspace.getActiveTextEditor()
  7. editor.getMarkers().length
  8. If you want, you can look at the last marker, which should have some interesting ranges depending on what you did.

Expected behavior: If whitespace or destructive actions was created in step 5, step 7 should return 0

Actual behavior: Step 7 returns at least 3

Reproduces how often: 100%

Versions

Atom    : 1.23.0-dev-02b133844
Electron: 1.6.15
Chrome  : 56.0.2924.87
Node    : 7.4.0
nathansobo commented 6 years ago

I agree this is definitely a bug, but I'm curious what user-visible negative effects it produces. Is it just the resource leak of the markers?

50Wliu commented 6 years ago

There's no real visible downsides of this, except that shift-tabbing can unexpectedly move you back to the last tab stop (which could be a long ways back) instead of decreasing indentation.

snippet-last-tab-stop