atom / snippets

Atom snippets package
MIT License
205 stars 100 forks source link

$n at the beginning of a line selects preceding spaces #205

Closed hediyi closed 8 years ago

hediyi commented 8 years ago

Say you have created a snippet with a $n at the beginning of a line (no spaces before it), as shown below. Then in a file, at a certain level of indention, when you try to expand that snippet, besides moving the cursor to the specified position, the spaces before it is selected.

You can also reproduce the problem in other types of files.

Reproduction Steps:

  1. Launch Atom.
  2. Put this in the snippets.cson:

    '.source.gfm':
     'Ruby sinppet':
       'prefix': 'rb'
       'body': """
         ```Ruby
         $1

    """

  3. Create a new test.md in Atom.
  4. In the pane of test.md, hit Tab once (to create a level of indentation), then enter rb, hit Tab again.

Expected behavior:

I should have

```Ruby

with the cursor at coordinate 2:3, and nothing selected.

**Observed behavior:**

I have


with the cursor at coordinate 2:3, and the spaces before that coordinate on the second row selected.

**Atom version:** 1.7.3
**OS and version:** OS X 10.11.5

**Additional information:**
- Problem can be reproduced in safe mode: Yes
- Problem can be reliably reproduced, doesn't happen randomly: Yes
- Problem happens with all files and projects, not only some files or projects: Yes
scottmcpherson commented 8 years ago

+1 Same issue here accept my snippet has a default value that it's selecting, and it's selecting the preceding white space.

# Python
'.source.python':
  'Docstring':
    'prefix': 'ds'
    'body': """
    '''${1:A description: Tell this function what to do}

    Keyword arguments:
    ${2:arg1} -- ${3:description} ${4:(default ${5:0})}

    Returns: ${6:string}

    '''
    """

So when I hit tab to go to ${2:arg1}, it selects all the preceding white space. When I start typing, it moves my indentation all the way to the right of the editor instead of honoring the indentation.

50Wliu commented 8 years ago

This is a duplicate of #140 - feel free to subscribe there for updates.