forked from Komodo/macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomagic_snippets_from_text.js
29 lines (28 loc) · 1.02 KB
/
automagic_snippets_from_text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Create a snippet from selected text, add a name and automatically open
* properties to add keybinding.
*
* A popup UI allows creation of the snippet name
*
* Type: keybound
* Usage: Add a keybinding of your liking in it's properties
*
* @source https://github.com/Komodo/macros
* @author Carey Hoffman
* @version 0.1
*/
// Create a base snippet with the selected text
scimoz = ko.views.manager.currentView.scimoz;
var snip =
ko.projects.addSnippetFromText(scimoz.selText);
//create a date to be used as a unique name on the snippet
var d = new Date();
// Create a unique default name string
var defaultName = "New Snippet - " + d.toLocaleTimeString().substr(0,8).trim()
// Ask for a name or provide the unique default
var name = ko.interpolate.interpolateStrings("%(ask:Snippet Name: " +
defaultName + ")")
// Assign the name to the snippet name attribute
snip.name = name;
// Open the snippet options to set a keybinding
ko.projects.snippetProperties(snip);