mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix opening internal link from ckeditor link editing, fixes #191
This commit is contained in:
parent
d65610429c
commit
b2776954a1
4697
package-lock.json
generated
4697
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@ -33,7 +33,7 @@
|
|||||||
"cls-hooked": "4.2.2",
|
"cls-hooked": "4.2.2",
|
||||||
"commonmark": "0.28.1",
|
"commonmark": "0.28.1",
|
||||||
"cookie-parser": "1.4.3",
|
"cookie-parser": "1.4.3",
|
||||||
"debug": "3.1.0",
|
"debug": "4.0.1",
|
||||||
"devtron": "1.4.0",
|
"devtron": "1.4.0",
|
||||||
"ejs": "2.6.1",
|
"ejs": "2.6.1",
|
||||||
"electron-debug": "2.0.0",
|
"electron-debug": "2.0.0",
|
||||||
@ -51,12 +51,12 @@
|
|||||||
"imagemin-mozjpeg": "7.0.0",
|
"imagemin-mozjpeg": "7.0.0",
|
||||||
"imagemin-pngquant": "6.0.0",
|
"imagemin-pngquant": "6.0.0",
|
||||||
"ini": "1.3.5",
|
"ini": "1.3.5",
|
||||||
"jimp": "0.4.0",
|
"jimp": "0.5.3",
|
||||||
"moment": "2.22.2",
|
"moment": "2.22.2",
|
||||||
"multer": "1.3.1",
|
"multer": "1.4.0",
|
||||||
"open": "0.0.5",
|
"open": "0.0.5",
|
||||||
"rand-token": "0.4.0",
|
"rand-token": "0.4.0",
|
||||||
"rcedit": "1.1.0",
|
"rcedit": "1.1.1",
|
||||||
"request": "2.88.0",
|
"request": "2.88.0",
|
||||||
"request-promise": "4.2.2",
|
"request-promise": "4.2.2",
|
||||||
"rimraf": "2.6.2",
|
"rimraf": "2.6.2",
|
||||||
@ -65,16 +65,16 @@
|
|||||||
"session-file-store": "1.2.0",
|
"session-file-store": "1.2.0",
|
||||||
"simple-node-logger": "0.93.40",
|
"simple-node-logger": "0.93.40",
|
||||||
"sqlite": "3.0.0",
|
"sqlite": "3.0.0",
|
||||||
"tar-stream": "1.6.1",
|
"tar-stream": "1.6.2",
|
||||||
"turndown": "5.0.1",
|
"turndown": "5.0.1",
|
||||||
"unescape": "1.0.1",
|
"unescape": "1.0.1",
|
||||||
"ws": "6.0.0",
|
"ws": "6.1.0",
|
||||||
"xml2js": "0.4.19"
|
"xml2js": "0.4.19"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "2.0.9",
|
"electron": "2.0.11",
|
||||||
"electron-compile": "6.4.3",
|
"electron-compile": "6.4.3",
|
||||||
"electron-packager": "12.1.1",
|
"electron-packager": "12.2.0",
|
||||||
"electron-rebuild": "1.8.2",
|
"electron-rebuild": "1.8.2",
|
||||||
"lorem-ipsum": "1.0.6",
|
"lorem-ipsum": "1.0.6",
|
||||||
"tape": "4.9.1",
|
"tape": "4.9.1",
|
||||||
|
@ -2,7 +2,7 @@ import treeService from './tree.js';
|
|||||||
import noteDetailText from './note_detail_text.js';
|
import noteDetailText from './note_detail_text.js';
|
||||||
import treeUtils from './tree_utils.js';
|
import treeUtils from './tree_utils.js';
|
||||||
|
|
||||||
function getNotePathFromLink(url) {
|
function getNotePathFromUrl(url) {
|
||||||
const notePathMatch = /#(root[A-Za-z0-9/]*)$/.exec(url);
|
const notePathMatch = /#(root[A-Za-z0-9/]*)$/.exec(url);
|
||||||
|
|
||||||
if (notePathMatch === null) {
|
if (notePathMatch === null) {
|
||||||
@ -14,7 +14,7 @@ function getNotePathFromLink(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getNotePathFromLabel(label) {
|
function getNotePathFromLabel(label) {
|
||||||
const notePathMatch = / \(([A-Za-z0-9/]+)\)/.exec(label);
|
const notePathMatch = / \((root[A-Za-z0-9/]*)\)/.exec(label);
|
||||||
|
|
||||||
if (notePathMatch !== null) {
|
if (notePathMatch !== null) {
|
||||||
return notePathMatch[1];
|
return notePathMatch[1];
|
||||||
@ -39,28 +39,19 @@ async function createNoteLink(notePath, noteTitle = null) {
|
|||||||
return noteLink;
|
return noteLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
function goToLink(e) {
|
function getNotePathFromLink($link) {
|
||||||
e.preventDefault();
|
const notePathAttr = $link.attr("data-note-path");
|
||||||
|
|
||||||
const $link = $(e.target);
|
if (notePathAttr) {
|
||||||
let notePath = $link.attr("data-note-path");
|
return notePathAttr;
|
||||||
|
|
||||||
if (!notePath) {
|
|
||||||
const address = $link.attr("data-note-path") ? $link.attr("data-note-path") : $link.attr('href');
|
|
||||||
|
|
||||||
if (!address) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (address.startsWith('http')) {
|
|
||||||
window.open(address, '_blank');
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
notePath = getNotePathFromLink(address);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const url = $link.attr('href');
|
||||||
|
|
||||||
|
return url ? getNotePathFromUrl(url) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openNotePath(notePath) {
|
||||||
treeService.activateNote(notePath);
|
treeService.activateNote(notePath);
|
||||||
|
|
||||||
// this is quite ugly hack, but it seems like we can't close the tooltip otherwise
|
// this is quite ugly hack, but it seems like we can't close the tooltip otherwise
|
||||||
@ -69,8 +60,27 @@ function goToLink(e) {
|
|||||||
if (glob.activeDialog) {
|
if (glob.activeDialog) {
|
||||||
try {
|
try {
|
||||||
glob.activeDialog.dialog('close');
|
glob.activeDialog.dialog('close');
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function goToLink(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const $link = $(e.target);
|
||||||
|
|
||||||
|
const notePath = getNotePathFromLink($link);
|
||||||
|
|
||||||
|
if (notePath) {
|
||||||
|
openNotePath(notePath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const address = $link.attr('href');
|
||||||
|
|
||||||
|
if (address && address.startsWith('http')) {
|
||||||
|
window.open(address, '_blank');
|
||||||
}
|
}
|
||||||
catch (e) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,10 +119,23 @@ ko.bindingHandlers.noteLink = {
|
|||||||
$(document).on('click', "a[data-action='note']", goToLink);
|
$(document).on('click', "a[data-action='note']", goToLink);
|
||||||
$(document).on('click', 'div.popover-content a, div.ui-tooltip-content a', goToLink);
|
$(document).on('click', 'div.popover-content a, div.ui-tooltip-content a', goToLink);
|
||||||
$(document).on('dblclick', '#note-detail-text a', goToLink);
|
$(document).on('dblclick', '#note-detail-text a', goToLink);
|
||||||
|
$(document).on('click', 'span.ck-button__label', e => {
|
||||||
|
// this is a link preview dialog from CKEditor link editing
|
||||||
|
// for some reason clicked element is span
|
||||||
|
|
||||||
|
const url = $(e.target).text();
|
||||||
|
const notePath = getNotePathFromUrl(url);
|
||||||
|
|
||||||
|
if (notePath) {
|
||||||
|
openNotePath(notePath);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getNotePathFromLabel,
|
getNotePathFromLabel,
|
||||||
getNotePathFromLink,
|
getNotePathFromUrl,
|
||||||
createNoteLink,
|
createNoteLink,
|
||||||
addLinkToEditor,
|
addLinkToEditor,
|
||||||
addTextToEditor
|
addTextToEditor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user