@@ -170,10 +170,14 @@ export default class RtlPlugin extends Plugin {
170170 containerEl . classList . add ( 'is-rtl' ) ;
171171 this . replacePageStyleByString ( 'List indent fix' ,
172172 `/* List indent fix */ .cm-s-obsidian .HyperMD-list-line { text-indent: 0px !important; }` , true ) ;
173+ // this.replaceStringInStyle('.markdown-source-view.mod-cm6 .cm-fold-indicator .collapse-indicator',
174+ // 'right: 0;', 'right: -15px;');
173175 } else {
174176 containerEl . classList . remove ( 'is-rtl' ) ;
175177 this . replacePageStyleByString ( 'List indent fix' ,
176178 `/* List indent fix */ /* Empty rule for LTR */` , true ) ;
179+ // this.replaceStringInStyle('.markdown-source-view.mod-cm6 .cm-fold-indicator .collapse-indicator',
180+ // 'right: -15px;', 'right: 0;');
177181 }
178182 this . replacePageStyleByString ( 'Embedded links always LTR' ,
179183 `/* Embedded links always LTR */ .embedded-backlinks { direction: ltr; }` , true ) ;
@@ -211,33 +215,39 @@ export default class RtlPlugin extends Plugin {
211215
212216 // Returns true if a replacement was made
213217 replacePageStyleByString ( searchString : string , newStyle : string , addIfNotFound : boolean ) {
214- let styles = document . head . getElementsByTagName ( 'style' ) ;
215- let found = false ;
216218 let alreadyExists = false ;
217- for ( let style of styles ) {
218- if ( style . getText ( ) . includes ( searchString ) ) {
219- found = true ;
220- if ( style . getText ( ) === searchString )
221- alreadyExists = true ;
222- else
223- style . setText ( newStyle ) ;
224- }
225- }
226- if ( ! found && addIfNotFound ) {
219+ let style = this . findPageStyle ( searchString ) ;
220+ if ( style ) {
221+ if ( style . getText ( ) === searchString )
222+ alreadyExists = true ;
223+ else
224+ style . setText ( newStyle ) ;
225+ } else if ( addIfNotFound ) {
227226 let style = document . createElement ( 'style' ) ;
228227 style . textContent = newStyle ;
229228 document . head . appendChild ( style ) ;
230229 }
231- return found && ! alreadyExists ;
230+ return style && ! alreadyExists ;
231+ }
232+
233+ // Returns true if a replacement was made
234+ replaceStringInStyle ( searchString : string , whatToReplace : string , replacement : string ) {
235+ let style = this . findPageStyle ( searchString ) ;
236+ if ( style && style . getText ( ) . includes ( whatToReplace ) ) {
237+ const newText = style . getText ( ) . replace ( whatToReplace , replacement ) ;
238+ style . textContent = newText ;
239+ return true ;
240+ }
241+ return false ;
232242 }
233243
234- findPageStyle ( searchString : string ) {
244+ findPageStyle ( regex : string ) {
235245 let styles = document . head . getElementsByTagName ( 'style' ) ;
236246 for ( let style of styles ) {
237- if ( style . getText ( ) . includes ( searchString ) )
238- return true ;
247+ if ( style . getText ( ) . match ( regex ) )
248+ return style ;
239249 }
240- return false ;
250+ return null ;
241251 }
242252
243253 patchAutoCloseBrackets ( cmEditor : any , newDirection : string ) {
@@ -266,7 +276,7 @@ export default class RtlPlugin extends Plugin {
266276 var cmEditor = this . getCmEditor ( ) ;
267277 return cmEditor ?. getOption ( 'direction' ) === 'rtl' ? 'rtl' : 'ltr' ;
268278 } else {
269- return this . findPageStyle ( 'direction: rtl' ) ? 'rtl' : 'ltr' ;
279+ return this . findPageStyle ( 'New editor content div.* direction: rtl' ) ? 'rtl' : 'ltr' ;
270280 }
271281 }
272282
0 commit comments