correctly parsing the click position

This commit is contained in:
zadam 2020-07-10 22:39:16 +02:00
parent 0ecb2f3662
commit 1c97310e92

View File

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