Skip to content

Commit 7cca51c

Browse files
committed
improvement
1 parent 689682b commit 7cca51c

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

editor/src/messages/input_preprocessor/input_preprocessor_message_handler.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,23 @@ impl<'a> MessageHandler<InputPreprocessorMessage, InputPreprocessorMessageContex
4848
self.keyboard.set(key as usize);
4949

5050
if !key_repeat {
51-
if let Some((last_key, last_time)) = self.last_key_down {
52-
if last_key == key && self.time.saturating_sub(last_time) < DOUBLE_CLICK_MILLISECONDS {
53-
responses.add(InputMapperMessage::DoubleTap(key));
54-
self.last_key_down = None;
55-
} else {
56-
self.last_key_down = Some((key, self.time));
57-
}
51+
let is_double_tap = if let Some((last_key, last_time)) = self.last_key_down {
52+
last_key == key && self.time.saturating_sub(last_time) < DOUBLE_CLICK_MILLISECONDS
53+
} else {
54+
false
55+
};
56+
57+
if is_double_tap {
58+
responses.add(InputMapperMessage::DoubleTap(key));
59+
self.last_key_down = None;
5860
} else {
5961
self.last_key_down = Some((key, self.time));
62+
responses.add(InputMapperMessage::KeyDownNoRepeat(key));
63+
responses.add(InputMapperMessage::KeyDown(key));
6064
}
61-
responses.add(InputMapperMessage::KeyDownNoRepeat(key));
65+
} else {
66+
responses.add(InputMapperMessage::KeyDown(key));
6267
}
63-
responses.add(InputMapperMessage::KeyDown(key));
6468
}
6569
InputPreprocessorMessage::KeyUp { key, key_repeat, modifier_keys } => {
6670
self.update_states_of_modifier_keys(modifier_keys, responses);
@@ -335,6 +339,8 @@ mod test {
335339
key_down(&mut input_preprocessor, Key::Space, &mut responses);
336340

337341
assert!(responses.contains(&InputMapperMessage::DoubleTap(Key::Space).into()));
342+
assert!(!responses.contains(&InputMapperMessage::KeyDown(Key::Space).into()));
343+
assert!(!responses.contains(&InputMapperMessage::KeyDownNoRepeat(Key::Space).into()));
338344
assert!(input_preprocessor.last_key_down.is_none());
339345
}
340346

0 commit comments

Comments
 (0)