From c8aaf6085d2a6c3a16385dd384c176179065f1e3 Mon Sep 17 00:00:00 2001 From: azivner Date: Sun, 19 Nov 2017 20:36:13 -0500 Subject: [PATCH] fixed jump to note --- public/javascripts/dialogs/add_link.js | 6 +++--- public/javascripts/dialogs/jump_to_note.js | 24 ++++++++++++++-------- public/javascripts/init.js | 2 +- public/javascripts/link.js | 22 ++++++++++---------- public/javascripts/note_tree.js | 2 +- views/index.ejs | 8 +++++++- 6 files changed, 39 insertions(+), 25 deletions(-) diff --git a/public/javascripts/dialogs/add_link.js b/public/javascripts/dialogs/add_link.js index 02f3c43c2..aeed99bd6 100644 --- a/public/javascripts/dialogs/add_link.js +++ b/public/javascripts/dialogs/add_link.js @@ -31,7 +31,7 @@ const addLink = (function() { minLength: 0, change: () => { const val = autoCompleteEl.val(); - const noteId = link.getNodeIdFromLabel(val); + const noteId = link.getNodePathFromLabel(val); if (noteId) { setDefaultLinkTitle(noteId); @@ -40,7 +40,7 @@ const addLink = (function() { // this is called when user goes through autocomplete list with keyboard // at this point the item isn't selected yet so we use supplied ui.item to see where the cursor is focus: (event, ui) => { - const noteId = link.getNodeIdFromLabel(ui.item.value); + const noteId = link.getNodePathFromLabel(ui.item.value); setDefaultLinkTitle(noteId); } @@ -50,7 +50,7 @@ const addLink = (function() { formEl.submit(() => { let val = autoCompleteEl.val(); - const noteId = link.getNodeIdFromLabel(val); + const noteId = link.getNodePathFromLabel(val); if (noteId) { const linkTitle = linkTitleEl.val(); diff --git a/public/javascripts/dialogs/jump_to_note.js b/public/javascripts/dialogs/jump_to_note.js index 8051fd8d2..50c232c8e 100644 --- a/public/javascripts/dialogs/jump_to_note.js +++ b/public/javascripts/dialogs/jump_to_note.js @@ -5,7 +5,7 @@ const jumpToNote = (function() { const autoCompleteEl = $("#jump-to-note-autocomplete"); const formEl = $("#jump-to-note-form"); - function showDialog() { + async function showDialog() { glob.activeDialog = dialogEl; autoCompleteEl.val(''); @@ -15,22 +15,30 @@ const jumpToNote = (function() { width: 800 }); - autoCompleteEl.autocomplete({ + await autoCompleteEl.autocomplete({ source: noteTree.getAutocompleteItems(), minLength: 0 }); } + function goToNote() { + const val = autoCompleteEl.val(); + const notePath = link.getNodePathFromLabel(val); + + if (notePath) { + noteTree.activateNode(notePath); + + dialogEl.dialog('close'); + } + } + $(document).bind('keydown', 'alt+j', showDialog); formEl.submit(() => { - const val = autoCompleteEl.val(); - const noteId = link.getNodeIdFromLabel(val); + const action = dialogEl.find("button:focus").val(); - if (noteId) { - noteTree.activateNode(noteId); - - dialogEl.dialog('close'); + if (action === 'jump') { + goToNote(); } return false; diff --git a/public/javascripts/init.js b/public/javascripts/init.js index c96fea726..490c98b12 100644 --- a/public/javascripts/init.js +++ b/public/javascripts/init.js @@ -79,7 +79,7 @@ $.ui.autocomplete.filter = (array, terms) => { $(document).tooltip({ items: ".note-editable a", content: function(callback) { - const noteId = link.getNoteIdFromLink($(this).attr("href")); + const noteId = link.getNotePathFromLink($(this).attr("href")); if (noteId !== null) { noteEditor.loadNote(noteId).then(note => callback(note.detail.note_text)); diff --git a/public/javascripts/link.js b/public/javascripts/link.js index 541f401d6..580005b92 100644 --- a/public/javascripts/link.js +++ b/public/javascripts/link.js @@ -1,22 +1,22 @@ "use strict"; const link = (function() { - function getNoteIdFromLink(url) { - const noteIdMatch = /app#([A-Za-z0-9]+)$/.exec(url); + function getNotePathFromLink(url) { + const notePathMatch = /app#([A-Za-z0-9/]+)$/.exec(url); - if (noteIdMatch === null) { + if (notePathMatch === null) { return null; } else { - return noteIdMatch[1]; + return notePathMatch[1]; } } - function getNodeIdFromLabel(label) { - const noteIdMatch = / \(([A-Za-z0-9]+)\)/.exec(label); + function getNodePathFromLabel(label) { + const notePathMatch = / \(([A-Za-z0-9/]+)\)/.exec(label); - if (noteIdMatch !== null) { - return noteIdMatch[1]; + if (notePathMatch !== null) { + return notePathMatch[1]; } return null; @@ -37,7 +37,7 @@ const link = (function() { let noteId = linkEl.attr("note-id"); if (!noteId) { - noteId = getNoteIdFromLink(linkEl.attr('href')); + noteId = getNotePathFromLink(linkEl.attr('href')); } if (noteId) { @@ -64,8 +64,8 @@ const link = (function() { $(document).on('dblclick', '.note-editable a, div.ui-tooltip-content', goToInternalNote); return { - getNodeIdFromLabel, - getNoteIdFromLink, + getNodePathFromLabel, + getNotePathFromLink, createNoteLink }; })(); \ No newline at end of file diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.js index 05bf3b325..574f2903b 100644 --- a/public/javascripts/note_tree.js +++ b/public/javascripts/note_tree.js @@ -468,7 +468,7 @@ const noteTree = (function() { const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId); autocompleteItems.push({ - value: childNotePath, + value: childTitlePath + ' (' + childNotePath + ')', label: childTitlePath }); diff --git a/views/index.ejs b/views/index.ejs index df64f280e..c1337dbc1 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -137,7 +137,13 @@ - + + + + + + +