terminal: Add right-click in terminal to create a new selection if none is present (#29131)
This PR adds functionality to right click in terminal create new selection if none present. The selection is identical with double click a text in terminal, plus the logic is moved from the double-click in the terminal::mouse_down. Closes #28237 Release Notes: - Adds functionality to right click in terminal create new selection if none present
This commit is contained in:
parent
6d2bdc3bac
commit
f8ac6eef75
2 changed files with 17 additions and 0 deletions
|
@ -1547,6 +1547,18 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn select_word_at_event_position(&mut self, e: &MouseDownEvent) {
|
||||||
|
let position = e.position - self.last_content.terminal_bounds.bounds.origin;
|
||||||
|
let (point, side) = grid_point_and_side(
|
||||||
|
position,
|
||||||
|
self.last_content.terminal_bounds,
|
||||||
|
self.last_content.display_offset,
|
||||||
|
);
|
||||||
|
let selection = Selection::new(SelectionType::Semantic, point, side);
|
||||||
|
self.events
|
||||||
|
.push_back(InternalEvent::SetSelection(Some((selection, point))));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mouse_drag(
|
pub fn mouse_drag(
|
||||||
&mut self,
|
&mut self,
|
||||||
e: &MouseMoveEvent,
|
e: &MouseMoveEvent,
|
||||||
|
|
|
@ -1278,6 +1278,11 @@ impl Render for TerminalView {
|
||||||
MouseButton::Right,
|
MouseButton::Right,
|
||||||
cx.listener(|this, event: &MouseDownEvent, window, cx| {
|
cx.listener(|this, event: &MouseDownEvent, window, cx| {
|
||||||
if !this.terminal.read(cx).mouse_mode(event.modifiers.shift) {
|
if !this.terminal.read(cx).mouse_mode(event.modifiers.shift) {
|
||||||
|
if this.terminal.read(cx).last_content.selection.is_none() {
|
||||||
|
this.terminal.update(cx, |terminal, _| {
|
||||||
|
terminal.select_word_at_event_position(event);
|
||||||
|
});
|
||||||
|
};
|
||||||
this.deploy_context_menu(event.position, window, cx);
|
this.deploy_context_menu(event.position, window, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue