@@ -54,7 +54,6 @@ export default class RichInputElement extends HTMLElement {
5454 classList . toggle ( 'noselection' , selectionStart !== null && selectionStart === selectionEnd ) ;
5555 } ;
5656
57- // when receiving focus update the ::selection styles
5857 this . addEventListener ( 'focus' , ( ) => {
5958 // when receiving focus update the ::selection styles
6059 this . #updateSelectionStyles( ) ;
@@ -101,7 +100,7 @@ export default class RichInputElement extends HTMLElement {
101100 attributeChangedCallback ( name , oldValue , newValue ) {
102101 if ( name === 'stylepattern' ) {
103102 try {
104- this . #formatRegex = new RegExp ( `^(?:${ newValue } )$` , 'gd ' ) ;
103+ this . #formatRegex = new RegExp ( `^(?:${ newValue } )$` , 'dv ' ) ;
105104 } catch ( e ) {
106105 this . #formatRegex = null ;
107106 }
@@ -127,9 +126,9 @@ export default class RichInputElement extends HTMLElement {
127126 }
128127
129128 #updateSelectionStyles( ) {
130- // It's not possible for ::selection to inherit values form the cascade
131- // so we query the host element styles and pass them on through a custom
132- // property.
129+ // It's not possible for ::selection to inherit values from the cascade
130+ // so we query the host element for its styles and pass them on through a
131+ // custom property.
133132 const { backgroundColor } = getComputedStyle ( this , '::selection' ) ;
134133 this . #input. style . setProperty ( '--selection' , backgroundColor ) ;
135134 }
@@ -142,8 +141,9 @@ export default class RichInputElement extends HTMLElement {
142141 this . #internals. setFormValue ( value ) ;
143142 this . #setValidityFromInput( ) ;
144143
145- // If the output doesn't match the regex then there is no need to higlight
146- // the content so set `textContent`
144+ // If the output doesn't match the regex pattern there is no need to
145+ // highlight the content. Instead we just set `textContent` on the output
146+ // element and exit.
147147 const match = this . #formatRegex?. exec ( value ) ;
148148 if ( ! match ) {
149149 this . #output. textContent = value ;
@@ -170,7 +170,6 @@ export default class RichInputElement extends HTMLElement {
170170 chunks . push ( htmlEncode ( value . slice ( lastIndex ) ) ) ;
171171 }
172172 this . #output. innerHTML = chunks . join ( '' ) ;
173- this . #formatRegex. lastIndex = 0 ;
174173 }
175174
176175
@@ -416,8 +415,8 @@ export default class RichInputElement extends HTMLElement {
416415
417416 /**
418417 * The regular expression pattern used to control styling of the input value.
419- * The pattern must match the entire input value, rather than matching a
420- * substring .
418+ * It's compiled with the `v` flag, so it's Unicode-aware. The pattern must
419+ * match the entire input value—not just part of it .
421420 * @htmlattr stylepattern
422421 * @type {string }
423422 */
0 commit comments