From 48317bc67e4569c65a65f8bcfc72c920b7bff8dc Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Tue, 29 Aug 2023 14:05:42 -0700 Subject: [PATCH 1/3] fix(ui): ensure that trailing special chars are not included in link tags --- ui/src/utils/tags.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/ui/src/utils/tags.ts b/ui/src/utils/tags.ts index 371647d8..85aeeb54 100644 --- a/ui/src/utils/tags.ts +++ b/ui/src/utils/tags.ts @@ -1,15 +1,3 @@ -import { ROUTES } from "@/router"; -import { - LinkTarget, - LinkTargetName, - MentionLinkTarget, - MewContentPart, - MewTagType, - UrlLinkTarget, -} from "@/types/types"; -import { AgentPubKey, encodeHashToBase64 } from "@holochain/client"; -import { RouteLocationRaw } from "vue-router"; - export const TAG_SYMBOLS = { CASHTAG: "$", HASHTAG: "#", @@ -20,7 +8,7 @@ export const TAG_SYMBOLS = { const MENTION_TAG_REGEX_STRING = `\\B\\${TAG_SYMBOLS.MENTION}\\S+`; const MENTION_TAG_REGEX = new RegExp(MENTION_TAG_REGEX_STRING, "mi"); -const LINK_TAG_REGEX_STRING = `\\B\\${TAG_SYMBOLS.LINK}\\S+`; +const LINK_TAG_REGEX_STRING = `\\B\\${TAG_SYMBOLS.LINK}\\w+`; const LINK_TAG_REGEX = new RegExp(LINK_TAG_REGEX_STRING, "mi"); const CASH_TAG_REGEX_STRING = `\\B\\${TAG_SYMBOLS.CASHTAG}\\w+`; From c348357d1ef1dca6031185b9c374f18634f2d323 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Tue, 29 Aug 2023 14:18:57 -0700 Subject: [PATCH 2/3] fix(ui): do not highlight characters before '^' in link tags in CreateMewInput field --- ui/src/components/CreateMewInput.vue | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ui/src/components/CreateMewInput.vue b/ui/src/components/CreateMewInput.vue index 45acfd6b..1b3da413 100644 --- a/ui/src/components/CreateMewInput.vue +++ b/ui/src/components/CreateMewInput.vue @@ -579,12 +579,24 @@ const onCaretPositionChange = () => { } // current word is a URL } else if (isLinkTag(currentWord)) { + + // find start of tag that the caret is positioned at + const behind = content.substring(0, selection.anchorOffset - 1); + let lastCaretIndex = -1; + // find last index of space, which can be " " (32) or " " (160) + for (let i = behind.length - 1; i >= 0; i--) { + if (behind.charCodeAt(i) === 94) { + lastCaretIndex = i; + break; + } + } + showElement( selection.anchorNode, - startOfWordIndex, + lastCaretIndex, "#link-target-input-container" ); - currentAnchorOffset = startOfWordIndex; + currentAnchorOffset = lastCaretIndex; currentFocusOffset = endOfWordIndex; } else { hideAutocompleter(); From ea339d9a1d4a7fee3ac7b5bfa1a3a98a112fa9e9 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Tue, 29 Aug 2023 14:19:11 -0700 Subject: [PATCH 3/3] fix(ui): do not insert space after link tag in CreateMewInput field --- ui/src/components/CreateMewInput.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/components/CreateMewInput.vue b/ui/src/components/CreateMewInput.vue index 1b3da413..4a243174 100644 --- a/ui/src/components/CreateMewInput.vue +++ b/ui/src/components/CreateMewInput.vue @@ -370,12 +370,12 @@ const createLinkTag = (e: Event) => { range.insertNode(anchor); // insert space after html link - const spaceNode = document.createTextNode(String.fromCharCode(160)); + const spaceNode = document.createTextNode(""); anchor.after(spaceNode); // reset input resetLinkTargetInput(); - document.getSelection()?.setPosition(spaceNode, 1); + document.getSelection()?.setPosition(spaceNode, 0); }; /**