11#![ cfg_attr( test, allow( clippy:: expect_used, clippy:: unwrap_used) ) ]
2- use std:: { cfg_select, path:: PathBuf } ;
2+ use std:: { cfg_select, path:: PathBuf , str :: FromStr } ;
33
44use gpui:: { App , Global , ReadGlobal , SharedString } ;
55use serde:: { Deserialize , Serialize } ;
@@ -10,8 +10,6 @@ use crate::{
1010 i18n:: { I18n , Language } ,
1111} ;
1212
13- mod validate;
14-
1513const DEFAULT_MAX_HISTORY_RECORDS : usize = 100 ;
1614const DEFAULT_MAX_STORAGE_RECORDS : usize = 200 ;
1715/// 40% is the lowest opacity that still keeps text legible during testing;
@@ -130,6 +128,27 @@ impl Settings {
130128 self . validate_storage ( ) ;
131129 self
132130 }
131+
132+ /// Validate hotkey and reset to default if invalid.
133+ fn validate_hotkey ( & mut self ) {
134+ if self . hotkey . activation_key . is_empty ( )
135+ || global_hotkey:: hotkey:: HotKey :: from_str ( & self . hotkey . activation_key ) . is_err ( )
136+ {
137+ self . hotkey . activation_key = Self :: default ( ) . hotkey . activation_key ;
138+ }
139+ }
140+
141+ fn validate_window_opacity ( & mut self ) {
142+ self . window . normalize_opacity ( ) ;
143+ }
144+
145+ fn validate_storage ( & mut self ) {
146+ self . storage . max_history_records = self . storage . max_history_records . clamp ( 1 , 10_000 ) ;
147+ self . storage . max_storage_records = self . storage . max_storage_records . clamp ( 1 , 100_000 ) ;
148+ if self . storage . max_storage_records < self . storage . max_history_records {
149+ self . storage . max_storage_records = self . storage . max_history_records ;
150+ }
151+ }
133152}
134153
135154#[ derive( Debug , Clone , Copy , Serialize , Deserialize , PartialEq , Eq , Default ) ]
@@ -298,8 +317,6 @@ impl Settings {
298317
299318#[ cfg( test) ]
300319mod tests {
301- use std:: str:: FromStr ;
302-
303320 use tempfile:: TempDir ;
304321
305322 use super :: * ;
0 commit comments