Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Conversation

nathansobo
Copy link
Contributor

@nathansobo nathansobo commented Jan 6, 2018

Description of the Change

Previously, when you hit tab inside the last tab stop of a snippet, it would be treated as an ordinary tab.

Now, to bring Atom's behavior more in line with Sublime Text, hitting tab within the last tab stop moves the cursor to the end of the tab stop and terminates the snippet expansion. From this point forward, the tab stops will no longer be present and tab will function as it normally does.

snippets-last-tab-stop

This PR also moves tab stop markers into their own marker layer so that they can be managed with the history. I had hoped this would enable you to cycle through tab stops after expanding, undoing, and redoing, but there is a bug in restoring markers that will need to be fixed before that will work.

Benefits

This prevents us from leaking markers and provides a somewhat more intuitive experience for eliminating tab stops.

Alternate Designs

Ultimately, I think we need to rethink our approach to tab stops entirely. It would be better to enter a snippet editing mode that highlighted the tab stops in a different color and that you exit either by hitting escape or by tabbing off the end. That's a bigger project though.

Possible Drawbacks

It may be surprising that tab doesn't indent code when editing the last tab stop until the tab stop is completely dismissed.

Applicable Issues

Fixes #248

/cc @50Wliu

Nathan Sobo added 3 commits January 8, 2018 07:37
The previous commit changed the behavior of tab in the last tab stop to
jump to the end of the tab stop and eat the tab, whereas previously
hitting tab in the last tab stop just fell back to the default behavior
of tab.

Previously, when we undid a snippet expansion, we didn't destroy its
markers. Instead, we relied on the fact that hitting tab again would be
treated as if it were in the last tab stop, since all the markers got
scrunched together after the prefix following the undo. This would abort
handling of the command and we would move on to dispatch
`snippets:expand`.

Now that we don't abort the command handling in the last tab stop, we
need a better solution. Putting tab stop markers on their own layer and
maintaining history causes these markers to automatically be destroyed
when undoing. Now before working with any tab stop, we check that its
marker is not destroyed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant