@@ -2,6 +2,13 @@ import { eventBus, SendTarget } from '@/eventbus'
22import { CONFIG_EVENTS } from '@/events'
33import fontList from 'font-list'
44
5+ const AUTO_COMPACTION_TRIGGER_THRESHOLD_DEFAULT = 80
6+ const AUTO_COMPACTION_TRIGGER_THRESHOLD_MIN = 5
7+ const AUTO_COMPACTION_TRIGGER_THRESHOLD_MAX = 95
8+ const AUTO_COMPACTION_RETAIN_RECENT_PAIRS_DEFAULT = 2
9+ const AUTO_COMPACTION_RETAIN_RECENT_PAIRS_MIN = 1
10+ const AUTO_COMPACTION_RETAIN_RECENT_PAIRS_MAX = 10
11+
512const normalizeFontNameValue = ( name : string ) : string => {
613 const trimmed = name
714 . replace ( / \( .* ?\) / g, '' )
@@ -61,6 +68,42 @@ export class UiSettingsHelper {
6168 eventBus . send ( CONFIG_EVENTS . AUTO_SCROLL_CHANGED , SendTarget . ALL_WINDOWS , boolValue )
6269 }
6370
71+ getAutoCompactionEnabled ( ) : boolean {
72+ const value = this . getSetting < boolean > ( 'autoCompactionEnabled' )
73+ if ( value === undefined ) return true
74+ return Boolean ( value )
75+ }
76+
77+ setAutoCompactionEnabled ( enabled : boolean ) : void {
78+ this . setSetting ( 'autoCompactionEnabled' , Boolean ( enabled ) )
79+ }
80+
81+ getAutoCompactionTriggerThreshold ( ) : number {
82+ return this . normalizeAutoCompactionTriggerThreshold (
83+ this . getSetting < number > ( 'autoCompactionTriggerThreshold' )
84+ )
85+ }
86+
87+ setAutoCompactionTriggerThreshold ( threshold : number ) : void {
88+ this . setSetting (
89+ 'autoCompactionTriggerThreshold' ,
90+ this . normalizeAutoCompactionTriggerThreshold ( threshold )
91+ )
92+ }
93+
94+ getAutoCompactionRetainRecentPairs ( ) : number {
95+ return this . normalizeAutoCompactionRetainRecentPairs (
96+ this . getSetting < number > ( 'autoCompactionRetainRecentPairs' )
97+ )
98+ }
99+
100+ setAutoCompactionRetainRecentPairs ( count : number ) : void {
101+ this . setSetting (
102+ 'autoCompactionRetainRecentPairs' ,
103+ this . normalizeAutoCompactionRetainRecentPairs ( count )
104+ )
105+ }
106+
64107 getContentProtectionEnabled ( ) : boolean {
65108 const value = this . getSetting < boolean > ( 'contentProtectionEnabled' )
66109 return value === undefined || value === null ? false : value
@@ -186,4 +229,28 @@ export class UiSettingsHelper {
186229 private normalizeFontName ( name : string ) : string {
187230 return normalizeFontNameValue ( name )
188231 }
232+
233+ private normalizeAutoCompactionTriggerThreshold ( value : unknown ) : number {
234+ if ( typeof value !== 'number' || ! Number . isFinite ( value ) ) {
235+ return AUTO_COMPACTION_TRIGGER_THRESHOLD_DEFAULT
236+ }
237+
238+ const rounded = Math . round ( value / 5 ) * 5
239+ return Math . min (
240+ AUTO_COMPACTION_TRIGGER_THRESHOLD_MAX ,
241+ Math . max ( AUTO_COMPACTION_TRIGGER_THRESHOLD_MIN , rounded )
242+ )
243+ }
244+
245+ private normalizeAutoCompactionRetainRecentPairs ( value : unknown ) : number {
246+ if ( typeof value !== 'number' || ! Number . isFinite ( value ) ) {
247+ return AUTO_COMPACTION_RETAIN_RECENT_PAIRS_DEFAULT
248+ }
249+
250+ const rounded = Math . round ( value )
251+ return Math . min (
252+ AUTO_COMPACTION_RETAIN_RECENT_PAIRS_MAX ,
253+ Math . max ( AUTO_COMPACTION_RETAIN_RECENT_PAIRS_MIN , rounded )
254+ )
255+ }
189256}
0 commit comments