@@ -3,7 +3,7 @@ use crate::editor::TextEditor;
33use crate :: language:: { Language , LanguageManager } ;
44use crate :: sidebar:: Sidebar ;
55use crate :: theme:: AtomTheme ;
6- use crate :: { get_app_info , open_repository, open_sponsor_page} ;
6+ use crate :: { open_repository, open_sponsor_page} ;
77use eframe:: egui;
88use rfd:: FileDialog ;
99use std:: path:: PathBuf ;
@@ -164,20 +164,21 @@ impl SpellCheckerApp {
164164 }
165165
166166 // Perform spell check
167- if let Ok ( checker) = self . spell_checker . lock ( ) {
168- self . analysis = Some ( checker. check_document ( & self . state . document_content ) ) ;
169- if let Some ( analysis) = & self . analysis {
170- self . stats . total_words = analysis. total_words ;
171- self . stats . errors = analysis. misspelled_words ;
172- self . stats . last_check_duration = start_time. elapsed ( ) ;
173- self . stats . check_count += 1 ;
174-
175- // Update text editor with analysis for highlighting
176- self . text_editor . set_analysis ( analysis. clone ( ) ) ;
177- self . last_spell_check = Some ( analysis. clone ( ) ) ;
178- self . last_check_time = Instant :: now ( ) ;
179- }
180- }
167+ let analysis = {
168+ let checker = self . spell_checker . lock ( ) . unwrap ( ) ;
169+ checker. check_document ( & self . state . document_content )
170+ } ;
171+
172+ self . analysis = Some ( analysis. clone ( ) ) ;
173+ self . stats . total_words = analysis. total_words ;
174+ self . stats . errors = analysis. misspelled_words ;
175+ self . stats . last_check_duration = start_time. elapsed ( ) ;
176+ self . stats . check_count += 1 ;
177+
178+ // Update text editor with analysis for highlighting
179+ self . text_editor . set_analysis ( analysis. clone ( ) ) ;
180+ self . last_spell_check = Some ( analysis) ;
181+ self . last_check_time = Instant :: now ( ) ;
181182 }
182183
183184 fn open_file ( & mut self , path : PathBuf ) -> anyhow:: Result < ( ) > {
@@ -269,22 +270,24 @@ impl SpellCheckerApp {
269270 fn handle_pending_actions ( & mut self ) {
270271 // Handle adding words to dictionary
271272 if let Some ( word) = self . pending_add_word . take ( ) {
272- if let Ok ( mut checker) = self . spell_checker . lock ( ) {
273+ {
274+ let mut checker = self . spell_checker . lock ( ) . unwrap ( ) ;
273275 if checker. add_word_to_dictionary ( & word) . is_ok ( ) {
274276 println ! ( "Added word to dictionary: {}" , word) ;
275- self . check_spelling ( ) ; // Re-check with updated dictionary
276277 }
277278 }
279+ self . check_spelling ( ) ; // Re-check with updated dictionary
278280 }
279281
280282 // Handle ignoring words
281283 if let Some ( word) = self . pending_ignore_word . take ( ) {
282- if let Ok ( mut checker) = self . spell_checker . lock ( ) {
284+ {
285+ let mut checker = self . spell_checker . lock ( ) . unwrap ( ) ;
283286 if checker. ignore_word ( & word) . is_ok ( ) {
284287 println ! ( "Ignored word: {}" , word) ;
285- self . check_spelling ( ) ; // Re-check with updated ignore list
286288 }
287289 }
290+ self . check_spelling ( ) ; // Re-check with updated ignore list
288291 }
289292
290293 // Handle word replacement
@@ -304,14 +307,15 @@ impl SpellCheckerApp {
304307 . set_directory ( self . state . last_directory . clone ( ) . unwrap_or_else ( || PathBuf :: from ( "." ) ) )
305308 . pick_file ( )
306309 {
307- if let Ok ( mut checker) = self . spell_checker . lock ( ) {
310+ {
311+ let mut checker = self . spell_checker . lock ( ) . unwrap ( ) ;
308312 if let Err ( e) = checker. import_dictionary ( & path) {
309313 eprintln ! ( "Failed to import dictionary: {}" , e) ;
310314 } else {
311315 println ! ( "Imported dictionary from: {:?}" , path) ;
312- self . check_spelling ( ) ;
313316 }
314317 }
318+ self . check_spelling ( ) ;
315319 }
316320 }
317321
@@ -325,7 +329,8 @@ impl SpellCheckerApp {
325329 . set_directory ( self . state . last_directory . clone ( ) . unwrap_or_else ( || PathBuf :: from ( "." ) ) )
326330 . save_file ( )
327331 {
328- if let Ok ( checker) = self . spell_checker . lock ( ) {
332+ {
333+ let checker = self . spell_checker . lock ( ) . unwrap ( ) ;
329334 if let Err ( e) = checker. export_dictionary ( & path) {
330335 eprintln ! ( "Failed to export dictionary: {}" , e) ;
331336 } else {
@@ -338,16 +343,19 @@ impl SpellCheckerApp {
338343 // Handle clear ignored words
339344 if self . pending_clear_ignored {
340345 self . pending_clear_ignored = false ;
341- if let Ok ( mut checker) = self . spell_checker . lock ( ) {
346+ {
347+ let mut checker = self . spell_checker . lock ( ) . unwrap ( ) ;
342348 checker. clear_ignored_words ( ) ;
343- self . check_spelling ( ) ;
344349 }
350+ self . check_spelling ( ) ;
345351 }
346352 }
347353
348354 fn show_about_dialog ( & mut self , ctx : & egui:: Context ) {
355+ let mut show_about = self . state . show_about ;
356+
349357 egui:: Window :: new ( "About AtomSpell" )
350- . open ( & mut self . state . show_about )
358+ . open ( & mut show_about)
351359 . resizable ( false )
352360 . collapsible ( false )
353361 . anchor ( egui:: Align2 :: CENTER_CENTER , [ 0.0 , 0.0 ] )
@@ -385,6 +393,8 @@ impl SpellCheckerApp {
385393 } ) ;
386394 } ) ;
387395 } ) ;
396+
397+ self . state . show_about = show_about;
388398 }
389399
390400 fn show_menu_bar ( & mut self , ui : & mut egui:: Ui ) {
@@ -424,10 +434,13 @@ impl SpellCheckerApp {
424434 // Recent files
425435 if !self . state . recent_files . is_empty ( ) {
426436 ui. menu_button ( "Recent Files" , |ui| {
427- for path in & self . state . recent_files {
437+ // Make a copy to avoid borrowing issues
438+ let recent_files = self . state . recent_files . clone ( ) ;
439+ for path in & recent_files {
428440 if let Some ( filename) = path. file_name ( ) . and_then ( |n| n. to_str ( ) ) {
429441 if ui. button ( format ! ( "📄 {}" , filename) ) . clicked ( ) {
430- if let Err ( e) = self . open_file ( path. clone ( ) ) {
442+ let path_clone = path. clone ( ) ;
443+ if let Err ( e) = self . open_file ( path_clone) {
431444 eprintln ! ( "Failed to open file: {}" , e) ;
432445 }
433446 ui. close_menu ( ) ;
@@ -459,7 +472,8 @@ impl SpellCheckerApp {
459472 let detected = self . language_manager . detect_language ( & self . state . document_content ) ;
460473 self . state . selected_language = detected;
461474 self . state . auto_detect_language = false ;
462- if let Ok ( mut checker) = self . spell_checker . lock ( ) {
475+ {
476+ let mut checker = self . spell_checker . lock ( ) . unwrap ( ) ;
463477 let _ = checker. set_language ( detected) ;
464478 }
465479 self . check_spelling ( ) ;
@@ -523,7 +537,8 @@ impl SpellCheckerApp {
523537 ) . clicked ( ) {
524538 self . state . selected_language = selected_language;
525539 self . state . auto_detect_language = false ;
526- if let Ok ( mut checker) = self . spell_checker . lock ( ) {
540+ {
541+ let mut checker = self . spell_checker . lock ( ) . unwrap ( ) ;
527542 let _ = checker. set_language ( * lang) ;
528543 }
529544 self . check_spelling ( ) ;
@@ -612,7 +627,8 @@ impl SpellCheckerApp {
612627 ) . clicked ( ) {
613628 self . state . selected_language = selected_language;
614629 self . state . auto_detect_language = false ;
615- if let Ok ( mut checker) = self . spell_checker . lock ( ) {
630+ {
631+ let mut checker = self . spell_checker . lock ( ) . unwrap ( ) ;
616632 let _ = checker. set_language ( * lang) ;
617633 }
618634 self . check_spelling ( ) ;
@@ -666,7 +682,10 @@ impl SpellCheckerApp {
666682 ui. colored_label ( egui:: Color32 :: GREEN , "🔄 Auto" ) ;
667683 }
668684
669- let word_count = self . spell_checker . lock ( ) . unwrap ( ) . word_count ( ) ;
685+ let word_count = {
686+ let checker = self . spell_checker . lock ( ) . unwrap ( ) ;
687+ checker. word_count ( )
688+ } ;
670689 ui. label ( format ! ( "Dict: {}" , word_count) ) ;
671690
672691 if self . state . auto_detect_language {
@@ -690,9 +709,10 @@ impl SpellCheckerApp {
690709 . default_width ( self . state . sidebar_width )
691710 . width_range ( 200.0 ..=500.0 )
692711 . show_inside ( ui, |ui| {
712+ let checker = self . spell_checker . lock ( ) . unwrap ( ) ;
693713 self . state . sidebar_state . show (
694714 ui,
695- & self . spell_checker . lock ( ) . unwrap ( ) ,
715+ & checker ,
696716 & self . analysis ,
697717 & self . state . document_content ,
698718 & mut self . pending_add_word ,
@@ -787,10 +807,6 @@ impl eframe::App for SpellCheckerApp {
787807 std:: time:: Duration :: from_secs ( 30 )
788808 }
789809
790- fn persist_native_window ( & self ) -> bool {
791- true
792- }
793-
794810 fn persist_egui_memory ( & self ) -> bool {
795811 true
796812 }
0 commit comments