@@ -71,10 +71,10 @@ impl EditorHandle {
71
71
pub fn new ( frontend_message_handler_callback : js_sys:: Function ) -> Self {
72
72
let editor = Editor :: new ( ) ;
73
73
let editor_handle = EditorHandle { frontend_message_handler_callback } ;
74
- if EDITOR . with ( |editor_cell| editor_cell . set ( RefCell :: new ( editor) ) ) . is_err ( ) {
74
+ if EDITOR . with ( |handle| handle . lock ( ) . ok ( ) . map ( | mut guard| * guard = Some ( editor) ) ) . is_none ( ) {
75
75
log:: error!( "Attempted to initialize the editor more than once" ) ;
76
76
}
77
- if EDITOR_HANDLE . with ( |handle_cell| handle_cell . set ( RefCell :: new ( editor_handle. clone ( ) ) ) ) . is_err ( ) {
77
+ if EDITOR_HANDLE . with ( |handle| handle . lock ( ) . ok ( ) . map ( | mut guard| * guard = Some ( editor_handle. clone ( ) ) ) ) . is_none ( ) {
78
78
log:: error!( "Attempted to initialize the editor handle more than once" ) ;
79
79
}
80
80
editor_handle
@@ -888,29 +888,29 @@ fn set_timeout(f: &Closure<dyn FnMut()>, delay: Duration) {
888
888
}
889
889
890
890
/// Provides access to the `Editor` by calling the given closure with it as an argument.
891
- fn editor < T : Default > ( callback : impl FnOnce ( & mut editor:: application:: Editor ) -> T ) -> T {
891
+ fn editor < T > ( callback : impl FnOnce ( & mut editor:: application:: Editor ) -> T ) -> T {
892
892
EDITOR . with ( |editor| {
893
- let Some ( Ok ( mut editor) ) = editor. get ( ) . map ( RefCell :: try_borrow_mut) else {
894
- // TODO: Investigate if this should just panic instead, and if not doing so right now may be the cause of silent crashes that don't inform the user that the app has panicked
895
- log:: error!( "Failed to borrow the editor" ) ;
896
- return T :: default ( ) ;
893
+ let mut guard = editor. lock ( ) ;
894
+ let Ok ( Some ( ref mut editor) ) = guard. as_deref_mut ( ) else {
895
+ panic ! ( "Failed to borrow the editor" ) ;
897
896
} ;
898
897
899
- callback ( & mut editor)
898
+ callback ( editor)
900
899
} )
901
900
}
902
901
903
902
/// Provides access to the `Editor` and its `EditorHandle` by calling the given closure with them as arguments.
904
903
pub ( crate ) fn editor_and_handle ( mut callback : impl FnMut ( & mut Editor , & mut EditorHandle ) ) {
905
- editor ( |editor| {
906
- EDITOR_HANDLE . with ( |editor_handle| {
907
- let Some ( Ok ( mut handle) ) = editor_handle. get ( ) . map ( RefCell :: try_borrow_mut) else {
904
+ EDITOR_HANDLE . with ( |editor_handle| {
905
+ editor ( |editor| {
906
+ let mut guard = editor_handle. lock ( ) ;
907
+ let Ok ( Some ( ref mut editor_handle) ) = guard. as_deref_mut ( ) else {
908
908
log:: error!( "Failed to borrow editor handle" ) ;
909
909
return ;
910
910
} ;
911
911
912
912
// Call the closure with the editor and its handle
913
- callback ( editor, & mut handle ) ;
913
+ callback ( editor, editor_handle ) ;
914
914
} )
915
915
} ) ;
916
916
}
0 commit comments