Skip to content

Build your personal knowledge base with Trilium Notes

initial implementation of link dialog (buggy and feature incomplete)

azivner169825abfff5
diff --git a/src/templates/app.html b/src/templates/app.html
index 3171ea999e..426c95298b 100644
--- a/src/templates/app.html
+++ b/src/templates/app.html
@@ -84,6 +84,22 @@
</select>
</div>
+ <div id="insertLinkDialog" title="Recent notes" style="display: none;">
+ <form>
+ <div class="form-group">
+ <label for="noteAutocomplete">Link to note</label>
+ <input id="noteAutocomplete" style="width: 100%;">
+ </div>
+
+ <div class="form-group">
+ <label for="linkTitle">Link title</label>
+ <input id="linkTitle" style="width: 100%;">
+ </div>
+
+ <button id="addLinkButton" class="btn btn-sm">Add link</button>
+ </form>
+ </div>
+
<script type="text/javascript">
const baseUrl = '';
</script>
diff --git a/static/js/init.js b/static/js/init.js
index feec14292a..404b4a4c99 100644
--- a/static/js/init.js
+++ b/static/js/init.js
@@ -92,4 +92,61 @@ $(document).on('click', 'div.popover-content a', function(e) {
e.preventDefault();
}
+});
+
+let linkInfo;
+
+$(document).bind('keydown', 'alt+l', function() {
+ $("#insertLinkDialog").dialog({
+ modal: true
+ });
+
+ let autocompleteItems = [];
+
+ for (let noteId in globalNoteNames) {
+ autocompleteItems.push({
+ value: globalNoteNames[noteId] + " (" + noteId + ")",
+ label: globalNoteNames[noteId]
+ });
+ }
+
+ $("#noteAutocomplete").autocomplete({
+ source: autocompleteItems,
+ change: function(event, ui) {
+ let val = $("#noteAutocomplete").val();
+
+ val = val.replace(/ \([A-Za-z0-9]{22}\)/, "");
+
+ $("#linkTitle").val(val);
+ }
+ });
+
+ //const noteDetail = $('#noteDetail');
+
+ //linkInfo = noteDetail.summernote('invoke', 'editor.getLinkInfo');
+ //noteDetail.summernote('invoke', 'editor.saveRange');
+});
+
+$("#addLinkButton").click(function() {
+ let val = $("#noteAutocomplete").val();
+
+ const noteIdMatch = / \(([A-Za-z0-9]{22})\)/.exec(val);
+
+ if (noteIdMatch !== null) {
+ const noteId = noteIdMatch[1];
+ const linkTitle = $("#linkTitle").val();
+
+ const noteDetail = $('#noteDetail');
+
+ noteDetail.summernote('createLink', {
+ text: globalNoteNames[noteId],
+ url: 'app#' + noteId,
+ isNewWindow: true
+// range: linkInfo.range
+ });
+
+ //noteDetail.summernote('invoke', 'editor.restoreRange');
+
+ $("#insertLinkDialog").dialog("close");
+ }
});
\ No newline at end of file