diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index b53966656..7686d96cb 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1659,6 +1659,24 @@ fn tab_new( Ok(()) } +fn tab_rename( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + if event != PromptEvent::Validate { + return Ok(()); + } + + if args.len() != 1 { + anyhow::bail!("Bad arguments. Usage: `:tab-rename name`"); + } + + cx.editor.tabs.curr_tab_mut().name = args[0].to_string(); + + Ok(()) +} + fn vsplit( cx: &mut compositor::Context, args: &[Cow], @@ -2975,6 +2993,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: tab_previous, signature: CommandSignature::none(), }, + TypableCommand { + name: "tab-rename", + aliases: &[], + doc: "Change the name of the current tab.", + fun: tab_rename, + signature: CommandSignature::none(), + }, TypableCommand { name: "vsplit", aliases: &["vs"], diff --git a/helix-view/src/tabs.rs b/helix-view/src/tabs.rs index 25aa22081..7dcd9c41d 100644 --- a/helix-view/src/tabs.rs +++ b/helix-view/src/tabs.rs @@ -46,6 +46,11 @@ impl Tabs { self.tabs.iter() } + #[inline] + pub fn curr_tab_mut(&mut self) -> &mut Tab { + self.tabs.get_mut(self.focus).unwrap() + } + #[inline] pub fn new_tab(&mut self) -> TabId { let area = self.curr_tree().area();