From 14dd6531ea1ce6bafe50cddf7ba41c17596102f5 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Fri, 31 Mar 2023 10:59:19 +0800 Subject: [PATCH] ! Fix original space padding logic --- src/renderer/helpers/api/local.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/helpers/api/local.js b/src/renderer/helpers/api/local.js index bdb02eb5d80ed..01738ac8a02cb 100644 --- a/src/renderer/helpers/api/local.js +++ b/src/renderer/helpers/api/local.js @@ -511,8 +511,10 @@ export function parseLocalTextRuns(runs, emojiSize = 16, options = { looseChanne const trimmedText = text.trim() // In comments, mention can be `@Channel Name` (not handle, but name) if (CHANNEL_HANDLE_REGEX.test(trimmedText) || (options.looseChannelNameDetection && /^@/.test(trimmedText))) { - // Extra space at the end due to YT tend to include one space afterward into "channel run" `text` for "mentions" - parsedRuns.push(`${trimmedText} `) + // Note that in regex `\s` must be used since the text contain non-default space (the half-width space char when we press spacebar) + const spacesBefore = (/^\s+/.exec(text) || [''])[0] + const spacesAfter = (/\s+$/.exec(text) || [''])[0] + parsedRuns.push(`${spacesBefore}${trimmedText}${spacesAfter}`) } else { parsedRuns.push(`https://www.youtube.com${endpoint.metadata.url}`) }