added: complete snippet on tab
This commit is contained in:
parent
b41f7e2e5f
commit
968df214f7
20
main.js
20
main.js
|
@ -2642,6 +2642,23 @@ function boldify()
|
|||
md.setSelectionRange(pos.start + offset, pos.end + offset);
|
||||
}
|
||||
|
||||
function snippetautocomplete()
|
||||
{
|
||||
var tocursor = md.value.substr(0, md.selectionStart)
|
||||
var slashindex = tocursor.lastIndexOf("/");
|
||||
if (slashindex > tocursor.lastIndexOf(" ") && slashindex > tocursor.lastIndexOf("\n"))
|
||||
{
|
||||
var commandbegin = tocursor.substr(slashindex);
|
||||
var snippet = snippets.find(s => s.command.startsWith(commandbegin));
|
||||
if (snippet)
|
||||
{
|
||||
insert(snippet.insert, snippet.cursor, commandbegin.length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function mainkeydownhandler()
|
||||
{
|
||||
if (event.key == "Escape")
|
||||
|
@ -2798,6 +2815,8 @@ function editorkeydown()
|
|||
else if (event.key === "Tab")
|
||||
{
|
||||
event.preventDefault();
|
||||
if (!snippetautocomplete())
|
||||
{
|
||||
var init = currentrange();
|
||||
var range = getlinesrange();
|
||||
range.start--;
|
||||
|
@ -2829,6 +2848,7 @@ function editorkeydown()
|
|||
md.selectionStart = init.start + shift;
|
||||
md.selectionEnd = init.end + (newtext.length - selection.length);
|
||||
}
|
||||
}
|
||||
else if (event.key === "[" && before(1) == "[")
|
||||
{
|
||||
event.preventDefault();
|
||||
|
|
Loading…
Reference in New Issue