Open Skydancer9 opened 2 years ago
No, but you can define a custom command in your init.js
to do this.
Haven't tested this, but here's how your example could work:
atom.commands.add('atom-text-editor', {
'custom:some-command': () => {
let editor = atom.workspace.getActiveTextEditor();
let selection = editor.getLastSelection();
let output = `<a epub:type="noteref" role="doc-noteref" href="#fn${selection} id="ref${selection}">${selection}</a>`;
selection.insertText(output);
}
});
Feel free to name it whatever you want, of course. Then you could map it to a keystroke in your keymap.cson
:
'atom-text-editor':
'ctrl-shift-0': 'custom:some-command'
There's a similar programmatic interface to the snippets module, so you could define a snippet on-the-fly that incorporates the selection. But in your example, there's no reason to do so; it's simpler to do it with Atom's built-in APIs.
@savetheclocktower Thank you!
Hi, Sorry for my beginner's question. Is it possible to wrap selected text in snippet code? Example: Select some text, for example number 10 below:
<p>Some text<sup>10</sup></p>
AFTER (inserts a snippet and adds the selected number 10 in three places):
<p>Some text<sup><a epub:type="noteref" role="doc-noteref" href="#fn10" id="ref10">10</a></sup></p>