Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions crates/poltertype-core/src/engine/switcher/correction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 43 additions & 2 deletions crates/poltertype-core/src/engine/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MockClipboard>) {
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<MockClipboard>) {
let clipboard = Arc::new(MockClipboard::default());
let emitter = MockEmitter::default();
let cb = Arc::clone(&clipboard);
Expand All @@ -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<dyn poltertype_input::Clipboard>),
);
(h, clipboard)
Expand Down Expand Up @@ -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
Expand Down
Loading