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

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
MCStreetguy committed Jul 28, 2017
2 parents 5ec5d10 + b56a289 commit 1d95755
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 24 deletions.
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/icon-helper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 40 additions & 17 deletions lib/snippet-injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}
};
16 changes: 12 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -159,14 +164,17 @@ export default class Util {
listDOMstring += IconHelper.getIconTag('default');
}
}
listDOMstring += '<p class="value">';
listDOMstring += currentValue;
listDOMstring += '<p class="value" data-id="'+currentValue.uid+'">';
listDOMstring += currentValue.title;
listDOMstring += '</p></li>';
});
} else {
listDOMstring += '<li class="notice"><i>'+options.nothingfound+'</i></li>';
}
$('#prompt-list').append(listDOMstring);
if(options.icons.length > 0) {
IconHelper.colorize('colored-svg');
}
});
var handleCancel = function(e) {
window.removeEventListener('keyup',handleKey,true);
Expand Down

0 comments on commit 1d95755

Please sign in to comment.