diff --git a/CHANGELOG.md b/CHANGELOG.md index 84183fa..c4eb030 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,22 @@ ----------- -## v1.1.* +## v1.2.* **latest release** #### Features +- Snippet tag functionalities +#### Improvements + +#### Patches +- Debug output +- Search prompt + + +--- + +## v1.1.* +**stable release** +#### Features - Debug functionalities *(for easier bug reporting)* - Snippet class: - (+) Author @@ -18,11 +31,13 @@ - Migration even if there were no changes made - Debug snippet logging - jQuery module bug +- Storage bug + --- ## v1.0.* -**stable release** + #### Features - Snippet class: - (+) UID diff --git a/lib/icon-helper.js b/lib/icon-helper.js index c0f4ce5..d656d37 100644 --- a/lib/icon-helper.js +++ b/lib/icon-helper.js @@ -101,7 +101,7 @@ export default class IconHelper { * (http://konpa.github.io/devicon/) */ // markdown icon - return ''; + return ''; break; // case 'Go': /** diff --git a/lib/snippet-injector.js b/lib/snippet-injector.js index c4f5351..1b5f55c 100644 --- a/lib/snippet-injector.js +++ b/lib/snippet-injector.js @@ -121,39 +121,55 @@ export default { }, create() { - console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group')); - console.time("snippet-injector:create duration"); + if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') { + console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group')); + console.time("snippet-injector:create duration"); + } var selection = atom.workspace.getActiveTextEditor().getSelectedText(); var grammar = atom.workspace.getActiveTextEditor().getGrammar().name; var storage = this.storage; const inputPrompt = Util.promptUser({ - placeholder: 'Enter snippet title', + placeholder: 'Enter snippet title #and #add #tags', btnconfirm: 'Save snippet', btncancel: 'Cancel' },function(text){ if(Util.isset(text,'string')) { + var tags = new Array(); + var title = text.split(' ').filter(function(element,index,array) { + if(element.startsWith('#')) { + tags.push(element.substring(1)); + return false; + } else { + return true; + } + }).join(' '); var result = storage.store(new Snippet({ - title: text, + title: title, + tags: tags, content: selection, lang: grammar, version: Util.getPackageVersion() })); if(result) { - atom.notifications.addSuccess('Snippet "'+text+'" was saved successfully.', null); + atom.notifications.addSuccess('Snippet "'+title+'" was saved successfully.', null); } else { - atom.notifications.addError('An Error occured while saving the snippet "'+text+'".', null); + atom.notifications.addError('An Error occured while saving the snippet "'+title+'".', null); } } }); - console.timeEnd("snippet-injector:create duration"); - console.groupEnd(); + if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') { + console.timeEnd("snippet-injector:create duration"); + console.groupEnd(); + } }, insert() { - console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group')); - console.time("snippet-injector:insert duration"); + if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') { + console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group')); + console.time("snippet-injector:insert duration"); + } var storage = this.storage; var filenames = storage.retrieveFiles(); @@ -164,7 +180,8 @@ export default { var elem = new Snippet(JSON.parse(storage.retrieveFile(currentValue.replace('.json','')))); listitems.push({ title: elem.getTitle(), - uid: elem.getUID() + uid: elem.getUID(), + tags: elem.getTags() }); icons.push(elem.getLang()); }); @@ -193,13 +210,17 @@ export default { atom.notifications.addWarning('No snippets found in the local storage directory.', null); } - console.timeEnd("snippet-injector:insert duration"); - console.groupEnd(); + if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') { + console.timeEnd("snippet-injector:insert duration"); + console.groupEnd(); + } }, delete() { - console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group')); - console.time("snippet-injector:delete duration"); + if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') { + console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group')); + console.time("snippet-injector:delete duration"); + } var storage = this.storage; var fileNames = storage.retrieveFiles(); @@ -233,7 +254,9 @@ export default { atom.notifications.addWarning('No snippets found in the local storage directory.', null); } - console.timeEnd("snippet-injector:delete duration"); - console.groupEnd(); + if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') { + console.timeEnd("snippet-injector:delete duration"); + console.groupEnd(); + } } }; diff --git a/lib/util.js b/lib/util.js index b1aec35..0458dd9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -140,10 +140,15 @@ export default class Util { var text = edit.getText(); $('#prompt-list').find('.list-item, .notice').remove(); var filteredItems = options.listItems.filter(function(element) { - element = element.toLowerCase(); text = text.toLowerCase(); if(text !== '' && text !== ' ' && text !== null && text !== undefined) { - return (element.indexOf(text) > -1 ? true : false); + var title = element.title.toLowerCase(); + var tags = element.tags.join(' ').toLowerCase(); + if(text.startsWith('#')) { + return (tags.indexOf(text.split('#').join('')) > -1 ? true : false); + } else { + return (title.indexOf(text) > -1 ? true : false); + } } else { return true; } @@ -159,14 +164,17 @@ export default class Util { listDOMstring += IconHelper.getIconTag('default'); } } - listDOMstring += '

'; - listDOMstring += currentValue; + listDOMstring += '

'; + listDOMstring += currentValue.title; listDOMstring += '

'; }); } else { listDOMstring += '
  • '+options.nothingfound+'
  • '; } $('#prompt-list').append(listDOMstring); + if(options.icons.length > 0) { + IconHelper.colorize('colored-svg'); + } }); var handleCancel = function(e) { window.removeEventListener('keyup',handleKey,true);