Merge pull request #1659 from zed-industries/terminal-selections

Terminal Touch ups
This commit is contained in:
Mikayla Maki 2022-09-26 20:58:36 -07:00 committed by GitHub
commit 75594fc3e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 70 deletions

1
Cargo.lock generated
View file

@ -5489,6 +5489,7 @@ dependencies = [
"procinfo", "procinfo",
"project", "project",
"rand 0.8.5", "rand 0.8.5",
"serde",
"settings", "settings",
"shellexpand", "shellexpand",
"smallvec", "smallvec",

View file

@ -428,17 +428,45 @@
{ {
"context": "Terminal", "context": "Terminal",
"bindings": { "bindings": {
// Overrides for global bindings, remove at your own risk:
"up": "terminal::Up",
"down": "terminal::Down",
"escape": "terminal::Escape",
"enter": "terminal::Enter",
"ctrl-c": "terminal::CtrlC",
// Useful terminal actions:
"ctrl-cmd-space": "terminal::ShowCharacterPalette", "ctrl-cmd-space": "terminal::ShowCharacterPalette",
"cmd-c": "terminal::Copy", "cmd-c": "terminal::Copy",
"cmd-v": "terminal::Paste", "cmd-v": "terminal::Paste",
"cmd-k": "terminal::Clear" "cmd-k": "terminal::Clear",
// Some nice conveniences
"cmd-backspace": [
"terminal::SendText",
"\u0015"
],
"cmd-right": [
"terminal::SendText",
"\u0005"
],
"cmd-left": [
"terminal::SendText",
"\u0001"
],
// There are conflicting bindings for these keys in the global context.
// these bindings override them, remove at your own risk:
"up": [
"terminal::SendKeystroke",
"up"
],
"down": [
"terminal::SendKeystroke",
"down"
],
"escape": [
"terminal::SendKeystroke",
"escape"
],
"enter": [
"terminal::SendKeystroke",
"enter"
],
"ctrl-c": [
"terminal::SendKeystroke",
"ctrl-c"
]
} }
} }
] ]

View file

@ -30,6 +30,8 @@ libc = "0.2"
anyhow = "1" anyhow = "1"
thiserror = "1.0" thiserror = "1.0"
lazy_static = "1.4.0" lazy_static = "1.4.0"
serde = { version = "1.0", features = ["derive"] }

View file

@ -53,9 +53,7 @@ use thiserror::Error;
use gpui::{ use gpui::{
geometry::vector::{vec2f, Vector2F}, geometry::vector::{vec2f, Vector2F},
keymap::Keystroke, keymap::Keystroke,
scene::{ scene::{DownRegionEvent, DragRegionEvent, ScrollWheelRegionEvent, UpRegionEvent},
ClickRegionEvent, DownRegionEvent, DragRegionEvent, ScrollWheelRegionEvent, UpRegionEvent,
},
ClipboardItem, Entity, ModelContext, MouseButton, MouseMovedEvent, MutableAppContext, Task, ClipboardItem, Entity, ModelContext, MouseButton, MouseMovedEvent, MutableAppContext, Task,
}; };
@ -969,8 +967,6 @@ impl Terminal {
self.events self.events
.push_back(InternalEvent::Scroll(AlacScroll::Delta(scroll_lines))); .push_back(InternalEvent::Scroll(AlacScroll::Delta(scroll_lines)));
self.events
.push_back(InternalEvent::UpdateSelection(position))
} }
} }
} }
@ -996,21 +992,18 @@ impl Terminal {
self.last_content.size, self.last_content.size,
self.last_content.display_offset, self.last_content.display_offset,
); );
let side = mouse_side(position, self.last_content.size); // let side = mouse_side(position, self.last_content.size);
if self.mouse_mode(e.shift) { if self.mouse_mode(e.shift) {
if let Some(bytes) = mouse_button_report(point, e, true, self.last_content.mode) { if let Some(bytes) = mouse_button_report(point, e, true, self.last_content.mode) {
self.pty_tx.notify(bytes); self.pty_tx.notify(bytes);
} }
} else if e.button == MouseButton::Left { } else if e.button == MouseButton::Left {
self.events.push_back(InternalEvent::SetSelection(Some(( self.left_click(e, origin)
Selection::new(SelectionType::Simple, point, side),
point,
))));
} }
} }
pub fn left_click(&mut self, e: &ClickRegionEvent, origin: Vector2F) { pub fn left_click(&mut self, e: &DownRegionEvent, origin: Vector2F) {
let position = e.position.sub(origin); let position = e.position.sub(origin);
if !self.mouse_mode(e.shift) { if !self.mouse_mode(e.shift) {
//Hyperlinks //Hyperlinks

View file

@ -429,17 +429,6 @@ impl TerminalElement {
}, },
), ),
) )
// Handle click based selections
.on_click(
MouseButton::Left,
TerminalElement::generic_button_handler(
connection,
origin,
move |terminal, origin, e, _cx| {
terminal.left_click(&e, origin);
},
),
)
// Context menu // Context menu
.on_click(MouseButton::Right, move |e, cx| { .on_click(MouseButton::Right, move |e, cx| {
let mouse_mode = if let Some(conn_handle) = connection.upgrade(cx.app) { let mouse_mode = if let Some(conn_handle) = connection.upgrade(cx.app) {

View file

@ -6,13 +6,15 @@ use gpui::{
actions, actions,
elements::{AnchorCorner, ChildView, ParentElement, Stack}, elements::{AnchorCorner, ChildView, ParentElement, Stack},
geometry::vector::Vector2F, geometry::vector::Vector2F,
impl_internal_actions, impl_actions, impl_internal_actions,
keymap::Keystroke, keymap::Keystroke,
AnyViewHandle, AppContext, Element, ElementBox, Entity, ModelHandle, MutableAppContext, Task, AnyViewHandle, AppContext, Element, ElementBox, Entity, ModelHandle, MutableAppContext, Task,
View, ViewContext, ViewHandle, View, ViewContext, ViewHandle,
}; };
use serde::Deserialize;
use settings::{Settings, TerminalBlink}; use settings::{Settings, TerminalBlink};
use smol::Timer; use smol::Timer;
use util::ResultExt;
use workspace::pane; use workspace::pane;
use crate::{terminal_element::TerminalElement, Event, Terminal}; use crate::{terminal_element::TerminalElement, Event, Terminal};
@ -28,6 +30,12 @@ pub struct DeployContextMenu {
pub position: Vector2F, pub position: Vector2F,
} }
#[derive(Clone, Default, Deserialize, PartialEq)]
pub struct SendText(String);
#[derive(Clone, Default, Deserialize, PartialEq)]
pub struct SendKeystroke(String);
actions!( actions!(
terminal, terminal,
[ [
@ -43,16 +51,15 @@ actions!(
SearchTest SearchTest
] ]
); );
impl_actions!(terminal, [SendText, SendKeystroke]);
impl_internal_actions!(project_panel, [DeployContextMenu]); impl_internal_actions!(project_panel, [DeployContextMenu]);
pub fn init(cx: &mut MutableAppContext) { pub fn init(cx: &mut MutableAppContext) {
//Global binding overrrides
cx.add_action(TerminalView::ctrl_c);
cx.add_action(TerminalView::up);
cx.add_action(TerminalView::down);
cx.add_action(TerminalView::escape);
cx.add_action(TerminalView::enter);
//Useful terminal views //Useful terminal views
cx.add_action(TerminalView::send_text);
cx.add_action(TerminalView::send_keystroke);
cx.add_action(TerminalView::deploy_context_menu); cx.add_action(TerminalView::deploy_context_menu);
cx.add_action(TerminalView::copy); cx.add_action(TerminalView::copy);
cx.add_action(TerminalView::paste); cx.add_action(TerminalView::paste);
@ -283,44 +290,26 @@ impl TerminalView {
} }
} }
///Synthesize the keyboard event corresponding to 'up' fn send_text(&mut self, text: &SendText, cx: &mut ViewContext<Self>) {
fn up(&mut self, _: &Up, cx: &mut ViewContext<Self>) {
self.clear_bel(cx); self.clear_bel(cx);
self.terminal.update(cx, |term, _| { self.terminal.update(cx, |term, _| {
term.try_keystroke(&Keystroke::parse("up").unwrap(), false) term.input(text.0.to_string());
}); });
} }
///Synthesize the keyboard event corresponding to 'down' fn send_keystroke(&mut self, text: &SendKeystroke, cx: &mut ViewContext<Self>) {
fn down(&mut self, _: &Down, cx: &mut ViewContext<Self>) { if let Some(keystroke) = Keystroke::parse(&text.0).log_err() {
self.clear_bel(cx); self.clear_bel(cx);
self.terminal.update(cx, |term, _| { self.terminal.update(cx, |term, cx| {
term.try_keystroke(&Keystroke::parse("down").unwrap(), false) term.try_keystroke(
}); &keystroke,
} cx.global::<Settings>()
.terminal_overrides
///Synthesize the keyboard event corresponding to 'ctrl-c' .option_as_meta
fn ctrl_c(&mut self, _: &CtrlC, cx: &mut ViewContext<Self>) { .unwrap_or(false),
self.clear_bel(cx); );
self.terminal.update(cx, |term, _| { });
term.try_keystroke(&Keystroke::parse("ctrl-c").unwrap(), false) }
});
}
///Synthesize the keyboard event corresponding to 'escape'
fn escape(&mut self, _: &Escape, cx: &mut ViewContext<Self>) {
self.clear_bel(cx);
self.terminal.update(cx, |term, _| {
term.try_keystroke(&Keystroke::parse("escape").unwrap(), false)
});
}
///Synthesize the keyboard event corresponding to 'enter'
fn enter(&mut self, _: &Enter, cx: &mut ViewContext<Self>) {
self.clear_bel(cx);
self.terminal.update(cx, |term, _| {
term.try_keystroke(&Keystroke::parse("enter").unwrap(), false)
});
} }
} }