@@ -5,8 +5,10 @@ import {
55 revertToParagraph ,
66 clearPrepareCache ,
77 clearFontMetricsCache ,
8+ setPrepareCacheMaxSize ,
89 type JustifySettings ,
910} from "./renderer" ;
11+ import { clearCache as clearPretextCache } from "@chenglou/pretext" ;
1012import { PretextJustifySettingTab , DEFAULT_SETTINGS } from "./settings" ;
1113
1214// ---------------------------------------------------------------------------
@@ -61,13 +63,10 @@ export default class PretextJustifyPlugin extends Plugin {
6163 async onload ( ) : Promise < void > {
6264 await this . loadSettings ( ) ;
6365
64- this . addSettingTab ( new PretextJustifySettingTab ( this . app , this ) ) ;
66+ // Apply cache limit from settings
67+ setPrepareCacheMaxSize ( this . settings . maxCacheEntries ) ;
6568
66- this . addCommand ( {
67- id : "toggle-justification" ,
68- name : "Toggle justification" ,
69- callback : ( ) => this . toggle ( ) ,
70- } ) ;
69+ this . addSettingTab ( new PretextJustifySettingTab ( this . app , this ) ) ;
7170
7271 // Markdown post-processor — runs on every rendered section
7372 this . registerMarkdownPostProcessor ( ( el ) => {
@@ -85,7 +84,6 @@ export default class PretextJustifyPlugin extends Plugin {
8584 }
8685 this . _fileSwitchDebounce = window . setTimeout ( ( ) => {
8786 this . _fileSwitchDebounce = null ;
88- if ( ! this . settings . enabled ) return ;
8987 this . _observePreviewViews ( ) ;
9088 this . _scanForMissedParagraphs ( ) ;
9189 this . _scheduleProcessing ( ) ;
@@ -135,6 +133,7 @@ export default class PretextJustifyPlugin extends Plugin {
135133 this . _justified . clear ( ) ;
136134 clearPrepareCache ( ) ;
137135 clearFontMetricsCache ( ) ;
136+ clearPretextCache ( ) ;
138137 }
139138
140139 // ------------------------------------------------------------------
@@ -148,32 +147,15 @@ export default class PretextJustifyPlugin extends Plugin {
148147
149148 async saveSettings ( ) : Promise < void > {
150149 await this . saveData ( this . settings ) ;
150+ setPrepareCacheMaxSize ( this . settings . maxCacheEntries ) ;
151151 }
152152
153153 // ------------------------------------------------------------------
154- // Toggle / refresh
154+ // Refresh
155155 // ------------------------------------------------------------------
156156
157- async toggle ( ) : Promise < void > {
158- this . settings . enabled = ! this . settings . enabled ;
159- await this . saveSettings ( ) ;
160- if ( this . settings . enabled ) {
161- this . refresh ( ) ;
162- } else {
163- this . _pending . clear ( ) ;
164- this . _revertAll ( ) ;
165- this . _justified . clear ( ) ;
166- }
167- }
168-
169157 /** Re-justify every tracked element (used after settings change). */
170158 refresh ( ) : void {
171- if ( ! this . settings . enabled ) {
172- this . _revertAll ( ) ;
173- this . _justified . clear ( ) ;
174- return ;
175- }
176-
177159 const entries = Array . from ( this . _justified . entries ( ) ) ;
178160
179161 if ( entries . length > 0 ) {
@@ -204,7 +186,6 @@ export default class PretextJustifyPlugin extends Plugin {
204186 // ------------------------------------------------------------------
205187
206188 private _onScroll = ( ) : void => {
207- if ( ! this . settings . enabled ) return ;
208189 if ( this . _scrollRAF !== null ) return ;
209190
210191 this . _scrollRAF = window . requestAnimationFrame ( ( ) => {
@@ -219,7 +200,6 @@ export default class PretextJustifyPlugin extends Plugin {
219200 // ------------------------------------------------------------------
220201
221202 private _scheduleProcessing ( ) : void {
222- if ( ! this . settings . enabled ) return ;
223203 if ( this . _fileSwitchDebounce !== null ) return ; // wait for file-settle window
224204 if ( this . _processingRAF !== null ) return ;
225205 if ( this . _pending . size === 0 ) return ;
@@ -321,8 +301,6 @@ export default class PretextJustifyPlugin extends Plugin {
321301 * or null if justification was skipped.
322302 */
323303 private _justifyInternal ( p : HTMLElement , font : string ) : HTMLElement | null {
324- if ( ! this . settings . enabled ) return null ;
325-
326304 const w = p . getBoundingClientRect ( ) . width ;
327305 if ( w < this . settings . minWidth ) return null ;
328306
@@ -339,7 +317,6 @@ export default class PretextJustifyPlugin extends Plugin {
339317 // ------------------------------------------------------------------
340318
341319 private _rejustifyAll ( ) : void {
342- if ( ! this . settings . enabled ) return ;
343320 if ( this . _justified . size === 0 ) return ;
344321
345322 // Cooldown: if we just completed a batch pass within the last 2 s,
0 commit comments