From 748f0941c9e2291a032138b251c859d5fc7b0330 Mon Sep 17 00:00:00 2001 From: Dmitry Khlestkov Date: Sun, 1 Nov 2026 18:08:18 +0000 Subject: [PATCH] correction: a converted selection plays the correction chime The chime lived only in the word paths of the force-switch hotkey: `convert_selection` pasted the converted text back in silence, so a press that worked looked like one that did nothing. It now plays `SoundEvent::Correct` on success, gated on `general.sound_on_correct` like every other path, and stays silent when nothing was converted. --- CHANGELOG.md | 12 +++++ .../src/engine/switcher/correction.rs | 5 +++ crates/poltertype-core/src/engine/tests.rs | 45 ++++++++++++++++++- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a4eb8b..8d440bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ All notable changes to PolterType are recorded here. The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project follows [Semantic Versioning](https://semver.org/). +## [Unreleased] + +### Fixed + +- **Converting a selection now plays the correction chime.** With + `[selection] enabled`, pressing the force-switch hotkey on a selected + passage converted it, pasted it back and put the clipboard back in + complete silence — the chime lived only in the word paths, so a press + that worked looked like one that did nothing. The selection path now + chimes too, on the same "Play a soft chime on correction" setting as + every other path, and stays silent when there was nothing to convert. + ## [0.38.2] — hands off first ### Fixed diff --git a/crates/poltertype-core/src/engine/switcher/correction.rs b/crates/poltertype-core/src/engine/switcher/correction.rs index 409fb6a..4b336bb 100644 --- a/crates/poltertype-core/src/engine/switcher/correction.rs +++ b/crates/poltertype-core/src/engine/switcher/correction.rs @@ -999,6 +999,11 @@ impl SwitcherEngine { std::thread::sleep(PASTE_SETTLE); self.restore_clipboard(clipboard, previous.as_deref()); + // Text was just replaced on screen as in `apply_correction`; with no + // chime here a press that worked looked like one that did nothing. + if self.settings.snapshot().general.sound_on_correct { + self.audio.play(SoundEvent::Correct); + } info!(%from, %to, "selection converted"); let _ = self.out_tx.send(SwitcherEvent::Corrected { from_layout: from, diff --git a/crates/poltertype-core/src/engine/tests.rs b/crates/poltertype-core/src/engine/tests.rs index 0a35db9..2403ed9 100644 --- a/crates/poltertype-core/src/engine/tests.rs +++ b/crates/poltertype-core/src/engine/tests.rs @@ -1705,8 +1705,17 @@ mod engine_integration_tests { /// clipboard to fall back to, with the focused application's half /// of a copy wired to the emitter: press copy, and `selection` /// appears on the clipboard, exactly as an application answers - /// `Ctrl+C`. + /// `Ctrl+C`. Default settings in every other respect. fn selection_harness(selection: &str) -> (Harness, Arc) { + selection_harness_configured(selection, |_| {}) + } + + /// The wide harness: `tweak` gets the whole `Settings` before the + /// engine starts; this harness always enables `[selection]`. + fn selection_harness_configured( + selection: &str, + tweak: impl FnOnce(&mut crate::settings::Settings), + ) -> (Harness, Arc) { let clipboard = Arc::new(MockClipboard::default()); let emitter = MockEmitter::default(); let cb = Arc::clone(&clipboard); @@ -1724,7 +1733,10 @@ mod engine_integration_tests { None, None, None, - |s| s.selection.enabled = true, + |s| { + s.selection.enabled = true; + tweak(s); + }, Some(Arc::clone(&clipboard) as Arc), ); (h, clipboard) @@ -1759,6 +1771,35 @@ mod engine_integration_tests { Some("something the user copied earlier"), "and the user's own clipboard must be the last thing put back: {writes:?}" ); + assert!( + matches!( + h.sounds().as_slice(), + [crate::audio::SoundEvent::Correct, ..] + ), + "and a converted selection must chime like every other correction: {:?}", + h.sounds() + ); + } + + /// Issue #47's lesson read on the selection path too: the chime + /// gate must hold there as well. Chime off still converts — it + /// just says nothing. + #[test] + fn a_converted_selection_is_silent_when_the_chime_is_off() { + let (h, clipboard) = + selection_harness_configured("ghbdsn", |s| s.general.sound_on_correct = false); + h.cmd_tx + .send(EngineCommand::SwitchLastForcefully) + .expect("engine alive"); + h.settle(); + + assert!( + clipboard.writes().iter().any(|w| w == "привіт"), + "the conversion must still happen: {:?}", + clipboard.writes() + ); + let sounds = h.sounds(); + assert!(sounds.is_empty(), "chime off means no chime: {sounds:?}"); } /// Issue #51, the half that only X11 shows: while the chord that