Add manual tab names with selected-pane fallback
This commit is contained in:
@@ -55,8 +55,8 @@ its zygote for new GUI windows, preserving existing windows and shells. Changes
|
||||
to server logic or the protocol still require restarting the server;
|
||||
`--shutdown` also ends its shell sessions.
|
||||
|
||||
This build uses protocol version 3. An older server must be restarted before
|
||||
attaching; the new `psyterm --shutdown` command can stop version-1 and version-2 servers.
|
||||
This build uses protocol version 4. An older server must be restarted before
|
||||
attaching; `psyterm --shutdown` can stop servers using versions 1–3.
|
||||
Finish any running work first, since shutdown ends its sessions, then launch
|
||||
`psyterm` again to start the updated server.
|
||||
|
||||
@@ -118,8 +118,9 @@ run `psyterm --shutdown` on the remote host, for example through SSH.
|
||||
| Ctrl+Shift+Left / Right | Focus the previous / next pane |
|
||||
| Ctrl+Shift+W | Close the focused pane and its shell |
|
||||
| Ctrl+Shift+R | Edit the pane name |
|
||||
| Palette → Rename tab | Edit the selected tab's name |
|
||||
| Enter / Esc while renaming | Save / cancel the edit |
|
||||
| Save a blank name | Restore automatic pane naming |
|
||||
| Save a blank name | Restore automatic pane/tab naming |
|
||||
| Window `×` | Detach this GUI; keep server sessions running |
|
||||
| Drag / double-click / triple-click | Select text / word / line |
|
||||
| Ctrl+Shift+C / V | Copy selection / paste with negotiated bracketed-paste mode |
|
||||
@@ -150,6 +151,13 @@ with `~`; pane headers and equal-width tabs truncate long names in the middle.
|
||||
It checks shell directories every 500 ms, including while the shell is idle. Manual names survive program title changes and client disconnects;
|
||||
returning to automatic naming uses the latest program title or directory.
|
||||
|
||||
Tabs use a manual name when set; otherwise they inherit the selected pane's
|
||||
effective name. Use **Rename tab** in the command palette to edit the tab label
|
||||
inline. Enter saves; Escape or clicking elsewhere cancels. Saving an empty name
|
||||
or choosing **Use automatic tab name** restores inheritance immediately. Tab
|
||||
names are server-owned and survive pane switches, shell exits within the tab,
|
||||
and client reconnects.
|
||||
|
||||
Tabs form the horizontal dimension; each column within a tab has an ordered
|
||||
vertical stack. One pane per stack is expanded, with the other titles above and
|
||||
below it. Creating or switching stacked panes uses the same curve as tab changes,
|
||||
@@ -267,7 +275,8 @@ Tests cover protocol framing, socket ownership, binary bridge flushing,
|
||||
key/paste encoding, palettes, fonts, cursor curves, rendering assembly, PTY
|
||||
lifecycle, and server reattachment/layout behavior. Pane tests cover natural
|
||||
shell exit, empty-tab removal, focus preservation, idle directory changes,
|
||||
program/manual name precedence, title resets, and rename persistence. Editor
|
||||
program/manual name precedence, title resets, and rename persistence. Tab-name
|
||||
tests cover manual precedence, selected-pane inheritance, resets, and reconnects. Editor
|
||||
tests cover Unicode selection and composition; protocol tests pin the previous
|
||||
versions’ shutdown handshakes. Stack tests cover insertion, navigation, hidden
|
||||
output, reattachment, exit cleanup, and command bursts without intervening snapshots.
|
||||
|
||||
+18
-10
@@ -7,10 +7,11 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
App, Div, ElementId, MouseButton, SharedString, Stateful, Window, div, prelude::*, px, rgb,
|
||||
App, Div, ElementId, Entity, MouseButton, SharedString, Stateful, Window, div, prelude::*, px,
|
||||
rgb,
|
||||
};
|
||||
|
||||
use crate::label::middle_label;
|
||||
use crate::{label::middle_label, pane_name::RenameField};
|
||||
|
||||
pub const APP_BACKGROUND: u32 = 0x06060f;
|
||||
pub const PANEL_BACKGROUND: u32 = 0x080817;
|
||||
@@ -34,6 +35,7 @@ pub struct ChromeTab {
|
||||
pub id: u64,
|
||||
pub label: SharedString,
|
||||
pub active: bool,
|
||||
pub editor: Option<Entity<RenameField>>,
|
||||
}
|
||||
|
||||
/// An app-owned titlebar. Callbacks issue server commands; no tab state lives here.
|
||||
@@ -58,6 +60,18 @@ pub fn header(
|
||||
let on_tab = on_tab.clone();
|
||||
let active = tab.active;
|
||||
let id = tab.id;
|
||||
let label = div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.h_full()
|
||||
.flex()
|
||||
.items_center()
|
||||
.overflow_hidden();
|
||||
let label = if let Some(editor) = tab.editor {
|
||||
label.child(editor)
|
||||
} else {
|
||||
label.child(middle_label(tab.label))
|
||||
};
|
||||
tab_strip = tab_strip.child(
|
||||
div()
|
||||
.id(ElementId::Name(format!("tab-{id}").into()))
|
||||
@@ -93,14 +107,7 @@ pub fn header(
|
||||
.h(px(12.))
|
||||
.bg(rgb(if active { ACCENT } else { BORDER })),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.h_full()
|
||||
.overflow_hidden()
|
||||
.child(middle_label(tab.label)),
|
||||
),
|
||||
.child(label),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -189,6 +196,7 @@ mod tests {
|
||||
id: 1,
|
||||
label: "Shell".into(),
|
||||
active: true,
|
||||
editor: None,
|
||||
}],
|
||||
|_, _, _| {},
|
||||
|_, _| {},
|
||||
|
||||
@@ -15,6 +15,8 @@ pub enum CommandAction {
|
||||
ClosePane,
|
||||
RenamePane,
|
||||
ResetPaneName,
|
||||
RenameTab,
|
||||
ResetTabName,
|
||||
Copy,
|
||||
Paste,
|
||||
PreviousTab,
|
||||
@@ -131,6 +133,22 @@ pub fn root_items(snapshot: Option<&Snapshot>) -> Vec<PaletteItem> {
|
||||
ResetPaneName,
|
||||
)
|
||||
.available(pane),
|
||||
PaletteItem::action(
|
||||
"rename-tab",
|
||||
"Rename tab",
|
||||
"name title label workspace",
|
||||
None,
|
||||
RenameTab,
|
||||
)
|
||||
.available(tabs),
|
||||
PaletteItem::action(
|
||||
"reset-tab-name",
|
||||
"Use automatic tab name",
|
||||
"reset rename title inherit selected pane",
|
||||
None,
|
||||
ResetTabName,
|
||||
)
|
||||
.available(tabs),
|
||||
PaletteItem::action(
|
||||
"previous-tab",
|
||||
"Previous tab",
|
||||
@@ -338,6 +356,8 @@ mod tests {
|
||||
assert!(!find("close-pane").enabled);
|
||||
assert!(!find("switch-tab").enabled);
|
||||
assert!(find("reset-pane-name").shortcut.is_none());
|
||||
assert!(!find("rename-tab").enabled);
|
||||
assert!(!find("reset-tab-name").enabled);
|
||||
let unique: std::collections::HashSet<_> = items.iter().map(|item| &item.id).collect();
|
||||
assert_eq!(unique.len(), items.len());
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
//! Single-line pane-name editing. UTF-8 offsets stay internal; platform input
|
||||
//! Single-line pane/tab-name editing. UTF-8 offsets stay internal; platform input
|
||||
//! methods use UTF-16 ranges. Editing never sends bytes to the terminal process.
|
||||
use std::ops::Range;
|
||||
|
||||
|
||||
+8
-1
@@ -10,7 +10,7 @@ use anyhow::{Context, Result, bail};
|
||||
use bincode::Options;
|
||||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
|
||||
pub const VERSION: u32 = 3;
|
||||
pub const VERSION: u32 = 4;
|
||||
pub const MAX_MESSAGE_BYTES: usize = 16 * 1024 * 1024;
|
||||
pub type PaneId = u64;
|
||||
pub type TabId = u64;
|
||||
@@ -96,6 +96,11 @@ pub enum ClientMessage {
|
||||
CyclePane {
|
||||
forward: bool,
|
||||
},
|
||||
/// A blank/absent name returns to the selected pane's effective name.
|
||||
RenameTab {
|
||||
tab: TabId,
|
||||
name: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -173,7 +178,9 @@ pub struct Snapshot {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TabInfo {
|
||||
pub id: TabId,
|
||||
/// Effective display name: manual override, then the selected pane's name.
|
||||
pub title: String,
|
||||
pub manual_title: Option<String>,
|
||||
/// All pane IDs, flattened in column/stack order.
|
||||
pub panes: Vec<PaneId>,
|
||||
pub active_pane: PaneId,
|
||||
|
||||
+134
-3
@@ -647,6 +647,15 @@ impl Server {
|
||||
self.refresh_directories();
|
||||
self.dirty = true;
|
||||
}
|
||||
ClientMessage::RenameTab { tab, name } => {
|
||||
self.tabs
|
||||
.iter_mut()
|
||||
.find(|entry| entry.id == tab)
|
||||
.context("unknown tab")?
|
||||
.manual_title = name.and_then(clean_title);
|
||||
self.refresh_directories();
|
||||
self.dirty = true;
|
||||
}
|
||||
ClientMessage::Hello { .. } | ClientMessage::Shutdown => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
@@ -881,6 +890,7 @@ impl Server {
|
||||
self.tabs.push(TabInfo {
|
||||
id,
|
||||
title: "Shell".into(),
|
||||
manual_title: None,
|
||||
panes: vec![pane],
|
||||
active_pane: pane,
|
||||
stacks: vec![single_pane_stack(pane)],
|
||||
@@ -939,9 +949,11 @@ impl Server {
|
||||
fn snapshot(&mut self) -> Snapshot {
|
||||
self.revision += 1;
|
||||
for tab in &mut self.tabs {
|
||||
if let Some(pane) = self.panes.get(&tab.active_pane) {
|
||||
tab.title = pane.title();
|
||||
}
|
||||
tab.title = tab
|
||||
.manual_title
|
||||
.clone()
|
||||
.or_else(|| self.panes.get(&tab.active_pane).map(Pane::title))
|
||||
.unwrap_or_else(|| "Shell".into());
|
||||
for stack in &mut tab.stacks {
|
||||
for entry in &mut stack.panes {
|
||||
if let Some(pane) = self.panes.get(&entry.id) {
|
||||
@@ -1942,6 +1954,125 @@ mod tests {
|
||||
assert!(automatic.panes[0].manual_title.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manual_tab_names_override_selected_panes_and_survive_clients_and_exit() {
|
||||
let server = TestServer::start();
|
||||
let mut client = server.client();
|
||||
send(&mut client, ClientMessage::Attach);
|
||||
let initial = snapshot(&mut client, |s| s.panes.len() == 1);
|
||||
let tab = initial.active_tab;
|
||||
let first = initial.panes[0].id;
|
||||
assert!(active_tab(&initial).manual_title.is_none());
|
||||
assert_eq!(active_tab(&initial).title, initial.panes[0].title);
|
||||
|
||||
input(&mut client, first, "printf '\\033]2;Codex\\007'\n");
|
||||
snapshot(&mut client, |s| active_tab(s).title == "Codex");
|
||||
send(
|
||||
&mut client,
|
||||
ClientMessage::NewStackPane {
|
||||
pane: None,
|
||||
direction: VerticalDirection::Down,
|
||||
cwd: None,
|
||||
},
|
||||
);
|
||||
let stacked = snapshot(&mut client, |s| active_tab(s).panes.len() == 2);
|
||||
let second = active_tab(&stacked).active_pane;
|
||||
send(
|
||||
&mut client,
|
||||
ClientMessage::RenamePane {
|
||||
pane: second,
|
||||
name: Some("Build".into()),
|
||||
},
|
||||
);
|
||||
snapshot(&mut client, |s| active_tab(s).title == "Build");
|
||||
send(
|
||||
&mut client,
|
||||
ClientMessage::RenameTab {
|
||||
tab,
|
||||
name: Some(" Pro\nject\t\u{7} ".into()),
|
||||
},
|
||||
);
|
||||
let named = snapshot(&mut client, |s| active_tab(s).title == "Project");
|
||||
assert_eq!(active_tab(&named).manual_title.as_deref(), Some("Project"));
|
||||
assert_eq!(named.panes[0].title, "Build");
|
||||
|
||||
send(&mut client, ClientMessage::FocusPane { pane: first });
|
||||
input(&mut client, first, "printf '\\033]2;Editor\\007'\n");
|
||||
let changed = snapshot(&mut client, |s| s.panes[0].title == "Editor");
|
||||
assert_eq!(active_tab(&changed).title, "Project");
|
||||
send(&mut client, ClientMessage::FocusPane { pane: second });
|
||||
input(&mut client, second, "exit\n");
|
||||
let exited = snapshot(&mut client, |s| active_tab(s).panes.len() == 1);
|
||||
assert_eq!(active_tab(&exited).active_pane, first);
|
||||
assert_eq!(active_tab(&exited).title, "Project");
|
||||
|
||||
send(&mut client, ClientMessage::NewTab { cwd: None });
|
||||
let another = snapshot(&mut client, |s| s.tabs.len() == 2);
|
||||
let other_tab = another.active_tab;
|
||||
assert!(active_tab(&another).manual_title.is_none());
|
||||
assert_eq!(active_tab(&another).title, another.panes[0].title);
|
||||
// An independent client can rename an inactive tab without stealing
|
||||
// focus. All attached views receive the server's name immediately.
|
||||
let mut other = server.client();
|
||||
send(
|
||||
&mut other,
|
||||
ClientMessage::RenameTab {
|
||||
tab,
|
||||
name: Some("Server name".into()),
|
||||
},
|
||||
);
|
||||
let renamed = snapshot(&mut client, |s| {
|
||||
s.tabs
|
||||
.iter()
|
||||
.any(|entry| entry.id == tab && entry.title == "Server name")
|
||||
});
|
||||
assert_eq!(renamed.active_tab, other_tab);
|
||||
send(&mut client, ClientMessage::Detach);
|
||||
drop(client);
|
||||
let mut client = server.client();
|
||||
send(&mut client, ClientMessage::Attach);
|
||||
let reattached = snapshot(&mut client, |s| s.tabs.len() == 2);
|
||||
let saved = reattached
|
||||
.tabs
|
||||
.iter()
|
||||
.find(|entry| entry.id == tab)
|
||||
.unwrap();
|
||||
assert_eq!(saved.title, "Server name");
|
||||
assert_eq!(saved.manual_title.as_deref(), Some("Server name"));
|
||||
|
||||
send(&mut client, ClientMessage::FocusTab { tab });
|
||||
send(
|
||||
&mut client,
|
||||
ClientMessage::RenameTab {
|
||||
tab,
|
||||
name: Some(" \n\t ".into()),
|
||||
},
|
||||
);
|
||||
let automatic = snapshot(&mut client, |s| active_tab(s).title == "Editor");
|
||||
assert!(active_tab(&automatic).manual_title.is_none());
|
||||
input(&mut client, first, "printf '\\033]2;Changed\\007'\n");
|
||||
snapshot(&mut client, |s| active_tab(s).title == "Changed");
|
||||
send(
|
||||
&mut client,
|
||||
ClientMessage::RenamePane {
|
||||
pane: first,
|
||||
name: Some("Pane override".into()),
|
||||
},
|
||||
);
|
||||
snapshot(&mut client, |s| active_tab(s).title == "Pane override");
|
||||
send(
|
||||
&mut client,
|
||||
ClientMessage::RenameTab {
|
||||
tab,
|
||||
name: Some("Pinned again".into()),
|
||||
},
|
||||
);
|
||||
snapshot(&mut client, |s| active_tab(s).title == "Pinned again");
|
||||
send(&mut client, ClientMessage::RenameTab { tab, name: None });
|
||||
let automatic = snapshot(&mut client, |s| active_tab(s).title == "Pane override");
|
||||
assert!(active_tab(&automatic).manual_title.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn displayed_titles_are_bounded_single_line_text() {
|
||||
assert_eq!(
|
||||
|
||||
+86
-1
@@ -29,6 +29,12 @@ use std::{
|
||||
};
|
||||
const PADDING: f32 = 6.;
|
||||
|
||||
struct TabRename {
|
||||
tab: u64,
|
||||
editor: Entity<RenameField>,
|
||||
_blur: Subscription,
|
||||
}
|
||||
|
||||
pub struct Workspace {
|
||||
client: Client,
|
||||
connection: SharedString,
|
||||
@@ -37,6 +43,7 @@ pub struct Workspace {
|
||||
error: Option<String>,
|
||||
focus: FocusHandle,
|
||||
palette: Option<Entity<CommandPalette>>,
|
||||
tab_rename: Option<TabRename>,
|
||||
outgoing: HashMap<u64, Entity<TerminalPane>>,
|
||||
outgoing_snapshot: Option<Arc<Snapshot>>,
|
||||
transition: Option<Slide>,
|
||||
@@ -44,6 +51,54 @@ pub struct Workspace {
|
||||
_updates: Task<()>,
|
||||
}
|
||||
impl Workspace {
|
||||
fn begin_tab_rename(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let Some(tab) = self.snapshot.as_ref().and_then(|snapshot| {
|
||||
snapshot
|
||||
.tabs
|
||||
.iter()
|
||||
.find(|tab| tab.id == snapshot.active_tab)
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
let id = tab.id;
|
||||
let initial = tab.title.clone();
|
||||
let owner = cx.weak_entity();
|
||||
let editor = cx.new(|cx| {
|
||||
RenameField::new(
|
||||
initial,
|
||||
move |name, window, cx| {
|
||||
let _ = owner.update(cx, |view, cx| {
|
||||
view.tab_rename = None;
|
||||
if let Some(name) = name
|
||||
&& let Err(error) = view.client.send(ClientMessage::RenameTab {
|
||||
tab: id,
|
||||
name: Some(name),
|
||||
})
|
||||
{
|
||||
view.error = Some(error.to_string());
|
||||
}
|
||||
view.restore_focus(window, cx);
|
||||
cx.notify();
|
||||
});
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
let focus = editor.read(cx).focus_handle(cx);
|
||||
let blur = cx.on_blur(&focus, window, |view, _, cx| {
|
||||
// Clicking elsewhere cancels the edit and keeps the clicked focus.
|
||||
view.tab_rename = None;
|
||||
cx.notify();
|
||||
});
|
||||
self.tab_rename = Some(TabRename {
|
||||
tab: id,
|
||||
editor,
|
||||
_blur: blur,
|
||||
});
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn focused_pane(&self) -> Option<Entity<TerminalPane>> {
|
||||
let snapshot = self.snapshot.as_ref()?;
|
||||
let tab = snapshot
|
||||
@@ -72,6 +127,7 @@ impl Workspace {
|
||||
self.close_palette(window, cx);
|
||||
return;
|
||||
}
|
||||
self.tab_rename = None;
|
||||
for pane in self.panes.values() {
|
||||
pane.update(cx, |pane, cx| {
|
||||
pane.rename = None;
|
||||
@@ -111,6 +167,7 @@ impl Workspace {
|
||||
return;
|
||||
}
|
||||
if self.palette.is_some()
|
||||
|| self.tab_rename.is_some()
|
||||
|| self
|
||||
.focused_pane()
|
||||
.is_some_and(|pane| pane.read(cx).rename.is_some())
|
||||
@@ -149,6 +206,17 @@ impl Workspace {
|
||||
}),
|
||||
ClosePane => pane_id.map(|pane| ClientMessage::ClosePane { pane }),
|
||||
ResetPaneName => pane_id.map(|pane| ClientMessage::RenamePane { pane, name: None }),
|
||||
ResetTabName => self
|
||||
.snapshot
|
||||
.as_ref()
|
||||
.map(|snapshot| ClientMessage::RenameTab {
|
||||
tab: snapshot.active_tab,
|
||||
name: None,
|
||||
}),
|
||||
RenameTab => {
|
||||
self.begin_tab_rename(window, cx);
|
||||
None
|
||||
}
|
||||
Copy => pane_id.map(|pane| ClientMessage::Copy { pane }),
|
||||
Scroll(kind) => pane_id.map(|pane| ClientMessage::Scroll { pane, kind }),
|
||||
FocusTab(tab) => Some(ClientMessage::FocusTab { tab }),
|
||||
@@ -226,7 +294,16 @@ impl Workspace {
|
||||
old.active_tab != snapshot.active_tab
|
||||
|| old.tabs != snapshot.tabs
|
||||
});
|
||||
let focus_allowed = view.palette.is_none();
|
||||
let cancelled_tab_rename =
|
||||
view.tab_rename.as_ref().is_some_and(|rename| {
|
||||
snapshot.active_tab != rename.tab
|
||||
|| !snapshot.tabs.iter().any(|tab| tab.id == rename.tab)
|
||||
});
|
||||
if cancelled_tab_rename {
|
||||
view.tab_rename = None;
|
||||
}
|
||||
let focus_allowed =
|
||||
view.palette.is_none() && view.tab_rename.is_none();
|
||||
if let Some(direction) = view
|
||||
.snapshot
|
||||
.as_ref()
|
||||
@@ -321,6 +398,8 @@ impl Workspace {
|
||||
palette
|
||||
.update(cx, |palette, cx| palette.set_items(items, cx));
|
||||
}
|
||||
} else if cancelled_tab_rename {
|
||||
view.restore_focus(window, cx);
|
||||
} else if view.panes.is_empty() {
|
||||
window.focus(&view.focus);
|
||||
}
|
||||
@@ -343,6 +422,7 @@ impl Workspace {
|
||||
error: None,
|
||||
focus,
|
||||
palette: None,
|
||||
tab_rename: None,
|
||||
outgoing: HashMap::new(),
|
||||
outgoing_snapshot: None,
|
||||
transition: None,
|
||||
@@ -386,6 +466,11 @@ impl Render for Workspace {
|
||||
id: tab.id,
|
||||
label: tab.title.clone().into(),
|
||||
active: tab.id == s.active_tab,
|
||||
editor: self
|
||||
.tab_rename
|
||||
.as_ref()
|
||||
.filter(|rename| rename.tab == tab.id)
|
||||
.map(|rename| rename.editor.clone()),
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
|
||||
@@ -116,6 +116,7 @@ mod tests {
|
||||
crate::protocol::TabInfo {
|
||||
id: 1,
|
||||
title: String::new(),
|
||||
manual_title: None,
|
||||
panes: ids.to_vec(),
|
||||
active_pane: active,
|
||||
stacks: vec![crate::protocol::StackInfo {
|
||||
|
||||
Reference in New Issue
Block a user