mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-29 08:32:27 +03:00
Added a SendKeystroke action and rewrote terminal actions to remove duplication
This commit is contained in:
parent
24cc9859c7
commit
9a59603065
@ -427,17 +427,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"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -14,6 +14,7 @@ use gpui::{
|
|||||||
use serde::Deserialize;
|
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};
|
||||||
@ -32,6 +33,9 @@ pub struct DeployContextMenu {
|
|||||||
#[derive(Clone, Default, Deserialize, PartialEq)]
|
#[derive(Clone, Default, Deserialize, PartialEq)]
|
||||||
pub struct SendText(String);
|
pub struct SendText(String);
|
||||||
|
|
||||||
|
#[derive(Clone, Default, Deserialize, PartialEq)]
|
||||||
|
pub struct SendKeystroke(String);
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
terminal,
|
terminal,
|
||||||
[
|
[
|
||||||
@ -48,19 +52,14 @@ actions!(
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
impl_actions!(terminal, [SendText]);
|
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_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);
|
||||||
@ -298,44 +297,19 @@ impl TerminalView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
///Synthesize the keyboard event corresponding to 'up'
|
fn send_keystroke(&mut self, text: &SendKeystroke, cx: &mut ViewContext<Self>) {
|
||||||
fn up(&mut self, _: &Up, 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("up").unwrap(), false)
|
term.try_keystroke(
|
||||||
|
&keystroke,
|
||||||
|
cx.global::<Settings>()
|
||||||
|
.terminal_overrides
|
||||||
|
.option_as_meta
|
||||||
|
.unwrap_or(false),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
///Synthesize the keyboard event corresponding to 'down'
|
|
||||||
fn down(&mut self, _: &Down, cx: &mut ViewContext<Self>) {
|
|
||||||
self.clear_bel(cx);
|
|
||||||
self.terminal.update(cx, |term, _| {
|
|
||||||
term.try_keystroke(&Keystroke::parse("down").unwrap(), false)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
///Synthesize the keyboard event corresponding to 'ctrl-c'
|
|
||||||
fn ctrl_c(&mut self, _: &CtrlC, cx: &mut ViewContext<Self>) {
|
|
||||||
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)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user