@@ -382,7 +382,17 @@ impl ServoUpstreamRuntime {
382382 let mut opts = libservo:: Opts :: default ( ) ;
383383 opts. ignore_certificate_errors = config. ignore_certificate_errors ;
384384 opts. certificate_path = resolved_certificate_path. as_ref ( ) . map ( |p| p. display ( ) . to_string ( ) ) ;
385- opts. config_dir = config. storage_path . as_ref ( ) . and_then ( |p| p. parent ( ) . map ( |p| p. to_path_buf ( ) ) ) ;
385+
386+ // Ensure config_dir is set to the profile directory
387+ if let Some ( storage_path) = & config. storage_path {
388+ if let Some ( parent) = storage_path. parent ( ) {
389+ opts. config_dir = Some ( parent. to_path_buf ( ) ) ;
390+ tracing:: info!( target: "brazen::servo::init" , path = ?parent, "servo config directory set" ) ;
391+ }
392+ }
393+
394+ // Explicitly set cookie path if available in libservo::Opts
395+ // opts.cookies_path = config.cookies_path.clone(); // Not supported in this version of libservo::Opts
386396
387397 // Set preferences
388398 let mut preferences = prefs:: get ( ) . clone ( ) ;
@@ -680,7 +690,20 @@ impl ServoUpstreamRuntime {
680690 if !modifiers. shift {
681691 c = c. to_lowercase ( ) ;
682692 }
683- Key :: Character ( c)
693+
694+ // Fix for "Double Typing":
695+ // Servo handles both KeyboardEvent (KeyDown) and ImeComposition/TextInput.
696+ // If we send a Key::Character in KeyDown, Servo often inserts it immediately.
697+ // To avoid duplication with TextInput (which handles IME and non-Latin layouts better),
698+ // we send Key::Unidentified for printable characters in KeyDown,
699+ // EXCEPT when a modifier like Ctrl/Alt is pressed (where we need the character for shortcuts).
700+
701+ if !modifiers. ctrl && !modifiers. alt && !modifiers. command {
702+ tracing:: trace!( target: "brazen::servo::input" , key = %c, "sending Key::Unidentified for printable char to avoid double typing" ) ;
703+ Key :: Named ( NamedKey :: Unidentified )
704+ } else {
705+ Key :: Character ( c)
706+ }
684707 } else {
685708 let named = match key {
686709 "Enter" => NamedKey :: Enter ,
@@ -705,7 +728,12 @@ impl ServoUpstreamRuntime {
705728 _ => NamedKey :: Unidentified ,
706729 } ;
707730 if key == "Space" {
708- Key :: Character ( " " . to_string ( ) )
731+ if !modifiers. ctrl && !modifiers. alt && !modifiers. command {
732+ tracing:: trace!( target: "brazen::servo::input" , "sending Key::Unidentified for Space to avoid double typing" ) ;
733+ Key :: Named ( NamedKey :: Unidentified )
734+ } else {
735+ Key :: Character ( " " . to_string ( ) )
736+ }
709737 } else {
710738 Key :: Named ( named)
711739 }
0 commit comments