@@ -29,6 +29,7 @@ type State = {
2929 replaceControlCharactersEnabled : boolean ;
3030 customTextPipeDelimiter : boolean ;
3131 replaceNewlines : "off" | "space" | "periodSpace" ;
32+ removeZeroWidthCharactersEnabled : boolean ;
3233} ;
3334
3435const state : State = {
@@ -47,6 +48,7 @@ const state: State = {
4748 replaceControlCharactersEnabled : true ,
4849 customTextPipeDelimiter : false ,
4950 replaceNewlines : "off" ,
51+ removeZeroWidthCharactersEnabled : true ,
5052} ;
5153
5254function updateUI ( ) : void {
@@ -115,6 +117,13 @@ function updateUI(): void {
115117 `${ popup } .inputs .group[data-id="control"] button[value="${ state . replaceControlCharactersEnabled } "]`
116118 ) . addClass ( "active" ) ;
117119
120+ $ ( `${ popup } .inputs .group[data-id="zeroWidth"] button` ) . removeClass (
121+ "active"
122+ ) ;
123+ $ (
124+ `${ popup } .inputs .group[data-id="zeroWidth"] button[value="${ state . removeZeroWidthCharactersEnabled } "]`
125+ ) . addClass ( "active" ) ;
126+
118127 $ ( `${ popup } .inputs .group[data-id="delimiter"] button` ) . removeClass (
119128 "active"
120129 ) ;
@@ -264,8 +273,10 @@ function cleanUpText(): string[] {
264273 //replace any characters that look like a space with an actual space
265274 text = text . replace ( / [ \u2000 - \u200A \u202F \u205F \u00A0 ] / g, " " ) ;
266275
267- //replace zero width characters
268- text = text . replace ( / [ \u200B - \u200D \u2060 \uFEFF ] / g, "" ) ;
276+ if ( state . removeZeroWidthCharactersEnabled ) {
277+ //replace zero width characters
278+ text = text . replace ( / [ \u200B - \u200D \u2060 \uFEFF ] / g, "" ) ;
279+ }
269280
270281 if ( state . replaceControlCharactersEnabled ) {
271282 text = text . replace ( / ( [ ^ \\ ] | ^ ) \\ t / gm, "$1\t" ) ;
@@ -426,6 +437,16 @@ async function setup(modalEl: HTMLElement): Promise<void> {
426437 } ) ;
427438 }
428439
440+ for ( const button of modalEl . querySelectorAll (
441+ ".group[data-id='zeroWidth'] button"
442+ ) ) {
443+ button . addEventListener ( "click" , ( e ) => {
444+ state . removeZeroWidthCharactersEnabled =
445+ ( e . target as HTMLButtonElement ) . value === "true" ? true : false ;
446+ updateUI ( ) ;
447+ } ) ;
448+ }
449+
429450 for ( const button of modalEl . querySelectorAll (
430451 ".group[data-id='delimiter'] button"
431452 ) ) {
0 commit comments