From 1c97310e92aa299ea4ceb999da40994d5d6ebefc Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 10 Jul 2020 22:39:16 +0200 Subject: [PATCH] correctly parsing the click position --- src/public/app/widgets/note_attributes.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/public/app/widgets/note_attributes.js b/src/public/app/widgets/note_attributes.js index 5b2ab5478..1c32143f5 100644 --- a/src/public/app/widgets/note_attributes.js +++ b/src/public/app/widgets/note_attributes.js @@ -392,10 +392,9 @@ export default class NoteAttributesWidget extends TabAwareWidget { const pos = this.textEditor.model.document.selection.getFirstPosition(); if (pos && pos.textNode && pos.textNode.data) { - const attrText = pos.textNode.data; - const clickIndex = pos.offset - pos.textNode.startOffset; + const clickIndex = this.getClickIndex(pos); - const parsedAttrs = attributesParser.lexAndParse(attrText, true); + const parsedAttrs = attributesParser.lexAndParse(this.textEditor.getData(), true); let matchedAttr = null; @@ -416,6 +415,24 @@ export default class NoteAttributesWidget extends TabAwareWidget { } } + getClickIndex(pos) { + let clickIndex = pos.offset - pos.textNode.startOffset; + + let curNode = pos.textNode; + + while (curNode.previousSibling) { + curNode = curNode.previousSibling; + + if (curNode.name === 'reference') { + clickIndex += curNode._attrs.get('notePath').length + 1; + } else { + clickIndex += curNode.data.length; + } + } + + return clickIndex; + } + async loadReferenceLinkTitle(noteId, $el) { const note = await treeCache.getNote(noteId, true);