Custom snippets - cursor jumping


#1

I have created this custom snippet in my snippets.cson file:

'class ...':
'prefix': 'class'
'body': '/**\n * \n */\nclass ClassName extends AnotherClass {\n  public function __construct($prop1, prop2, $prop3) {\n    $this->prop1 = $prop1;\n    $this->prop2 = $prop2;\n    $this->prop3 = $prop3;\n  }\n}\n'

which creates this:

/**
 * 
 */
class ClassName extends AnotherClass {
  public function __construct($prop1, $prop2, $prop3) {
    $this->prop1 = $prop1;
    $this->prop2 = $prop2;
    $this->prop3 = $prop3;
  }
}

I wish that i could automatically mark ClassName like this:

39

and then press the tab key to jump and mark AnotherClass like this:
04

I thought that i could do something like this:

'class ...':
'prefix': 'class'
'body': '/**\n * \n */\nclass ${1:ClassName} extends ${2:AnotherClass} {\n  public function __construct($prop1, $prop2, $prop3) {\n    $this->prop1 = $prop1;\n    $this->prop2 = $prop2;\n    $this->prop3 = $prop3;\n  }\n}\n'

but this doesn’t help.
How can i do this?:face_with_raised_eyebrow:


#3

It does do that for me. What were you expecting, and what was actually happening (in detail please)?


#4

I was expecting that it would automatically mark ‘ClassName’ and then if i pressed the tab key it’ll jump and mark ‘AnotherClass’, like this:


Press enter to expand, write the first class name:

and then press tab to mark ‘Bar’:!
index_php_%E2%80%94___Sites
so i can overwrite ‘Bar’ instantly instead of manually moving the cursor.
What really happend was that it just marked Foo like this:
!
and i couldn’t jump anywhere unless i manually moved the cursor :frowning:


#5

I don’t know what to say. The snippet you posted starts with ClassName selected, so typing replaces it, and pressing tab for me selects AnotherClass.

Maybe check the keybinding resolver (Keybinding resolver: toggle in the command palette) and see if another package is interfering with it. I know emmet does stuff with the tab key.

To confirm it’s a community package that’s breaking it, you could also open Atom using atom --safe, and see if it works then. If it does, then it was definitely a community package that was the problem.


#6

It was a problem with the keybindings, but I have solved it now :slight_smile: