Skip to content

Commit 558b161

Browse files
committed
fix: resolve double typing by sending Unidentified for printable keys in KeyDown and configure servo config directory correctly
1 parent b823a4b commit 558b161

3 files changed

Lines changed: 44 additions & 11 deletions

File tree

scratch/check_opts.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use libservo::Opts;
2+
3+
fn main() {
4+
let opts = Opts::default();
5+
// This script is just to check compilation
6+
// let _ = opts.cookies_path;
7+
// let _ = opts.storage_path;
8+
// let _ = opts.cache_path;
9+
}

src/app/input.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,10 @@ impl BrazenApp {
344344
tracing::trace!(target: "brazen::input", text = %text, "text input event received");
345345
}
346346

347-
// SUPPRESS single-character text input to avoid "double typing".
348-
// Servo's KeyboardEvent (KeyDown) already handles printable characters.
349-
if text.chars().count() == 1 {
350-
if input_logging {
351-
tracing::trace!(target: "brazen::input", text = %text, "suppressing single-char text input to avoid duplication in engine");
352-
}
353-
continue;
354-
}
347+
// We used to suppress single characters here to avoid double typing,
348+
// but we now handle this more robustly in the engine runtime by sending
349+
// Key::Unidentified for printable keys in KeyDown, relying on this event
350+
// for the actual character insertion.
355351

356352
if input_logging {
357353
tracing::trace!(

src/servo_upstream.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)