Skip to content

Commit

Permalink
Detect non-width spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout Van Den Driessche committed Jul 17, 2023
1 parent 2d03516 commit f83ba83
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
6 changes: 5 additions & 1 deletion dist/tribute.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ class TributeRange {
}
}

convertNonWidthSpacesToRealOnes(text) {
return text.replace(/[\u200B-\u200D\uFEFF]/g, ' ')
}

getTextPrecedingCurrentSelection() {
let context = this.tribute.current,
text = '';
Expand All @@ -734,7 +738,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) {
Expand Down
9 changes: 8 additions & 1 deletion dist/tribute.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

(function(l, r) { if (l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (window.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.head.appendChild(r) })(window.document);
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
Expand Down Expand Up @@ -792,6 +794,11 @@
};
}
}
}, {
key: "convertNonWidthSpacesToRealOnes",
value: function convertNonWidthSpacesToRealOnes(text) {
return text.replace(/[\u200B-\u200D\uFEFF]/g, ' ');
}
}, {
key: "getTextPrecedingCurrentSelection",
value: function getTextPrecedingCurrentSelection() {
Expand All @@ -812,7 +819,7 @@
var selectedElem = this.getWindowSelection().anchorNode;

if (selectedElem != null) {
var workingNodeContent = selectedElem.textContent;
var workingNodeContent = this.convertNonWidthSpacesToRealOnes(selectedElem.textContent);
var selectStartOffset = this.getWindowSelection().getRangeAt(0).startOffset;

if (workingNodeContent && selectStartOffset >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion dist/tribute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tribute.min.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion example/tribute.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

(function(l, r) { if (l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (window.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.head.appendChild(r) })(window.document);
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
Expand Down Expand Up @@ -792,6 +794,11 @@
};
}
}
}, {
key: "convertNonWidthSpacesToRealOnes",
value: function convertNonWidthSpacesToRealOnes(text) {
return text.replace(/[\u200B-\u200D\uFEFF]/g, ' ');
}
}, {
key: "getTextPrecedingCurrentSelection",
value: function getTextPrecedingCurrentSelection() {
Expand All @@ -812,7 +819,7 @@
var selectedElem = this.getWindowSelection().anchorNode;

if (selectedElem != null) {
var workingNodeContent = selectedElem.textContent;
var workingNodeContent = this.convertNonWidthSpacesToRealOnes(selectedElem.textContent);
var selectStartOffset = this.getWindowSelection().getRangeAt(0).startOffset;

if (workingNodeContent && selectStartOffset >= 0) {
Expand Down
6 changes: 5 additions & 1 deletion src/TributeRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ class TributeRange {
}
}

convertNonWidthSpacesToRealOnes(text) {
return text.replace(/[\u200B-\u200D\uFEFF]/g, ' ')
}

getTextPrecedingCurrentSelection() {
let context = this.tribute.current,
text = ''
Expand All @@ -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) {
Expand Down

0 comments on commit f83ba83

Please sign in to comment.