From 1226b326866829817de2c9f428c3ff56dc2ef95f Mon Sep 17 00:00:00 2001 From: Wout Van Den Driessche Date: Mon, 17 Jul 2023 17:09:31 +0200 Subject: [PATCH] Detect non-width spaces --- src/TributeRange.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/TributeRange.js b/src/TributeRange.js index 59e4d600..510271ff 100644 --- a/src/TributeRange.js +++ b/src/TributeRange.js @@ -243,6 +243,10 @@ class TributeRange { } } + convertNonWidthSpacesToRealOnes(text) { + return text.replace(/[\u200B-\u200D\uFEFF]/g, ' ') + } + getTextPrecedingCurrentSelection() { let context = this.tribute.current, text = '' @@ -260,7 +264,7 @@ class TributeRange { let selectedElem = this.getWindowSelection().anchorNode if (selectedElem != null) { - let workingNodeContent = selectedElem.textContent + let workingNodeContent = this.convertNonWidthSpacesToRealOnes(selectedElem.textContent) let selectStartOffset = this.getWindowSelection().getRangeAt(0).startOffset if (workingNodeContent && selectStartOffset >= 0) {