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

Commit 1d95755

Browse files
committed
Merge branch 'dev'
2 parents 5ec5d10 + b56a289 commit 1d95755

File tree

4 files changed

+70
-24
lines changed

4 files changed

+70
-24
lines changed

CHANGELOG.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22

33
-----------
44

5-
## v1.1.*
5+
## v1.2.*
66
**latest release**
77
#### Features
8+
- Snippet tag functionalities
9+
#### Improvements
10+
11+
#### Patches
12+
- Debug output
13+
- Search prompt
14+
15+
16+
---
17+
18+
## v1.1.*
19+
**stable release**
20+
#### Features
821
- Debug functionalities *(for easier bug reporting)*
922
- Snippet class:
1023
- (+) Author
@@ -18,11 +31,13 @@
1831
- Migration even if there were no changes made
1932
- Debug snippet logging
2033
- jQuery module bug
34+
- Storage bug
35+
2136

2237
---
2338

2439
## v1.0.*
25-
**stable release**
40+
2641
#### Features
2742
- Snippet class:
2843
- (+) UID

lib/icon-helper.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/snippet-injector.js

Lines changed: 40 additions & 17 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();
@@ -164,7 +180,8 @@ export default {
164180
var elem = new Snippet(JSON.parse(storage.retrieveFile(currentValue.replace('.json',''))));
165181
listitems.push({
166182
title: elem.getTitle(),
167-
uid: elem.getUID()
183+
uid: elem.getUID(),
184+
tags: elem.getTags()
168185
});
169186
icons.push(elem.getLang());
170187
});
@@ -193,13 +210,17 @@ export default {
193210
atom.notifications.addWarning('No snippets found in the local storage directory.', null);
194211
}
195212

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

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

204225
var storage = this.storage;
205226
var fileNames = storage.retrieveFiles();
@@ -233,7 +254,9 @@ export default {
233254
atom.notifications.addWarning('No snippets found in the local storage directory.', null);
234255
}
235256

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

lib/util.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,15 @@ export default class Util {
140140
var text = edit.getText();
141141
$('#prompt-list').find('.list-item, .notice').remove();
142142
var filteredItems = options.listItems.filter(function(element) {
143-
element = element.toLowerCase();
144143
text = text.toLowerCase();
145144
if(text !== '' && text !== ' ' && text !== null && text !== undefined) {
146-
return (element.indexOf(text) > -1 ? true : false);
145+
var title = element.title.toLowerCase();
146+
var tags = element.tags.join(' ').toLowerCase();
147+
if(text.startsWith('#')) {
148+
return (tags.indexOf(text.split('#').join('')) > -1 ? true : false);
149+
} else {
150+
return (title.indexOf(text) > -1 ? true : false);
151+
}
147152
} else {
148153
return true;
149154
}
@@ -159,14 +164,17 @@ export default class Util {
159164
listDOMstring += IconHelper.getIconTag('default');
160165
}
161166
}
162-
listDOMstring += '<p class="value">';
163-
listDOMstring += currentValue;
167+
listDOMstring += '<p class="value" data-id="'+currentValue.uid+'">';
168+
listDOMstring += currentValue.title;
164169
listDOMstring += '</p></li>';
165170
});
166171
} else {
167172
listDOMstring += '<li class="notice"><i>'+options.nothingfound+'</i></li>';
168173
}
169174
$('#prompt-list').append(listDOMstring);
175+
if(options.icons.length > 0) {
176+
IconHelper.colorize('colored-svg');
177+
}
170178
});
171179
var handleCancel = function(e) {
172180
window.removeEventListener('keyup',handleKey,true);

0 commit comments

Comments
 (0)