Skip to content

Commit

Permalink
Add tab renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
nrabulinski committed Feb 2, 2024
1 parent d2c06b3 commit 13be128
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,24 @@ fn tab_new(
Ok(())
}

fn tab_rename(
cx: &mut compositor::Context,
args: &[Cow<str>],
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<str>],
Expand Down Expand Up @@ -2901,6 +2919,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"],
Expand Down
5 changes: 5 additions & 0 deletions helix-view/src/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 13be128

Please sign in to comment.