Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit 145726c

Browse files
Match command snippet on ID rather than command name
Also ensure each snippet has its own ID.
1 parent eb7c820 commit 145726c

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

lib/snippet-body.pegjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ ifText = text:(escaped / char:[^:] { return char })+ {
213213
return text.join('')
214214
}
215215

216-
// For either the second part of a two-part if-else OR the sole part of a one-part if/else. Runs until the `}` that ends the expression.
216+
// For either the second part of a two-part if-else OR the sole part of a
217+
// one-part if/else. Runs until the `}` that ends the expression.
217218
ifElseText = text:(escaped / char:[^}] { return char })+ {
218219
return text.join('')
219220
}

lib/snippet.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ function tabStopsReferencedWithinTabStopContent (segment) {
1414

1515
module.exports = class Snippet {
1616
constructor (attrs) {
17-
1817
let {
18+
id,
1919
bodyText,
2020
bodyTree,
2121
command,
@@ -30,6 +30,7 @@ module.exports = class Snippet {
3030
selector
3131
} = attrs
3232

33+
this.id = id
3334
this.name = name
3435
this.prefix = prefix
3536
this.command = command

lib/snippets.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ module.exports = {
274274
} catch (e) {
275275
const message = `\
276276
Unable to watch path: \`snippets.cson\`. Make sure you have permissions
277-
to the \`~/.atom\` directory and \`${userSnippetsPath}\`.
277+
to the \`~/.pulsar\` directory and \`${userSnippetsPath}\`.
278278
279279
On linux there are currently problems with watch sizes. See
280280
[this document][watches] for more info.
@@ -537,7 +537,7 @@ module.exports = {
537537

538538
let targetSnippet = null
539539
for (let snippet of Object.values(snippets)) {
540-
if (snippet.command === command && snippet.packageName === packageName) {
540+
if (snippet.id === attributes.id) {
541541
targetSnippet = snippet
542542
break
543543
}
@@ -555,17 +555,7 @@ module.exports = {
555555
return event.abortKeyBinding()
556556
}
557557

558-
this.getStore(editor).observeHistory({
559-
undo: event => { this.onUndoOrRedo(editor, event, true) },
560-
redo: event => { this.onUndoOrRedo(editor, event, false) }
561-
})
562-
this.findOrCreateMarkerLayer(editor)
563-
editor.transact(() => {
564-
const cursors = editor.getCursors()
565-
for (const cursor of cursors) {
566-
this.insert(targetSnippet, editor, cursor)
567-
}
568-
})
558+
this.expandSnippet(editor, targetSnippet)
569559
}
570560

571561
let disposable = atom.commands.add(
@@ -770,6 +760,22 @@ module.exports = {
770760
}
771761
},
772762

763+
expandSnippet (editor, snippet) {
764+
this.getStore(editor).observeHistory({
765+
undo: event => { this.onUndoOrRedo(editor, event, true) },
766+
redo: event => { this.onUndoOrRedo(editor, event, false) }
767+
})
768+
769+
this.findOrCreateMarkerLayer(editor)
770+
771+
editor.transact(() => {
772+
const cursors = editor.getCursors()
773+
for (const cursor of cursors) {
774+
this.insert(snippet, editor, cursor)
775+
}
776+
})
777+
},
778+
773779
expandSnippetsUnderCursors (editor) {
774780
const snippet = this.snippetToExpandUnderCursor(editor)
775781
if (!snippet) { return false }
@@ -883,7 +889,7 @@ module.exports = {
883889
if (cursor == null) { cursor = editor.getLastCursor() }
884890
if (typeof snippet === 'string') {
885891
const bodyTree = this.getBodyParser().parse(snippet)
886-
snippet = new Snippet({name: '__anonymous', prefix: '', bodyTree, bodyText: snippet})
892+
snippet = new Snippet({id: this.snippetIdCounter++, name: '__anonymous', prefix: '', bodyTree, bodyText: snippet})
887893
}
888894
return new SnippetExpansion(snippet, editor, cursor, this)
889895
},

0 commit comments

Comments
 (0)