fixed jump to note

This commit is contained in:
azivner 2017-11-19 20:36:13 -05:00
parent 658f4872af
commit c8aaf6085d
6 changed files with 39 additions and 25 deletions

View File

@ -31,7 +31,7 @@ const addLink = (function() {
minLength: 0, minLength: 0,
change: () => { change: () => {
const val = autoCompleteEl.val(); const val = autoCompleteEl.val();
const noteId = link.getNodeIdFromLabel(val); const noteId = link.getNodePathFromLabel(val);
if (noteId) { if (noteId) {
setDefaultLinkTitle(noteId); setDefaultLinkTitle(noteId);
@ -40,7 +40,7 @@ const addLink = (function() {
// this is called when user goes through autocomplete list with keyboard // 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 // at this point the item isn't selected yet so we use supplied ui.item to see where the cursor is
focus: (event, ui) => { focus: (event, ui) => {
const noteId = link.getNodeIdFromLabel(ui.item.value); const noteId = link.getNodePathFromLabel(ui.item.value);
setDefaultLinkTitle(noteId); setDefaultLinkTitle(noteId);
} }
@ -50,7 +50,7 @@ const addLink = (function() {
formEl.submit(() => { formEl.submit(() => {
let val = autoCompleteEl.val(); let val = autoCompleteEl.val();
const noteId = link.getNodeIdFromLabel(val); const noteId = link.getNodePathFromLabel(val);
if (noteId) { if (noteId) {
const linkTitle = linkTitleEl.val(); const linkTitle = linkTitleEl.val();

View File

@ -5,7 +5,7 @@ const jumpToNote = (function() {
const autoCompleteEl = $("#jump-to-note-autocomplete"); const autoCompleteEl = $("#jump-to-note-autocomplete");
const formEl = $("#jump-to-note-form"); const formEl = $("#jump-to-note-form");
function showDialog() { async function showDialog() {
glob.activeDialog = dialogEl; glob.activeDialog = dialogEl;
autoCompleteEl.val(''); autoCompleteEl.val('');
@ -15,22 +15,30 @@ const jumpToNote = (function() {
width: 800 width: 800
}); });
autoCompleteEl.autocomplete({ await autoCompleteEl.autocomplete({
source: noteTree.getAutocompleteItems(), source: noteTree.getAutocompleteItems(),
minLength: 0 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); $(document).bind('keydown', 'alt+j', showDialog);
formEl.submit(() => { formEl.submit(() => {
const val = autoCompleteEl.val(); const action = dialogEl.find("button:focus").val();
const noteId = link.getNodeIdFromLabel(val);
if (noteId) { if (action === 'jump') {
noteTree.activateNode(noteId); goToNote();
dialogEl.dialog('close');
} }
return false; return false;

View File

@ -79,7 +79,7 @@ $.ui.autocomplete.filter = (array, terms) => {
$(document).tooltip({ $(document).tooltip({
items: ".note-editable a", items: ".note-editable a",
content: function(callback) { content: function(callback) {
const noteId = link.getNoteIdFromLink($(this).attr("href")); const noteId = link.getNotePathFromLink($(this).attr("href"));
if (noteId !== null) { if (noteId !== null) {
noteEditor.loadNote(noteId).then(note => callback(note.detail.note_text)); noteEditor.loadNote(noteId).then(note => callback(note.detail.note_text));

View File

@ -1,22 +1,22 @@
"use strict"; "use strict";
const link = (function() { const link = (function() {
function getNoteIdFromLink(url) { function getNotePathFromLink(url) {
const noteIdMatch = /app#([A-Za-z0-9]+)$/.exec(url); const notePathMatch = /app#([A-Za-z0-9/]+)$/.exec(url);
if (noteIdMatch === null) { if (notePathMatch === null) {
return null; return null;
} }
else { else {
return noteIdMatch[1]; return notePathMatch[1];
} }
} }
function getNodeIdFromLabel(label) { function getNodePathFromLabel(label) {
const noteIdMatch = / \(([A-Za-z0-9]+)\)/.exec(label); const notePathMatch = / \(([A-Za-z0-9/]+)\)/.exec(label);
if (noteIdMatch !== null) { if (notePathMatch !== null) {
return noteIdMatch[1]; return notePathMatch[1];
} }
return null; return null;
@ -37,7 +37,7 @@ const link = (function() {
let noteId = linkEl.attr("note-id"); let noteId = linkEl.attr("note-id");
if (!noteId) { if (!noteId) {
noteId = getNoteIdFromLink(linkEl.attr('href')); noteId = getNotePathFromLink(linkEl.attr('href'));
} }
if (noteId) { if (noteId) {
@ -64,8 +64,8 @@ const link = (function() {
$(document).on('dblclick', '.note-editable a, div.ui-tooltip-content', goToInternalNote); $(document).on('dblclick', '.note-editable a, div.ui-tooltip-content', goToInternalNote);
return { return {
getNodeIdFromLabel, getNodePathFromLabel,
getNoteIdFromLink, getNotePathFromLink,
createNoteLink createNoteLink
}; };
})(); })();

View File

@ -468,7 +468,7 @@ const noteTree = (function() {
const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId); const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId);
autocompleteItems.push({ autocompleteItems.push({
value: childNotePath, value: childTitlePath + ' (' + childNotePath + ')',
label: childTitlePath label: childTitlePath
}); });

View File

@ -137,7 +137,13 @@
<input id="jump-to-note-autocomplete" style="width: 100%;"> <input id="jump-to-note-autocomplete" style="width: 100%;">
</div> </div>
<button class="btn btn-sm">Jump</button> <button name="action" value="jump" class="btn btn-sm">Jump</button>
<button name="action" value="add-link" class="btn btn-sm">Add link</button>
<button name="action" value="add-current-as-child" class="btn btn-sm">Add current as child</button>
<button name="action" value="add-selected-as-child" class="btn btn-sm">Add selected as child</button>
</form> </form>
</div> </div>