rich-input 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -764,7 +764,7 @@ export class RichInput extends HTMLElement {
764
764
  const start = highlightQuotes ? token.valueStart : token.innerStart;
765
765
  const end = highlightQuotes ? token.valueEnd : token.innerEnd;
766
766
 
767
- if (end >= start && end <= text.length) {
767
+ if (end > start && end <= text.length) {
768
768
  try {
769
769
  const valRange = this._input.createValueRange(start, end);
770
770
  this._ownedRanges.push(valRange);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rich-input",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "A rich input field with keyword-based autocomplete and in-input highlighting powered by <datalist>, OpaqueRange, and the Custom Highlight API",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -13,6 +13,17 @@ export const isHighlightSupported =
13
13
  typeof CSS !== 'undefined' &&
14
14
  'highlights' in CSS;
15
15
 
16
+ function isRangeCollapsed(range) {
17
+ if (!range) return true;
18
+ if (range.collapsed === true) return true;
19
+ if (typeof range.startOffset === 'number' && typeof range.endOffset === 'number') {
20
+ if (range.startOffset === range.endOffset && range.startContainer === range.endContainer) {
21
+ return true;
22
+ }
23
+ }
24
+ return false;
25
+ }
26
+
16
27
  class HighlightRegistryManager {
17
28
  constructor() {
18
29
  this.instances = new Set();
@@ -77,6 +88,7 @@ class HighlightRegistryManager {
77
88
  hl.clear();
78
89
  for (const r of ranges) {
79
90
  try {
91
+ if (isRangeCollapsed(r)) continue;
80
92
  hl.add(r);
81
93
  } catch (e) {}
82
94
  }
@@ -95,6 +107,7 @@ class HighlightRegistryManager {
95
107
  kwHl.clear();
96
108
  for (const r of allKeywordRanges) {
97
109
  try {
110
+ if (isRangeCollapsed(r)) continue;
98
111
  kwHl.add(r);
99
112
  } catch (e) {}
100
113
  }
@@ -111,6 +124,7 @@ class HighlightRegistryManager {
111
124
  valHl.clear();
112
125
  for (const r of allValueRanges) {
113
126
  try {
127
+ if (isRangeCollapsed(r)) continue;
114
128
  valHl.add(r);
115
129
  } catch (e) {}
116
130
  }