Skip to content

Commit c933660

Browse files
authored
cleanup(core): remove unused mouse event listeners from tui (#33368)
Cleans up unused mouse event listeners from the TUI.
1 parent c2fba1f commit c933660

File tree

5 files changed

+5
-128
lines changed

5 files changed

+5
-128
lines changed

packages/nx/src/native/tui/app.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use color_eyre::eyre::Result;
2-
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
2+
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
33
use hashbrown::HashSet;
44
use napi::bindgen_prelude::External;
55
use napi::threadsafe_function::{ErrorStrategy, ThreadsafeFunction};
@@ -807,45 +807,6 @@ impl App {
807807
}
808808
}
809809
}
810-
tui::Event::Mouse(mouse) => {
811-
// If the app is in interactive mode, interactions are with
812-
// the running task, not the app itself
813-
if !self.is_interactive_mode() {
814-
// Record that the user has interacted with the app
815-
self.user_has_interacted = true;
816-
}
817-
818-
if matches!(self.focus, Focus::MultipleOutput(_)) {
819-
self.handle_mouse_event(mouse).ok();
820-
return Ok(false);
821-
}
822-
823-
match mouse.kind {
824-
MouseEventKind::ScrollUp => {
825-
if matches!(self.focus, Focus::TaskList) {
826-
self.dispatch_action(Action::ScrollUp);
827-
} else {
828-
self.handle_key_event(KeyEvent::new(
829-
KeyCode::Up,
830-
KeyModifiers::empty(),
831-
))
832-
.ok();
833-
}
834-
}
835-
MouseEventKind::ScrollDown => {
836-
if matches!(self.focus, Focus::TaskList) {
837-
self.dispatch_action(Action::ScrollDown);
838-
} else {
839-
self.handle_key_event(KeyEvent::new(
840-
KeyCode::Down,
841-
KeyModifiers::empty(),
842-
))
843-
.ok();
844-
}
845-
}
846-
_ => {}
847-
}
848-
}
849810
_ => {}
850811
}
851812

@@ -1458,15 +1419,6 @@ impl App {
14581419
let _ = self.handle_pty_resize();
14591420
}
14601421

