Skip to content

Commit 3499e6d

Browse files
only update count prefix after command/action is handled
Fixes #753 Fixes #764 This PR updates the logic to only update `count_prefix` if the pressed digit key is not handled as bind command or action --------- Co-authored-by: Thang Pham <[email protected]>
1 parent f408b48 commit 3499e6d

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

spotify_player/src/event/mod.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,6 @@ fn handle_key_event(
100100
let key: Key = event.into();
101101
let mut ui = state.ui.lock();
102102

103-
// Check if the key is a digit and handle count prefix
104-
if let Key::None(KeyCode::Char(c)) = key {
105-
if c.is_ascii_digit() {
106-
let digit = c.to_digit(10).unwrap() as usize;
107-
// If we have an existing count prefix, append the digit
108-
// Otherwise, start a new count (but ignore leading zeros)
109-
ui.count_prefix = match ui.count_prefix {
110-
Some(count) => Some(count * 10 + digit),
111-
None => {
112-
if digit > 0 {
113-
Some(digit)
114-
} else {
115-
None
116-
}
117-
}
118-
};
119-
return Ok(());
120-
}
121-
}
122-
123103
let mut key_sequence = ui.input_key_sequence.clone();
124104
key_sequence.keys.push(key);
125105

@@ -163,10 +143,26 @@ fn handle_key_event(
163143
ui.input_key_sequence.keys = vec![];
164144
ui.count_prefix = None;
165145
} else {
166-
ui.input_key_sequence = key_sequence;
167-
// If we didn't handle the key and it wasn't a digit, clear the count prefix
168-
if !matches!(key, Key::None(KeyCode::Char(c)) if c.is_ascii_digit()) {
169-
ui.count_prefix = None;
146+
// update the count prefix if the key is a digit
147+
match key {
148+
Key::None(KeyCode::Char(c)) if c.is_ascii_digit() => {
149+
let digit = c.to_digit(10).unwrap() as usize;
150+
ui.input_key_sequence.keys = vec![];
151+
ui.count_prefix = match ui.count_prefix {
152+
Some(count) => Some(count * 10 + digit),
153+
None => {
154+
if digit > 0 {
155+
Some(digit)
156+
} else {
157+
None
158+
}
159+
}
160+
};
161+
}
162+
_ => {
163+
ui.input_key_sequence = key_sequence;
164+
ui.count_prefix = None;
165+
}
170166
}
171167
}
172168
Ok(())

spotify_player/src/media_control.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ mod windows {
192192
..Default::default()
193193
};
194194

195-
if RegisterClassExW(&wnd_class) == 0 {
195+
if RegisterClassExW(&raw const wnd_class) == 0 {
196196
return Err(format!(
197197
"Registering class failed: {}",
198198
Error::last_os_error()
@@ -246,14 +246,14 @@ mod windows {
246246
pub fn pump_event_queue() -> bool {
247247
unsafe {
248248
let mut msg: MSG = std::mem::zeroed();
249-
let mut has_message = PeekMessageW(&mut msg, None, 0, 0, PM_REMOVE).as_bool();
249+
let mut has_message = PeekMessageW(&raw mut msg, None, 0, 0, PM_REMOVE).as_bool();
250250
while msg.message != WM_QUIT && has_message {
251-
if !IsDialogMessageW(GetAncestor(msg.hwnd, GA_ROOT), &msg).as_bool() {
252-
let _ = TranslateMessage(&msg);
253-
let _ = DispatchMessageW(&msg);
251+
if !IsDialogMessageW(GetAncestor(msg.hwnd, GA_ROOT), &raw const msg).as_bool() {
252+
let _ = TranslateMessage(&raw const msg);
253+
let _ = DispatchMessageW(&raw const msg);
254254
}
255255

256-
has_message = PeekMessageW(&mut msg, None, 0, 0, PM_REMOVE).as_bool();
256+
has_message = PeekMessageW(&raw mut msg, None, 0, 0, PM_REMOVE).as_bool();
257257
}
258258

259259
msg.message == WM_QUIT

0 commit comments

Comments
 (0)