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

Commit 5aea6cf

Browse files
committed
Started adding language property to snippets
1 parent da388dd commit 5aea6cf

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/snippet-injector.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default {
3636

3737
create() {
3838
var selection = atom.workspace.getActiveTextEditor().getSelectedText();
39+
var grammar = atom.workspace.getActiveTextEditor().getGrammar();
3940
var storage = this.storage;
4041
const inputPrompt = Util.promptUser({
4142
placeholder: 'Enter snippet title',
@@ -46,7 +47,8 @@ export default {
4647
var result = storage.store(new Snippet({
4748
title: text,
4849
tags: new Array(),
49-
content: selection
50+
content: selection,
51+
lang: grammar
5052
}));
5153
if(result) {
5254
atom.notifications.addSuccess('Snippet "'+text+'" was saved successfully.', null);

lib/snippet.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ export default class Snippet {
55
content = '';
66
title = '';
77
tags = new Array();
8+
lang = '';
89

910
constructor(state) {
1011
if(state !== undefined && state !== null && typeof state === 'object') {
1112
this.title = state.title;
1213
this.tags = state.tags;
1314
this.content = state.content;
15+
this.lang = state.lang;
1416
} else {
1517
this.title = "";
1618
this.tags = new Array();
1719
this.content = "";
20+
tis.lang = "";
1821
}
1922
}
2023

@@ -23,14 +26,15 @@ export default class Snippet {
2326
return {
2427
'title':this.title,
2528
'tags':this.tags,
26-
'content':this.content
29+
'content':this.content,
30+
'lang':this.lang
2731
};
2832
}
2933

3034
// Tear down any state and detach
3135
destroy() {}
3236

33-
37+
3438
getTitle() {
3539
return this.title;
3640
}
@@ -43,4 +47,7 @@ export default class Snippet {
4347
return this.tags;
4448
}
4549

50+
getLang() {
51+
return this.lang;
52+
}
4653
}

0 commit comments

Comments
 (0)