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

Commit 40b59f3

Browse files
committed
FIX: Debug output
1 parent 5b69e8b commit 40b59f3

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

lib/snippet-injector.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,39 +121,55 @@ export default {
121121
},
122122

123123
create() {
124-
console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group'));
125-
console.time("snippet-injector:create duration");
124+
if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') {
125+
console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group'));
126+
console.time("snippet-injector:create duration");
127+
}
126128

127129
var selection = atom.workspace.getActiveTextEditor().getSelectedText();
128130
var grammar = atom.workspace.getActiveTextEditor().getGrammar().name;
129131
var storage = this.storage;
130132
const inputPrompt = Util.promptUser({
131-
placeholder: 'Enter snippet title',
133+
placeholder: 'Enter snippet title #and #add #tags',
132134
btnconfirm: 'Save snippet',
133135
btncancel: 'Cancel'
134136
},function(text){
135137
if(Util.isset(text,'string')) {
138+
var tags = new Array();
139+
var title = text.split(' ').filter(function(element,index,array) {
140+
if(element.startsWith('#')) {
141+
tags.push(element.substring(1));
142+
return false;
143+
} else {
144+
return true;
145+
}
146+
}).join(' ');
136147
var result = storage.store(new Snippet({
137-
title: text,
148+
title: title,
149+
tags: tags,
138150
content: selection,
139151
lang: grammar,
140152
version: Util.getPackageVersion()
141153
}));
142154
if(result) {
143-
atom.notifications.addSuccess('Snippet "'+text+'" was saved successfully.', null);
155+
atom.notifications.addSuccess('Snippet "'+title+'" was saved successfully.', null);
144156
} else {
145-
atom.notifications.addError('An Error occured while saving the snippet "'+text+'".', null);
157+
atom.notifications.addError('An Error occured while saving the snippet "'+title+'".', null);
146158
}
147159
}
148160
});
149161

150-
console.timeEnd("snippet-injector:create duration");
151-
console.groupEnd();
162+
if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') {
163+
console.timeEnd("snippet-injector:create duration");
164+
console.groupEnd();
165+
}
152166
},
153167

154168
insert() {
155-
console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group'));
156-
console.time("snippet-injector:insert duration");
169+
if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') {
170+
console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group'));
171+
console.time("snippet-injector:insert duration");
172+
}
157173

158174
var storage = this.storage;
159175
var filenames = storage.retrieveFiles();
@@ -193,13 +209,17 @@ export default {
193209
atom.notifications.addWarning('No snippets found in the local storage directory.', null);
194210
}
195211

196-
console.timeEnd("snippet-injector:insert duration");
197-
console.groupEnd();
212+
if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') {
213+
console.timeEnd("snippet-injector:insert duration");
214+
console.groupEnd();
215+
}
198216
},
199217

200218
delete() {
201-
console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group'));
202-
console.time("snippet-injector:delete duration");
219+
if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') {
220+
console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group'));
221+
console.time("snippet-injector:delete duration");
222+
}
203223

204224
var storage = this.storage;
205225
var fileNames = storage.retrieveFiles();
@@ -233,7 +253,9 @@ export default {
233253
atom.notifications.addWarning('No snippets found in the local storage directory.', null);
234254
}
235255

236-
console.timeEnd("snippet-injector:delete duration");
237-
console.groupEnd();
256+
if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') {
257+
console.timeEnd("snippet-injector:delete duration");
258+
console.groupEnd();
259+
}
238260
}
239261
};

0 commit comments

Comments
 (0)