diff --git a/assets/editor.js b/assets/editor.js index 0277ba4..a356792 100644 --- a/assets/editor.js +++ b/assets/editor.js @@ -53,6 +53,45 @@ if (result) applyResult(result); } + function promptDisplayText(initial, onDone) { + var input = document.createElement('input'); + input.type = 'text'; + input.className = 'modal-input'; + input.placeholder = 'Display text (optional)'; + if (initial) input.value = initial; + var handle = openModal({ + title: 'Insert link — display text?', + body: input, + confirm: { + label: 'INSERT', + onConfirm: function () { + handle.close(); + onDone(input.value.trim()); + } + } + }); + } + + function insertWikilink() { + var sel = textarea.value.slice(textarea.selectionStart, textarea.selectionEnd); + openTreePicker({ + title: 'Insert link', + mode: 'any', + initialPath: '/', + confirmLabel: 'NEXT', + onSelect: function (path, kind) { + if (kind === 'folder') { + promptDisplayText(sel, function (display) { + insertAtCursor(display ? '[[' + path + '|' + display + ']]' : '[[' + path + ']]'); + }); + } else { + var name = path.split('/').pop(); + insertAtCursor('[' + (sel || name) + '](' + path + ')'); + } + } + }); + } + // --- Actions --- var T = EditorTables; @@ -71,23 +110,7 @@ codeblock: function () { wrap('```\n', '\n```', 'code'); }, quote: function () { linePrefix('> '); }, link: function () { wrap('[', '](url)', 'link text'); }, - wikilink: function () { - var sel = textarea.value.slice(textarea.selectionStart, textarea.selectionEnd); - openTreePicker({ - title: 'Insert link', - mode: 'any', - initialPath: '/', - confirmLabel: 'INSERT', - onSelect: function (path, kind) { - if (kind === 'folder') { - insertAtCursor(sel ? '[[' + path + '|' + sel + ']]' : '[[' + path + ']]'); - } else { - var name = path.split('/').pop(); - insertAtCursor('[' + (sel || name) + '](' + path + ')'); - } - } - }); - }, + wikilink: insertWikilink, ul: function () { linePrefix('- '); }, ol: function () { linePrefix('1. '); }, hr: function () { wrap('\n\n---\n\n', '', ''); }, diff --git a/assets/tree-picker.js b/assets/tree-picker.js index b63f66b..6721e2d 100644 --- a/assets/tree-picker.js +++ b/assets/tree-picker.js @@ -138,6 +138,13 @@ } }); + if (kind === 'folder') { + row.addEventListener('dblclick', function (e) { + e.preventDefault(); + if (isOpen) collapse(); else expand(); + }); + } + return { rowEl: row, name: name,