1461-
fn handle_mouse_event(&mut self, mouse_event: MouseEvent) -> io::Result<()> {
1462-
if let Focus::MultipleOutput(pane_idx) = self.focus {
1463-
let terminal_pane_data = &mut self.terminal_pane_data[pane_idx];
1464-
terminal_pane_data.handle_mouse_event(mouse_event)
1465-
} else {
1466-
Ok(())
1467-
}
1468-
}
1469-
14701422
/// Forward key events to the currently focused pane, if any.
14711423
fn handle_key_event(&mut self, key: KeyEvent) -> io::Result<()> {
14721424
if let Focus::MultipleOutput(pane_idx) = self.focus {

packages/nx/src/native/tui/components.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use color_eyre::eyre::Result;
2-
use crossterm::event::{KeyEvent, MouseEvent};
2+
use crossterm::event::KeyEvent;
33
use ratatui::layout::{Rect, Size};
44
use std::any::Any;
55
use tokio::sync::mpsc::UnboundedSender;
@@ -61,7 +61,6 @@ pub trait Component: Any + Send {
6161
fn handle_events(&mut self, event: Option<Event>) -> Result<Option<Action>> {
6262
let action = match event {
6363
Some(Event::Key(key_event)) => self.handle_key_event(key_event)?,
64-
Some(Event::Mouse(mouse_event)) => self.handle_mouse_event(mouse_event)?,
6564
_ => None,
6665
};
6766
Ok(action)
@@ -79,19 +78,6 @@ pub trait Component: Any + Send {
7978
let _ = key; // to appease clippy
8079
Ok(None)
8180
}
82-
/// Handle mouse events and produce actions if necessary.
83-
///
84-
/// # Arguments
85-
///
86-
/// * `mouse` - A mouse event to be processed.
87-
///
88-
/// # Returns
89-
///
90-
/// * `Result<Option<Action>>` - An action to be processed or none.
91-
fn handle_mouse_event(&mut self, mouse: MouseEvent) -> Result<Option<Action>> {
92-
let _ = mouse; // to appease clippy
93-
Ok(None)
94-
}
9581
/// Update the state of the component based on a received action. (REQUIRED)
9682
///
9783
/// # Arguments

packages/nx/src/native/tui/components/terminal_pane.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use arboard::Clipboard;
2-
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
2+
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
33
use ratatui::{
44
buffer::Buffer,
55
layout::{Alignment, Rect},
@@ -156,26 +156,6 @@ impl TerminalPaneData {
156156
Ok(None)
157157
}
158158

159-
pub fn handle_mouse_event(&mut self, event: MouseEvent) -> io::Result<()> {
160-
if let Some(pty) = &mut self.pty {
161-
let mut pty_mut = pty.as_ref().clone();
162-
if self.is_interactive {
163-
pty_mut.send_mouse_event(event);
164-
} else {
165-
match event.kind {
166-
MouseEventKind::ScrollUp => {
167-
self.scroll(ScrollDirection::Up);
168-
}
169-
MouseEventKind::ScrollDown => {
170-
self.scroll(ScrollDirection::Down);
171-
}
172-
_ => {}
173-
}
174-
}
175-
}
176-
Ok(())
177-
}
178-
179159
pub fn set_interactive(&mut self, interactive: bool) {
180160
self.is_interactive = interactive;
181161
// Reset scroll momentum when changing modes

packages/nx/src/native/tui/pty.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::scroll_momentum::{ScrollDirection, ScrollMomentum};
22
use super::utils::normalize_newlines;
3-
use crossterm::event::{KeyCode, KeyEvent, MouseEvent, MouseEventKind};
3+
use crossterm::event::{KeyCode, KeyEvent};
44
use parking_lot::Mutex;
55
use std::{
66
io::{self, Write},
@@ -201,43 +201,6 @@ impl PtyInstance {
201201
}
202202
}
203203

204-
pub fn send_mouse_event(&mut self, event: MouseEvent) {
205-
let is_interactive = self.handles_arrow_keys();
206-
debug!("Mouse event: {:?}, Interactive: {}", event, is_interactive);
207-
208-
if is_interactive {
209-
// Interactive program - send scroll as arrow keys
210-
match event.kind {
211-
MouseEventKind::ScrollUp => {
212-
self.write_input(b"\x1b[A").ok();
213-
}
214-
MouseEventKind::ScrollDown => {
215-
self.write_input(b"\x1b[B").ok();
216-
}
217-
_ => {}
218-
}
219-
} else {
220-
// Non-interactive program - handle scrolling ourselves
221-
match event.kind {
222-
MouseEventKind::ScrollUp => {
223-
let amount = self
224-
.scroll_momentum
225-
.lock()
226-
.calculate_momentum(ScrollDirection::Up);
227-
self.scroll_up(amount);
228-
}
229-
MouseEventKind::ScrollDown => {
230-
let amount = self
231-
.scroll_momentum
232-
.lock()
233-
.calculate_momentum(ScrollDirection::Down);
234-
self.scroll_down(amount);
235-
}
236-
_ => {}
237-
}
238-
}
239-
}
240-
241204
pub fn get_screen(&self) -> Option<PtyScreenRef> {
242205
self.parser
243206
.read()

packages/nx/src/native/tui/tui.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::native::tui::theme::THEME;
22
use color_eyre::eyre::Result;
33
use crossterm::{
44
cursor,
5-
event::{Event as CrosstermEvent, KeyEvent, KeyEventKind, MouseEvent},
5+
event::{Event as CrosstermEvent, KeyEvent, KeyEventKind},
66
execute,
77
terminal::{EnterAlternateScreen, LeaveAlternateScreen},
88
};
@@ -33,7 +33,6 @@ pub enum Event {
3333
FocusLost,
3434
Paste(String),
3535
Key(KeyEvent),
36-
Mouse(MouseEvent),
3736
Resize(u16, u16),
3837
}
3938

@@ -110,9 +109,6 @@ impl Tui {
110109
trace!("Key: {:?}", key);
111110
_event_tx.send(Event::Key(key)).unwrap();
112111
},
113-
CrosstermEvent::Mouse(mouse) => {
114-
_event_tx.send(Event::Mouse(mouse)).unwrap();
115-
},
116112
CrosstermEvent::Resize(x, y) => {
117113
_event_tx.send(Event::Resize(x, y)).unwrap();
118114
},

0 commit comments

Comments
 (0)