File tree Expand file tree Collapse file tree 3 files changed +8
-14
lines changed Expand file tree Collapse file tree 3 files changed +8
-14
lines changed Original file line number Diff line number Diff line change @@ -80,10 +80,11 @@ const highlightSupport = {
80
80
const elems = editableHost . querySelectorAll ( `[data-word-id="${ highlightId } "]` )
81
81
for ( const elem of elems ) {
82
82
content . unwrap ( elem )
83
- // in Chrome browsers the unwrap method leaves the host node split into 2 (lastChild !== firstChild)
84
- editableHost . normalize ( )
85
- if ( dispatcher ) dispatcher . notify ( 'change' , editableHost )
86
83
}
84
+
85
+ // in Chrome browsers the unwrap method leaves the host node split into 2 (lastChild !== firstChild)
86
+ editableHost . normalize ( )
87
+ if ( dispatcher ) dispatcher . notify ( 'change' , editableHost )
87
88
} ,
88
89
89
90
hasHighlight ( editableHost , highlightId ) {
Original file line number Diff line number Diff line change @@ -23,10 +23,8 @@ export default class WordHighlighting {
23
23
24
24
findMatches ( text , highlights ) {
25
25
if ( ! text || text === '' || ! this . isElement ( this . marker ) ) return
26
-
27
- if ( highlights && highlights . length > 0 ) {
28
- return this . searchMatches ( text , highlights )
29
- }
26
+ if ( ! highlights ?. length ) return
27
+ return this . searchMatches ( text , highlights )
30
28
}
31
29
32
30
searchMatches ( text , highlights ) {
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ const characters = {
23
23
// a paragraph and the highlighting prevents browsers from converting
24
24
// the no-break space back to a normal space when the user keeps typing.
25
25
const specialWhitespaceChars = '\\u2000-\\u200A\\u202F\\u205F\\u3000'
26
+ const specialWhitespaceCharsRegex = new RegExp ( `[${ specialWhitespaceChars } ]` , 'g' )
26
27
27
28
export default class WhitespaceHighlighting {
28
29
@@ -33,13 +34,7 @@ export default class WhitespaceHighlighting {
33
34
findMatches ( text ) {
34
35
if ( ! text ) return
35
36
36
- let regex = `[${ specialWhitespaceChars } ]`
37
- regex = new RegExp ( regex , 'g' )
38
-
39
- const matches = [ ]
40
- let match
41
- while ( ( match = regex . exec ( text ) ) ) matches . push ( match )
42
-
37
+ const matches = [ ...text . matchAll ( specialWhitespaceCharsRegex ) ]
43
38
return matches . map ( ( entry ) => this . prepareMatch ( entry ) )
44
39
}
45
40
You can’t perform that action at this time.
0 commit comments