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,
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();

View file

@ -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;

View file

@ -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));

View file

@ -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
};
})();

View file

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

View file

@ -137,7 +137,13 @@
<input id="jump-to-note-autocomplete" style="width: 100%;">
</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>
</div>