Rebind ctrl-
` to toggle terminal panel focus
Also, add `ctrl-~` to create new terminals. Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
parent
747fbfadeb
commit
f097444546
5 changed files with 42 additions and 34 deletions
|
@ -39,7 +39,8 @@
|
||||||
"cmd-shift-n": "workspace::NewWindow",
|
"cmd-shift-n": "workspace::NewWindow",
|
||||||
"cmd-o": "workspace::Open",
|
"cmd-o": "workspace::Open",
|
||||||
"alt-cmd-o": "projects::OpenRecent",
|
"alt-cmd-o": "projects::OpenRecent",
|
||||||
"ctrl-`": "workspace::NewTerminal"
|
"ctrl-~": "workspace::NewTerminal",
|
||||||
|
"ctrl-`": "terminal_panel::ToggleFocus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::TerminalView;
|
use crate::TerminalView;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
elements::*, AppContext, Entity, ModelHandle, Subscription, View, ViewContext, ViewHandle,
|
actions, elements::*, AppContext, Entity, ModelHandle, Subscription, View, ViewContext,
|
||||||
WeakViewHandle, WindowContext,
|
ViewHandle, WeakViewHandle, WindowContext,
|
||||||
};
|
};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use settings::{settings_file::SettingsFile, Settings, TerminalDockPosition, WorkingDirectory};
|
use settings::{settings_file::SettingsFile, Settings, TerminalDockPosition, WorkingDirectory};
|
||||||
|
@ -11,6 +11,8 @@ use workspace::{
|
||||||
pane, DraggedItem, Pane, Workspace,
|
pane, DraggedItem, Pane, Workspace,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
actions!(terminal_panel, [ToggleFocus]);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
cx.add_action(TerminalPanel::add_terminal);
|
cx.add_action(TerminalPanel::add_terminal);
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,6 +176,12 @@ impl Dock {
|
||||||
.map_or(false, |panel| panel.has_focus(cx))
|
.map_or(false, |panel| panel.has_focus(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn panel_index<T: Panel>(&self) -> Option<usize> {
|
||||||
|
self.panel_entries
|
||||||
|
.iter()
|
||||||
|
.position(|entry| entry.panel.as_any().is::<T>())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn active_panel_index(&self) -> usize {
|
pub fn active_panel_index(&self) -> usize {
|
||||||
self.active_panel_index
|
self.active_panel_index
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,6 +116,7 @@ actions!(
|
||||||
FollowNextCollaborator,
|
FollowNextCollaborator,
|
||||||
ToggleLeftDock,
|
ToggleLeftDock,
|
||||||
NewTerminal,
|
NewTerminal,
|
||||||
|
ToggleTerminalFocus,
|
||||||
NewSearch,
|
NewSearch,
|
||||||
Feedback,
|
Feedback,
|
||||||
Restart,
|
Restart,
|
||||||
|
@ -1475,17 +1476,9 @@ impl Workspace {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_panel_focus(
|
pub fn toggle_panel_focus<T: Panel>(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
&mut self,
|
for dock in [&self.left_dock, &self.bottom_dock, &self.right_dock] {
|
||||||
dock_position: DockPosition,
|
if let Some(panel_index) = dock.read(cx).panel_index::<T>() {
|
||||||
panel_index: usize,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
) {
|
|
||||||
let dock = match dock_position {
|
|
||||||
DockPosition::Left => &mut self.left_dock,
|
|
||||||
DockPosition::Bottom => &mut self.bottom_dock,
|
|
||||||
DockPosition::Right => &mut self.right_dock,
|
|
||||||
};
|
|
||||||
let active_item = dock.update(cx, |dock, cx| {
|
let active_item = dock.update(cx, |dock, cx| {
|
||||||
dock.set_open(true, cx);
|
dock.set_open(true, cx);
|
||||||
dock.activate_panel(panel_index, cx);
|
dock.activate_panel(panel_index, cx);
|
||||||
|
@ -1500,8 +1493,10 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.serialize_workspace(cx);
|
self.serialize_workspace(cx);
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {
|
fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
|
|
@ -31,14 +31,11 @@ use serde::Deserialize;
|
||||||
use serde_json::to_string_pretty;
|
use serde_json::to_string_pretty;
|
||||||
use settings::{Settings, DEFAULT_SETTINGS_ASSET_PATH};
|
use settings::{Settings, DEFAULT_SETTINGS_ASSET_PATH};
|
||||||
use std::{borrow::Cow, str, sync::Arc};
|
use std::{borrow::Cow, str, sync::Arc};
|
||||||
use terminal_view::terminal_panel::TerminalPanel;
|
use terminal_view::terminal_panel::{self, TerminalPanel};
|
||||||
use util::{channel::ReleaseChannel, paths, ResultExt};
|
use util::{channel::ReleaseChannel, paths, ResultExt};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
pub use workspace;
|
pub use workspace;
|
||||||
use workspace::{
|
use workspace::{create_and_open_local_file, open_new, AppState, NewFile, NewWindow, Workspace};
|
||||||
create_and_open_local_file, dock::DockPosition, open_new, AppState, NewFile, NewWindow,
|
|
||||||
Workspace,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, PartialEq)]
|
#[derive(Deserialize, Clone, PartialEq)]
|
||||||
pub struct OpenBrowser {
|
pub struct OpenBrowser {
|
||||||
|
@ -242,7 +239,14 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|
||||||
|workspace: &mut Workspace,
|
|workspace: &mut Workspace,
|
||||||
_: &project_panel::ToggleFocus,
|
_: &project_panel::ToggleFocus,
|
||||||
cx: &mut ViewContext<Workspace>| {
|
cx: &mut ViewContext<Workspace>| {
|
||||||
workspace.toggle_panel_focus(DockPosition::Left, 0, cx);
|
workspace.toggle_panel_focus::<ProjectPanel>(cx);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
cx.add_action(
|
||||||
|
|workspace: &mut Workspace,
|
||||||
|
_: &terminal_panel::ToggleFocus,
|
||||||
|
cx: &mut ViewContext<Workspace>| {
|
||||||
|
workspace.toggle_panel_focus::<TerminalPanel>(cx);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
cx.add_global_action({
|
cx.add_global_action({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue