added jump to note functionality

This commit is contained in:
azivner 2017-09-03 21:34:30 -04:00
parent f063d12d07
commit a54207dc07
3 changed files with 56 additions and 16 deletions

View File

@ -109,7 +109,18 @@
<input id="linkTitle" style="width: 100%;"> <input id="linkTitle" style="width: 100%;">
</div> </div>
<button id="addLinkButton" class="btn btn-sm">Add link</button> <button class="btn btn-sm">Add link</button>
</form>
</div>
<div id="jumpToNoteDialog" title="Jumpt to note" style="display: none;">
<form id="jumpToNoteForm">
<div class="form-group">
<label for="jumpToNoteAutocomplete">Jump to note</label>
<input id="jumpToNoteAutocomplete" style="width: 100%;">
</div>
<button class="btn btn-sm">Jump</button>
</form> </form>
</div> </div>

View File

@ -84,8 +84,6 @@ function html2notecase(contents, note) {
const linkMatch = /^<a[^>]+?href="([^"]+?)"[^>]*?>([^<]+?)<\/a>/.exec(curContent); const linkMatch = /^<a[^>]+?href="([^"]+?)"[^>]*?>([^<]+?)<\/a>/.exec(curContent);
if (linkMatch !== null) { if (linkMatch !== null) {
console.log("matched link: ", linkMatch);
const targetUrl = linkMatch[1]; const targetUrl = linkMatch[1];
const linkText = linkMatch[2]; const linkText = linkMatch[2];

View File

@ -107,6 +107,21 @@ function getNodeIdFromLabel(label) {
return null; return null;
} }
function getAutocompleteItems() {
const autocompleteItems = [];
for (const noteId of globalAllNoteIds) {
const fullName = getFullName(noteId);
autocompleteItems.push({
value: fullName + " (" + noteId + ")",
label: fullName
});
}
return autocompleteItems;
}
$(document).bind('keydown', 'alt+l', function() { $(document).bind('keydown', 'alt+l', function() {
$("#noteAutocomplete").val(''); $("#noteAutocomplete").val('');
$("#linkTitle").val(''); $("#linkTitle").val('');
@ -119,17 +134,6 @@ $(document).bind('keydown', 'alt+l', function() {
width: 500 width: 500
}); });
let autocompleteItems = [];
for (const noteId of globalAllNoteIds) {
let fullName = getFullName(noteId);
autocompleteItems.push({
value: fullName + " (" + noteId + ")",
label: fullName
});
}
function setDefaultLinkTitle(noteId) { function setDefaultLinkTitle(noteId) {
const note = getNodeByKey(noteId); const note = getNodeByKey(noteId);
if (!note) { if (!note) {
@ -146,7 +150,7 @@ $(document).bind('keydown', 'alt+l', function() {
} }
$("#noteAutocomplete").autocomplete({ $("#noteAutocomplete").autocomplete({
source: autocompleteItems, source: getAutocompleteItems(),
minLength: 0, minLength: 0,
change: function () { change: function () {
const val = $("#noteAutocomplete").val(); const val = $("#noteAutocomplete").val();
@ -166,7 +170,7 @@ $(document).bind('keydown', 'alt+l', function() {
}); });
}); });
$("#insertLinkForm").submit(function addLink() { $("#insertLinkForm").submit(function() {
let val = $("#noteAutocomplete").val(); let val = $("#noteAutocomplete").val();
const noteId = getNodeIdFromLabel(val); const noteId = getNodeIdFromLabel(val);
@ -200,4 +204,31 @@ $(document).bind('keydown', 'alt+t', function() {
date.getHours() + ":" + date.getMinutes(); date.getHours() + ":" + date.getMinutes();
$('#noteDetail').summernote('insertText', dateString); $('#noteDetail').summernote('insertText', dateString);
});
$(document).bind('keydown', 'alt+j', function() {
$("#jumpToNoteAutocomplete").val('');
$("#jumpToNoteDialog").dialog({
modal: true,
width: 500
});
$("#jumpToNoteAutocomplete").autocomplete({
source: getAutocompleteItems(),
minLength: 0
});
});
$("#jumpToNoteForm").submit(function() {
const val = $("#jumpToNoteAutocomplete").val();
const noteId = getNodeIdFromLabel(val);
if (noteId) {
getNodeByKey(noteId).setActive();
$("#jumpToNoteDialog").dialog('close');
}
return false;
}); });