Refinements for tree picker
This commit is contained in:
+40
-17
@@ -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', '', ''); },
|
||||
|
||||
@@ -138,6 +138,13 @@
|
||||
}
|
||||
});
|
||||
|
||||
if (kind === 'folder') {
|
||||
row.addEventListener('dblclick', function (e) {
|
||||
e.preventDefault();
|
||||
if (isOpen) collapse(); else expand();
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
rowEl: row,
|
||||
name: name,
|
||||
|
||||
Reference in New Issue
Block a user