Skip to content

Commit

Permalink
On macOS, call next responder in view's keyDown and doCommandbySelect…
Browse files Browse the repository at this point in the history
…or (#623)

* Call next responder in view's keyDown

* Bring back doCommandbySelector

* Add change file
  • Loading branch information
wusyong committed Nov 14, 2022
1 parent e9d6dad commit 045b768
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/responder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

On macOS, call next responder in view's keyDown and doCommandbySelector.
57 changes: 57 additions & 0 deletions src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ lazy_static! {
sel!(firstRectForCharacterRange:actualRange:),
first_rect_for_character_range as extern "C" fn(&Object, Sel, NSRange, *mut c_void) -> NSRect,
);
decl.add_method(
sel!(doCommandBySelector:),
do_command_by_selector as extern "C" fn(&Object, Sel, Sel),
);
decl.add_method(
sel!(keyDown:),
key_down as extern "C" fn(&mut Object, Sel, id),
Expand Down Expand Up @@ -569,6 +573,54 @@ extern "C" fn insert_text(this: &Object, _sel: Sel, string: id, _replacement_ran
trace!("Completed `insertText`");
}

extern "C" fn do_command_by_selector(this: &Object, _sel: Sel, command: Sel) {
trace!("Triggered `doCommandBySelector`");
// TODO: (Artur) all these inputs seem to trigger a key event with the correct text
// content so this is not needed anymore, it seems.

// Basically, we're sent this message whenever a keyboard event that doesn't generate a "human readable" character
// happens, i.e. newlines, tabs, and Ctrl+C.

// unsafe {
// let state_ptr: *mut c_void = *this.get_ivar("taoState");
// let state = &mut *(state_ptr as *mut ViewState);

// let mut events = VecDeque::with_capacity(1);
// if command == sel!(insertNewline:) {
// // The `else` condition would emit the same character, but I'm keeping this here both...
// // 1) as a reminder for how `doCommandBySelector` works
// // 2) to make our use of carriage return explicit
// events.push_back(EventWrapper::StaticEvent(Event::WindowEvent {
// window_id: WindowId(get_window_id(state.ns_window)),
// event: WindowEvent::ReceivedCharacter('\r'),
// }));
// } else {
// let raw_characters = state.raw_characters.take();
// if let Some(raw_characters) = raw_characters {
// for character in raw_characters
// .chars()
// .filter(|c| !is_corporate_character(*c))
// {
// events.push_back(EventWrapper::StaticEvent(Event::WindowEvent {
// window_id: WindowId(get_window_id(state.ns_window)),
// event: WindowEvent::ReceivedCharacter(character),
// }));
// }
// }
// };
// AppState::queue_events(events);
// }

unsafe {
let responder: id = msg_send![this, nextResponder];
if !responder.is_null() {
let () = msg_send![responder, doCommandBySelector: command];
}
}

trace!("Completed `doCommandBySelector`");
}

// Get characters
// fn get_characters(event: id, ignore_modifiers: bool) -> String {
// unsafe {
Expand Down Expand Up @@ -695,6 +747,11 @@ extern "C" fn key_down(this: &mut Object, _sel: Sel, event: id) {
},
};
AppState::queue_event(EventWrapper::StaticEvent(window_event));

let responder: id = msg_send![this, nextResponder];
if !responder.is_null() {
let () = msg_send![responder, keyDown: event];
}
}
trace!("Completed `keyDown`");
}
Expand Down

0 comments on commit 045b768

Please sign in to comment.