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

Commit f0a1ff6

Browse files
committed
temp take 3?
im second guessing myself
1 parent 06a627c commit f0a1ff6

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

constructs/snippet.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ module.exports = class Snippet extends Construct {
170170

171171
// helper cause Snippet isn't really ever available
172172
expand ({
173-
cursor = atom.workspace.getActiveTextEditor().getLastCursor(),
174-
tabstops = cursor.editor.addMarkerLayer(),
173+
editor = atom.workspace.getActiveTextEditor(),
174+
cursor = editor.getLastCursor(),
175+
tabstops = editor.addMarkerLayer(),
175176
variables = {}
176177
} = {}) {
177178
if (this.legacySyntax) {
@@ -207,8 +208,8 @@ module.exports = class Snippet extends Construct {
207208

208209
this.body.forEach(value => {
209210
value instanceof Object
210-
? value.expand(cursor, tabstops, variables)
211-
: this.insert(cursor, value)
211+
? value.expand(editor, cursor, tabstops, variables)
212+
: this.insert(editor, cursor.getBufferPosition(), value)
212213
})
213214

214215
// Only create tabstop stuff if we have any
@@ -218,13 +219,10 @@ module.exports = class Snippet extends Construct {
218219
// The markers aren't guaranteed to be in insertion order, as they're stored in an Object
219220
// Luckilly the ids used are integers and the values are fetched using 'Object.values'
220221
const stops = {
221-
tabstops: Snippet.getTabstops(tabstops.getMarkers()),
222-
get iterator () {
223-
delete this.iterator
224-
return (this.iterator = this.tabstops.values())
225-
},
226-
next () {
222+
iterator: Snippet.getTabstops(tabstops.getMarkers()).values(),
223+
next (event) {
227224
const { done, value: [stop, ...mirrors] = [] } = this.iterator.next()
225+
const editor = event.originalEvent.getModel();
228226
return done
229227
? disposables.dispose()
230228
// Cheaty way of returning true concisely
@@ -236,7 +234,7 @@ module.exports = class Snippet extends Construct {
236234
disposables.add(
237235
{ dispose: () => tabstops.destroy() },
238236
atom.keymaps.add(module.filename, { [target]: { tab: iterate } }),
239-
atom.commands.add(target, iterate, event => stops.next() ||
237+
atom.commands.add(target, iterate, event => stops.next(event) ||
240238
event.abortKeyBinding()))
241239

242240
// Go to the first tabstop

constructs/tabstop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const Construct = require('./construct')
22

33
module.exports = class Tabstop extends Construct {
4-
expand (cursor, tabstops, variables) {
4+
expand (editor, cursor, tabstops, variables) {
55
this.mark({ tabstops, start: cursor.getBufferPosition() })
66
}
77
}

constructs/variable.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const Construct = require('./construct')
22

33
module.exports = class Variable extends Construct {
4-
expand (cursor, tabstops, variables) {
4+
expand (editor, cursor, tabstops, variables) {
5+
const position = cursor.getBufferPosition();
56
this.identifier in variables
6-
? this.insert(cursor, variables[this.identifier])
7-
: this.mark({ tabstops, ...this.insert(cursor, this.identifier) })
7+
? this.insert(editor, position, variables[this.identifier])
8+
: this.mark({ tabstops, ...this.insert(editor, position, this.identifier) })
89
}
910
}

snippets.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ module.exports = class Snippets {
2121
: undefined),
2222
atom.commands.add('atom-text-editor', 'snippets:available', () =>
2323
this.availableSnippetsView.toggle(atom.workspace.getActiveTextEditor())),
24-
atom.packages.onDidActivatePackage(bundle => this.loadPackage(bundle)),
25-
atom.packages.onDidDeactivatePackage(bundle => this.unloadPackage(bundle)))
24+
atom.packages.onDidActivatePackage(pack => this.loadPackage(pack)),
25+
atom.packages.onDidDeactivatePackage(pack => this.unloadPackage(pack)))
2626

2727
await (this.loaded = Promise.all([
2828
this.loadUserSnippets(),
29-
...atom.packages.getActivePackages().map(bundle => this.loadPackage(bundle))
29+
...atom.packages.getActivePackages().map(pack => this.loadPackage(pack))
3030
]).then(() => true))
3131
}
3232

@@ -75,17 +75,17 @@ module.exports = class Snippets {
7575
}
7676
}
7777

78-
static async loadPackage (bundle) {
79-
const snippetsDirectory = path.join(bundle.path, 'snippets')
78+
static async loadPackage (pack) {
79+
const snippetsDirectory = path.join(pack.path, 'snippets')
8080
try {
8181
const files = await fs.promises.readdir(snippetsDirectory)
8282
files.forEach(async file => {
8383
const snippetsFile = path.join(snippetsDirectory, file)
8484
try {
8585
const disposable = await this.loadSnippetsFile(snippetsFile)
86-
this.packageDisposables.has(bundle)
87-
? this.packageDisposables.get(bundle).add(disposable)
88-
: this.packageDisposables.set(bundle, new CompositeDisposable(disposable))
86+
this.packageDisposables.has(pack)
87+
? this.packageDisposables.get(pack).add(disposable)
88+
: this.packageDisposables.set(pack, new CompositeDisposable(disposable))
8989
} catch (error) {
9090
atom.notifications.addWarning(`Unable to load snippets from: '${snippetsFile}'`, {
9191
description: 'Make sure you have permissions to access the directory and file.',
@@ -107,10 +107,10 @@ module.exports = class Snippets {
107107
}
108108
}
109109

110-
static unloadPackage (bundle) {
111-
if (this.packageDisposables.has(bundle)) {
112-
this.packageDisposables.get(bundle).dispose()
113-
this.packageDisposables.delete(bundle)
110+
static unloadPackage (pack) {
111+
if (this.packageDisposables.has(pack)) {
112+
this.packageDisposables.get(pack).dispose()
113+
this.packageDisposables.delete(pack)
114114
}
115115
}
116116

0 commit comments

Comments
 (0)