diff options
| author | Aram Drevekenin <aram@poor.dev> | 2026-02-06 10:58:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-06 10:58:35 +0100 |
| commit | d45697a7f2416220dae69e73aac2ec32f6fd20b1 (patch) | |
| tree | b0232fe686f123ffb623997c7cfb1de9fb583873 | |
| parent | fix: scrolling with double/triple-click selection (#4681) (diff) | |
| download | sl0ppij-d45697a7f2416220dae69e73aac2ec32f6fd20b1.tar.gz sl0ppij-d45697a7f2416220dae69e73aac2ec32f6fd20b1.tar.xz sl0ppij-d45697a7f2416220dae69e73aac2ec32f6fd20b1.zip | |
refactor: make tab_ids stable (#4685)
* refactor: clear distinction between tab_id and tab_position
* add tab_id to TabInfo
* add test
* rustfmt
* add pr
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | zellij-server/src/plugins/mod.rs | 8 | ||||
| -rw-r--r-- | zellij-server/src/screen.rs | 330 | ||||
| -rw-r--r-- | zellij-server/src/tab/mod.rs | 12 | ||||
| -rw-r--r-- | zellij-server/src/unit/screen_tests.rs | 87 | ||||
| -rw-r--r-- | zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap | 2 | ||||
| -rw-r--r-- | zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap | 2 | ||||
| -rw-r--r-- | zellij-utils/assets/prost/api.event.rs | 2 | ||||
| -rw-r--r-- | zellij-utils/src/data.rs | 2 | ||||
| -rw-r--r-- | zellij-utils/src/kdl/mod.rs | 8 | ||||
| -rw-r--r-- | zellij-utils/src/kdl/snapshots/zellij_utils__kdl__serialize_and_deserialize_session_info_with_data.snap | 2 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/event.proto | 1 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/event.rs | 6 |
13 files changed, 332 insertions, 131 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index af82125a..bb473c0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * feat: allow resizing panes with the mouse (https://github.com/zellij-org/zellij/pull/4678) * fix: don't trim empty colored cells when resizing terminal grid (https://github.com/zellij-org/zellij/pull/4680) * fix: prevent selection from scrolling up after double/triple-click (https://github.com/zellij-org/zellij/pull/4681) +* refactor: canonicalize tab_id vs. tab_position and expose tab_id to plugins (https://github.com/zellij-org/zellij/pull/4685) ## [0.43.1] - 2025-08-08 diff --git a/zellij-server/src/plugins/mod.rs b/zellij-server/src/plugins/mod.rs index a72c1ffa..151c1bde 100644 --- a/zellij-server/src/plugins/mod.rs +++ b/zellij-server/src/plugins/mod.rs @@ -94,7 +94,7 @@ pub enum PluginInstruction { Option<TerminalAction>, Option<TiledPaneLayout>, Vec<FloatingPaneLayout>, - usize, // tab_index + usize, // tab_id Option<Vec<CommandOrPlugin>>, // initial_panes bool, // block_on_first_terminal bool, // should change focus to new tab @@ -502,7 +502,7 @@ pub(crate) fn plugin_thread_main( terminal_action, mut tab_layout, mut floating_panes_layout, - tab_index, + tab_id, initial_panes, block_on_first_terminal, should_change_focus_to_new_tab, @@ -580,7 +580,7 @@ pub(crate) fn plugin_thread_main( let skip_cache = false; match wasm_bridge.load_plugin( &run_plugin, - Some(tab_index), + Some(tab_id), size, cwd, skip_cache, @@ -603,7 +603,7 @@ pub(crate) fn plugin_thread_main( terminal_action, tab_layout, floating_panes_layout, - tab_index, + tab_id, plugin_ids, initial_panes, block_on_first_terminal, diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 20909dc4..9c1d5523 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -1,4 +1,32 @@ //! Things related to [`Screen`]s. +//! +//! # Tab Identification +//! +//! Tabs have two distinct identifiers: +//! +//! - **ID** (`tab.id`): Stable, unique identifier that never changes after creation. +//! Used as BTreeMap key and for internal tracking. Monotonically increasing. +//! +//! - **Position** (`tab.position`): Current display order (0-based index in tab bar). +//! Changes when tabs are moved or closed. Used for user-facing operations. +//! +//! # Terminology Convention +//! +//! - **"id"**: Always means stable identifier +//! - **"position"**: Always means 0-based display order +//! - **"index"**: Synonym for "position" (used in public/plugin APIs) +//! +//! Examples: +//! - `close_tab_by_id(5)` - Closes tab with stable ID 5 +//! - `CloseTabWithIndex(2)` - Closes tab at position 2 (3rd tab visually) +//! - `get_tab_by_position(0)` - Gets first tab in display order +//! - `PluginInstruction::NewTab(tab_id, ...)` - Uses ID for async communication +//! +//! # Key Data Structures +//! +//! - `tabs: BTreeMap<usize, Tab>`: Keyed by tab.id (stable identifier) +//! - `active_tab_ids: BTreeMap<ClientId, usize>`: Maps clients to active tab ID +//! - `tab_history: BTreeMap<ClientId, Vec<usize>>`: History of tab IDs per client use std::cell::RefCell; use std::collections::{BTreeMap, HashMap, HashSet}; @@ -319,13 +347,17 @@ pub enum ScreenInstruction { (ClientId, bool), // bool -> is_web_client Option<NotificationEnd>, // completion signal ), + /// Apply layout to tab with given stable ID. + /// + /// The sixth parameter (usize) is a stable identifier (not position) from the + /// NewTab → ApplyLayout async flow that passes IDs between threads. ApplyLayout( TiledPaneLayout, Vec<FloatingPaneLayout>, Vec<(u32, HoldForCommand)>, // new pane pids Vec<(u32, HoldForCommand)>, // new floating pane pids HashMap<RunPluginOrAlias, Vec<u32>>, - usize, // tab_index + usize, // tab_id - stable identifier from NewTab instruction bool, // should change focus to new tab (ClientId, bool), // bool -> is_web_client Option<NotificationEnd>, // regular completion signal @@ -962,8 +994,8 @@ pub(crate) struct Screen { terminal_emulator_color_codes: Rc<RefCell<HashMap<usize, String>>>, connected_clients: Rc<RefCell<HashMap<ClientId, bool>>>, // bool -> is_web_client /// The indices of this [`Screen`]'s active [`Tab`]s. - active_tab_indices: BTreeMap<ClientId, usize>, - global_last_active_tab_index: usize, + active_tab_ids: BTreeMap<ClientId, usize>, + global_last_active_tab_id: usize, tab_history: BTreeMap<ClientId, Vec<usize>>, pane_history: BTreeMap<ClientId, Vec<PaneId>>, mode_info: BTreeMap<ClientId, ModeInfo>, @@ -1055,8 +1087,8 @@ impl Screen { sixel_image_store: Rc::new(RefCell::new(SixelImageStore::default())), style: client_attributes.style, connected_clients: Rc::new(RefCell::new(HashMap::new())), - active_tab_indices: BTreeMap::new(), - global_last_active_tab_index: 0, + active_tab_ids: BTreeMap::new(), + global_last_active_tab_id: 0, tabs: BTreeMap::new(), terminal_emulator_colors: Rc::new(RefCell::new(Palette::default())), terminal_emulator_color_codes: Rc::new(RefCell::new(HashMap::new())), @@ -1099,17 +1131,60 @@ impl Screen { } } - /// Returns the index where a new [`Tab`] should be created in this [`Screen`]. - /// Currently, this is right after the last currently existing tab, or `0` if + /// Generates the next available stable tab ID. + /// + /// IDs are monotonically increasing and never reused, even after tabs are closed. + /// Currently, this is one more than the last currently existing tab ID, or `0` if /// no tabs exist in this screen yet. - fn get_new_tab_index(&self) -> usize { - if let Some(index) = self.tabs.keys().last() { - *index + 1 + fn get_new_tab_id(&self) -> usize { + if let Some(id) = self.tabs.keys().last() { + *id + 1 } else { 0 } } + /// Gets a tab by its stable ID (BTreeMap key). + /// + /// Use this when you have a tab ID from active_tab_ids, tab_history, or tab.id. + fn get_tab_by_id(&self, id: usize) -> Option<&Tab> { + self.tabs.get(&id) + } + + /// Gets a mutable tab by its stable ID (BTreeMap key). + fn get_tab_by_id_mut(&mut self, id: usize) -> Option<&mut Tab> { + self.tabs.get_mut(&id) + } + + /// Gets a tab by its display position (0-based). + /// + /// Use this when you have a position from user input or visual operations. + fn get_tab_by_position(&self, position: usize) -> Option<&Tab> { + self.tabs.values().find(|t| t.position == position) + } + + /// Gets a mutable tab by its display position (0-based). + fn get_tab_by_position_mut(&mut self, position: usize) -> Option<&mut Tab> { + self.tabs.values_mut().find(|t| t.position == position) + } + + /// Gets the stable ID of the tab at the given display position. + /// + /// Use this to convert position → ID for BTreeMap lookups. + fn get_tab_id_at_position(&self, position: usize) -> Option<usize> { + self.tabs + .values() + .find(|t| t.position == position) + .map(|t| t.id) + } + + /// Gets the display position of the tab with the given ID. + /// + /// Use this to convert ID → position for user-facing operations. + fn get_tab_position_by_id(&self, id: usize) -> Option<usize> { + self.tabs.get(&id).map(|t| t.position) + } + fn move_clients_from_closed_tab( &mut self, client_ids_and_mode_infos: Vec<(ClientId, ModeInfo)>, @@ -1136,15 +1211,14 @@ impl Screen { let client_tab_history = self.tab_history.entry(client_id).or_insert_with(Vec::new); if let Some(client_previous_tab) = client_tab_history.pop() { if let Some(client_active_tab) = self.tabs.get_mut(&client_previous_tab) { - self.active_tab_indices - .insert(client_id, client_previous_tab); + self.active_tab_ids.insert(client_id, client_previous_tab); client_active_tab .add_client(client_id, Some(client_mode_info)) .with_context(err_context)?; continue; } } - self.active_tab_indices.insert(client_id, first_tab_index); + self.active_tab_ids.insert(client_id, first_tab_index); self.tabs .get_mut(&first_tab_index) .with_context(err_context)? @@ -1212,15 +1286,15 @@ impl Screen { } fn update_client_tab_focus(&mut self, client_id: ClientId, new_tab_index: usize) { - match self.active_tab_indices.remove(&client_id) { + match self.active_tab_ids.remove(&client_id) { Some(old_active_index) => { - self.active_tab_indices.insert(client_id, new_tab_index); + self.active_tab_ids.insert(client_id, new_tab_index); let client_tab_history = self.tab_history.entry(client_id).or_insert_with(Vec::new); client_tab_history.retain(|&e| e != new_tab_index); client_tab_history.push(old_active_index); }, None => { - self.active_tab_indices.insert(client_id, new_tab_index); + self.active_tab_ids.insert(client_id, new_tab_index); }, } } @@ -1247,8 +1321,8 @@ impl Screen { return Ok(()); } - let current_tab_index = current_tab.index; - let new_tab_index = new_tab.index; + let current_tab_index = current_tab.id; + let new_tab_index = new_tab.id; if self.session_is_mirrored { self.move_clients_between_tabs( current_tab_index, @@ -1406,10 +1480,10 @@ impl Screen { self.switch_active_tab_name(name, client_id) } - fn close_tab_at_index(&mut self, tab_index: usize) -> Result<()> { - let err_context = || format!("failed to close tab at index {tab_index:?}"); + fn close_tab_by_id(&mut self, tab_id: usize) -> Result<()> { + let err_context = || format!("failed to close tab at index {tab_id:?}"); - let mut tab_to_close = self.tabs.remove(&tab_index).with_context(err_context)?; + let mut tab_to_close = self.tabs.remove(&tab_id).with_context(err_context)?; let mut pane_ids = tab_to_close.get_all_pane_ids(); // here we extract the suppressed panes (these are background panes that don't care which @@ -1436,7 +1510,7 @@ impl Screen { .send_to_pty(PtyInstruction::CloseTab(pane_ids)) .with_context(err_context)?; if self.tabs.is_empty() { - self.active_tab_indices.clear(); + self.active_tab_ids.clear(); self.bus .senders .send_to_server(ServerInstruction::Render(None)) @@ -1448,9 +1522,9 @@ impl Screen { self.move_suppressed_panes_from_closed_tab(suppressed_panes) .with_context(err_context)?; let visible_tab_indices: HashSet<usize> = - self.active_tab_indices.values().copied().collect(); + self.active_tab_ids.values().copied().collect(); for t in self.tabs.values_mut() { - if visible_tab_indices.contains(&t.index) { + if visible_tab_indices.contains(&t.id) { t.set_force_render(); t.visible(true).with_context(err_context)?; } @@ -1477,10 +1551,10 @@ impl Screen { match client_id { Some(client_id) => { let active_tab_index = *self - .active_tab_indices + .active_tab_ids .get(&client_id) .with_context(err_context)?; - self.close_tab_at_index(active_tab_index) + self.close_tab_by_id(active_tab_index) .with_context(err_context) }, None => Ok(()), @@ -1601,7 +1675,7 @@ impl Screen { } } for tab_index in tabs_to_close { - self.close_tab_at_index(tab_index) + self.close_tab_by_id(tab_index) .context(err_context) .non_fatal(); } @@ -1637,10 +1711,8 @@ impl Screen { self.osc8_hyperlinks, ); - let focused_tab_index_of_followed_client_id = *self - .active_tab_indices - .get(&followed_client_id) - .unwrap_or(&0); + let focused_tab_index_of_followed_client_id = + *self.active_tab_ids.get(&followed_client_id).unwrap_or(&0); if let Some(tab) = self .tabs @@ -1717,7 +1789,7 @@ impl Screen { /// Returns an immutable reference to this [`Screen`]'s active [`Tab`]. pub fn get_active_tab(&self, client_id: ClientId) -> Result<&Tab> { - match self.active_tab_indices.get(&client_id) { + match self.active_tab_ids.get(&client_id) { Some(tab) => self .tabs .get(tab) @@ -1733,7 +1805,7 @@ impl Screen { } pub fn get_first_client_id(&self) -> Option<ClientId> { - self.active_tab_indices.keys().next().copied() + self.active_tab_ids.keys().next().copied() } /// Returns an immutable reference to this [`Screen`]'s previous active [`Tab`]. @@ -1756,7 +1828,7 @@ impl Screen { /// Returns a mutable reference to this [`Screen`]'s active [`Tab`]. pub fn get_active_tab_mut(&mut self, client_id: ClientId) -> Result<&mut Tab> { - match self.active_tab_indices.get(&client_id) { + match self.active_tab_ids.get(&client_id) { Some(tab) => self .tabs .get_mut(tab) @@ -1773,7 +1845,7 @@ impl Screen { /// Creates a new [`Tab`] in this [`Screen`] pub fn new_tab( &mut self, - tab_index: usize, + tab_id: usize, swap_layouts: (Vec<SwapTiledLayout>, Vec<SwapFloatingLayout>), tab_name: Option<String>, client_id: Option<ClientId>, @@ -1794,7 +1866,7 @@ impl Screen { let position = self.tabs.len(); let mut tab = Tab::new( - tab_index, + tab_id, position, tab_name, self.size, @@ -1838,7 +1910,7 @@ impl Screen { for (client_id, mode_info) in &self.mode_info { tab.change_mode_info(mode_info.clone(), *client_id); } - self.tabs.insert(tab_index, tab); + self.tabs.insert(tab_id, tab); Ok(()) } pub fn apply_layout( @@ -1848,15 +1920,15 @@ impl Screen { new_terminal_ids: Vec<(u32, HoldForCommand)>, new_floating_terminal_ids: Vec<(u32, HoldForCommand)>, new_plugin_ids: HashMap<RunPluginOrAlias, Vec<u32>>, - tab_index: usize, + tab_id: usize, should_change_client_focus: bool, client_id_and_is_web_client: (ClientId, bool), blocking_terminal: Option<(u32, NotificationEnd)>, ) -> Result<()> { - if self.tabs.get(&tab_index).is_none() { + if self.tabs.get(&tab_id).is_none() { // TODO: we should prevent this situation with a UI - eg. cannot close tabs with a // pending state - log::error!("Tab with index {tab_index} not found. Cannot apply layout!"); + log::error!("Tab with index {tab_id} not found. Cannot apply layout!"); return Ok(()); } let (client_id, mut is_web_client) = client_id_and_is_web_client; @@ -1877,7 +1949,7 @@ impl Screen { } else { client_id }; - let err_context = || format!("failed to apply layout for tab {tab_index:?}",); + let err_context = || format!("failed to apply layout for tab {tab_id:?}",); // move the relevant clients out of the current tab and place them in the new one let drained_clients = if should_change_client_focus { @@ -1903,7 +1975,7 @@ impl Screen { .map(|(c, _i)| *c) .collect(); for client_id in all_connected_clients { - self.update_client_tab_focus(client_id, tab_index); + self.update_client_tab_focus(client_id, tab_id); } client_mode_infos_in_source_tab } else if let Ok(active_tab) = self.get_active_tab_mut(client_id) { @@ -1915,7 +1987,7 @@ impl Screen { .with_context(err_context) .non_fatal(); } - self.update_client_tab_focus(client_id, tab_index); + self.update_client_tab_focus(client_id, tab_id); Some(client_mode_info_in_source_tab) } else { None @@ -1926,8 +1998,8 @@ impl Screen { // apply the layout to the new tab self.tabs - .get_mut(&tab_index) - .context("couldn't find tab with index {tab_index}") + .get_mut(&tab_id) + .context("couldn't find tab with index {tab_id}") .and_then(|tab| { tab.apply_layout( layout, @@ -1950,7 +2022,7 @@ impl Screen { }) .with_context(err_context)?; - if !self.active_tab_indices.contains_key(&client_id) { + if !self.active_tab_ids.contains_key(&client_id) { // this means this is a new client and we need to add it to our state properly self.add_client(client_id, is_web_client) .with_context(err_context)?; @@ -1977,11 +2049,11 @@ impl Screen { } let tab_index = if let Some((_first_client, first_active_tab_index)) = - self.active_tab_indices.iter().next() + self.active_tab_ids.iter().next() { *first_active_tab_index - } else if self.tabs.contains_key(&self.global_last_active_tab_index) { - self.global_last_active_tab_index + } else if self.tabs.contains_key(&self.global_last_active_tab_id) { + self.global_last_active_tab_id } else if self.tabs.contains_key(&0) { 0 } else if let Some(tab_index) = self.tabs.keys().next() { @@ -1990,7 +2062,7 @@ impl Screen { bail!("Can't find a valid tab to attach client to!"); }; - self.active_tab_indices.insert(client_id, tab_index); + self.active_tab_ids.insert(client_id, tab_index); self.connected_clients .borrow_mut() .insert(client_id, is_web_client); @@ -2028,9 +2100,9 @@ impl Screen { tab.visible(false).with_context(err_context)?; } } - if self.active_tab_indices.contains_key(&client_id) { - self.global_last_active_tab_index = *self.active_tab_indices.get(&client_id).unwrap(); - self.active_tab_indices.remove(&client_id); + if self.active_tab_ids.contains_key(&client_id) { + self.global_last_active_tab_id = *self.active_tab_ids.get(&client_id).unwrap(); + self.active_tab_ids.remove(&client_id); } if self.tab_history.contains_key(&client_id) { self.tab_history.remove(&client_id); @@ -2077,9 +2149,9 @@ impl Screen { let mut tab_infos_for_screen_state = BTreeMap::new(); for tab in self.tabs.values() { let all_focused_clients: Vec<ClientId> = self - .active_tab_indices + .active_tab_ids .iter() - .filter(|(_c_id, tab_position)| **tab_position == tab.index) + .filter(|(_c_id, tab_position)| **tab_position == tab.id) .map(|(c_id, _)| c_id) .copied() .collect(); @@ -2091,7 +2163,7 @@ impl Screen { let tab_info_for_screen = TabInfo { position: tab.position, name: tab.name.clone(), - active: self.active_tab_indices.values().any(|i| i == &tab.index), + active: self.active_tab_ids.values().any(|i| i == &tab.id), panes_to_hide: tab.panes_to_hide_count(), is_fullscreen_active: tab.is_fullscreen_active(), is_sync_panes_active: tab.is_sync_panes_active(), @@ -2105,19 +2177,20 @@ impl Screen { display_area_columns: tab_display_area.cols, selectable_tiled_panes_count, selectable_floating_panes_count, + tab_id: tab.id, }; tab_infos_for_screen_state.insert(tab.position, tab_info_for_screen); } - for (client_id, active_tab_index) in self.active_tab_indices.iter() { + for (client_id, active_tab_index) in self.active_tab_ids.iter() { let mut plugin_tab_updates = vec![]; for tab in self.tabs.values() { let other_focused_clients: Vec<ClientId> = if self.session_is_mirrored { vec![] } else { - self.active_tab_indices + self.active_tab_ids .iter() .filter(|(c_id, tab_position)| { - **tab_position == tab.index && *c_id != client_id + **tab_position == tab.id && *c_id != client_id }) .map(|(c_id, _)| c_id) .copied() @@ -2131,7 +2204,7 @@ impl Screen { let tab_info_for_plugins = TabInfo { position: tab.position, name: tab.name.clone(), - active: *active_tab_index == tab.index, + active: *active_tab_index == tab.id, panes_to_hide: tab.panes_to_hide_count(), is_fullscreen_active: tab.is_fullscreen_active(), is_sync_panes_active: tab.is_sync_panes_active(), @@ -2145,9 +2218,11 @@ impl Screen { display_area_columns: tab_display_area.cols, selectable_tiled_panes_count, selectable_floating_panes_count, + tab_id: tab.id, }; plugin_tab_updates.push(tab_info_for_plugins); } + plugin_tab_updates.sort_by(|a, b| a.position.cmp(&b.position)); plugin_updates.push((None, Some(*client_id), Event::TabUpdate(plugin_tab_updates))); } self.bus @@ -2198,7 +2273,7 @@ impl Screen { name: self.session_name.clone(), tabs: tab_infos, panes: pane_manifest, - connected_clients: self.active_tab_indices.keys().len(), + connected_clients: self.active_tab_ids.keys().len(), is_current_session: true, available_layouts, web_clients_allowed: self.web_sharing.web_clients_allowed(), @@ -2359,7 +2434,7 @@ impl Screen { active_tab_pos - 1 }; - self.switch_tabs(active_tab_pos, left_tab_pos, client_id); + self.switch_tabs(active_tab_pos, left_tab_pos); self.log_and_report_session_state(false) .context("failed to move tab to left")?; }, @@ -2376,21 +2451,28 @@ impl Screen { } } - fn switch_tabs(&mut self, active_tab_pos: usize, other_tab_pos: usize, client_id: u16) { - let Some(active_tab_idx) = self + /// Switches tabs at two positions, swapping their display order. + /// + /// # Arguments + /// * `active_tab_pos` - Current position of active tab (0-based) + /// * `other_tab_pos` - Position to swap with (0-based) + /// + /// NOTE: this expects positions rather than IDs (see distinction at top of file) + fn switch_tabs(&mut self, active_tab_pos: usize, other_tab_pos: usize) { + let Some(active_tab_id) = self .tabs .values() .find(|t| t.position == active_tab_pos) - .map(|t| t.index) + .map(|t| t.id) else { log::error!("Failed to find active tab at position: {}", active_tab_pos); return; }; - let Some(other_tab_idx) = self + let Some(other_tab_id) = self .tabs .values() .find(|t| t.position == other_tab_pos) - .map(|t| t.index) + .map(|t| t.id) else { log::error!( "Failed to find tab to switch to at position: {}", @@ -2399,11 +2481,11 @@ impl Screen { return; }; - if !self.tabs.contains_key(&active_tab_idx) || !self.tabs.contains_key(&other_tab_idx) { + if !self.tabs.contains_key(&active_tab_id) || !self.tabs.contains_key(&other_tab_id) { warn!( "failed to switch tabs: index {} or {} not found in {:?}", - active_tab_idx, - other_tab_idx, + active_tab_id, + other_tab_id, self.tabs.keys() ); return; @@ -2412,21 +2494,17 @@ impl Screen { // NOTE: Can `expect` here, because we checked that the keys exist above let mut active_tab = self .tabs - .remove(&active_tab_idx) + .remove(&active_tab_id) .expect("active tab not found"); let mut other_tab = self .tabs - .remove(&other_tab_idx) + .remove(&other_tab_id) .expect("other tab not found"); - std::mem::swap(&mut active_tab.index, &mut other_tab.index); std::mem::swap(&mut active_tab.position, &mut other_tab.position); - // now, `active_tab.index` is changed, so we need to update it - self.active_tab_indices.insert(client_id, active_tab.index); - - self.tabs.insert(active_tab.index, active_tab); - self.tabs.insert(other_tab.index, other_tab); + self.tabs.insert(active_tab_id, active_tab); + self.tabs.insert(other_tab_id, other_tab); } pub fn move_active_tab_to_right(&mut self, client_id: ClientId) -> Result<()> { @@ -2444,7 +2522,7 @@ impl Screen { let active_tab_pos = active_tab.position; let right_tab_pos = (active_tab_pos + 1) % self.tabs.len(); - self.switch_tabs(active_tab_pos, right_tab_pos, client_id); + self.switch_tabs(active_tab_pos, right_tab_pos); self.log_and_report_session_state(false) .context("failed to move tab to the right")?; }, @@ -2524,7 +2602,7 @@ impl Screen { ) }; - let connected_client_ids: Vec<ClientId> = self.active_tab_indices.keys().copied().collect(); + let connected_client_ids: Vec<ClientId> = self.active_tab_ids.keys().copied().collect(); for client_id in connected_client_ids { self.change_mode(mode_info.clone(), client_id) .with_context(err_context)?; @@ -2629,7 +2707,7 @@ impl Screen { let err_context = || format!("failed to focus_plugin_pane"); let mut tab_index_and_plugin_pane_id = None; let mut plugin_pane_to_move_to_active_tab = None; - let focused_tab_index = *self.active_tab_indices.get(&client_id).unwrap_or(&0); + let focused_tab_index = *self.active_tab_ids.get(&client_id).unwrap_or(&0); let all_tabs = self.get_tabs_mut(); for (tab_index, tab) in all_tabs.iter_mut() { if let Some(plugin_pane_id) = tab.find_plugin(&run_plugin) { @@ -2768,7 +2846,7 @@ impl Screen { .extract_pane(active_pane_id, false) .with_context(err_context)?; let active_pane_run_instruction = active_pane.invoked_with().clone(); - let tab_index = self.get_new_tab_index(); + let tab_index = self.get_new_tab_id(); let swap_layouts = ( default_layout.swap_tiled_layouts.clone(), default_layout.swap_floating_layouts.clone(), @@ -2841,7 +2919,7 @@ impl Screen { } let (mut tiled_panes_layout, floating_panes_layout) = self.default_layout.new_tab(); - let tab_index = self.get_new_tab_index(); + let tab_index = self.get_new_tab_id(); let swap_layouts = ( self.default_layout.swap_tiled_layouts.clone(), self.default_layout.swap_floating_layouts.clone(), @@ -3448,7 +3526,7 @@ impl Screen { } let first_client_id = self.get_first_client_id(); let active_tab_index = - first_client_id.and_then(|client_id| self.active_tab_indices.get(&client_id)); + first_client_id.and_then(|client_id| self.active_tab_ids.get(&client_id)); // Filter tabs based on optional tab_index parameter let tabs_to_process: Vec<_> = self @@ -3470,7 +3548,7 @@ impl Screen { .borrow() .iter() .map(|(c, _i)| *c) - .filter(|c| self.active_tab_indices.get(&c) == Some(&tab_index)) + .filter(|c| self.active_tab_ids.get(&c) == Some(&tab_index)) .collect(); let mut active_pane_ids: HashMap<ClientId, Option<PaneId>> = HashMap::new(); @@ -4391,7 +4469,7 @@ pub(crate) fn screen_thread_main( client_id, response_channel, } => { - let response = match screen.active_tab_indices.get(&client_id) { + let response = match screen.active_tab_ids.get(&client_id) { Some(&focused_tab_index) => match screen.get_active_pane_id(&client_id) { Some(focused_pane_id) => GetFocusedPaneInfoResponse::Ok { tab_index: focused_tab_index, @@ -4874,7 +4952,7 @@ pub(crate) fn screen_thread_main( (client_id, is_web_client), completion_tx, ) => { - let tab_index = screen.get_new_tab_index(); + let tab_index = screen.get_new_tab_id(); pending_tab_ids.insert(tab_index); let client_id_for_new_tab = if should_change_focus_to_new_tab { Some(client_id) @@ -4909,12 +4987,13 @@ pub(crate) fn screen_thread_main( new_pane_pids, new_floating_pane_pids, new_plugin_ids, - tab_index, + tab_id, should_change_focus_to_new_tab, (client_id, is_web_client), mut completion_tx, blocking_terminal, ) => { + // tab_id is a stable identifier from NewTab instruction if let Some(first_terminal_pane) = new_pane_pids.iter().next() { completion_tx .as_mut() @@ -4926,28 +5005,33 @@ pub(crate) fn screen_thread_main( new_pane_pids.clone(), new_floating_pane_pids, new_plugin_ids.clone(), - tab_index, + tab_id, should_change_focus_to_new_tab, (client_id, is_web_client), blocking_terminal, )?; - pending_tab_ids.remove(&tab_index); + pending_tab_ids.remove(&tab_id); if pending_tab_ids.is_empty() { for (tab_index, client_id) in pending_tab_switches.drain() { screen.go_to_tab(tab_index as usize + 1, client_id)?; } if should_change_focus_to_new_tab { - screen.go_to_tab(tab_index as usize + 1, client_id)?; + // Convert ID → position for go_to_tab (which expects 1-based position) + if let Some(tab_position) = screen.get_tab_position_by_id(tab_id) { + screen.go_to_tab(tab_position + 1, client_id)?; + } } } else if should_change_focus_to_new_tab { - let client_id_to_switch = if screen.active_tab_indices.contains_key(&client_id) - { + let client_id_to_switch = if screen.active_tab_ids.contains_key(&client_id) { Some(client_id) } else { - screen.active_tab_indices.keys().next().copied() + screen.active_tab_ids.keys().next().copied() }; if let Some(client_id_to_switch) = client_id_to_switch { - pending_tab_switches.insert((tab_index as usize, client_id_to_switch)); + // Convert ID → position for pending_tab_switches (which stores positions) + if let Some(tab_position) = screen.get_tab_position_by_id(tab_id) { + pending_tab_switches.insert((tab_position, client_id_to_switch)); + } } } @@ -4994,12 +5078,12 @@ pub(crate) fn screen_thread_main( let client_id_to_switch = if client_id.is_none() { None } else if screen - .active_tab_indices + .active_tab_ids .contains_key(&client_id.expect("This is checked above")) { client_id } else { - screen.active_tab_indices.keys().next().copied() + screen.active_tab_ids.keys().next().copied() }; match client_id_to_switch { // we must make sure pending_tab_ids is empty because otherwise we cannot be @@ -5029,12 +5113,12 @@ pub(crate) fn screen_thread_main( let client_id = if client_id.is_none() { None } else if screen - .active_tab_indices + .active_tab_ids .contains_key(&client_id.expect("This is checked above")) { client_id } else { - screen.active_tab_indices.keys().next().copied() + screen.active_tab_ids.keys().next().copied() }; if let Some(client_id) = client_id { let is_web_client = screen @@ -5046,7 +5130,7 @@ pub(crate) fn screen_thread_main( if let Ok(tab_exists) = screen.go_to_tab_name(tab_name.clone(), client_id) { screen.render(None)?; if create && !tab_exists { - let tab_index = screen.get_new_tab_index(); + let tab_index = screen.get_new_tab_id(); let should_change_focus_to_new_tab = true; screen.new_tab( tab_index, @@ -5403,7 +5487,7 @@ pub(crate) fn screen_thread_main( continue; } let mut tab_layout_info = tab_layouts.remove(0); - tab_layout_info.tab_index = active_tab.index; + tab_layout_info.tab_index = active_tab.id; // Set the tab name if provided if let Some(name) = tab_layout_info.tab_name.take() { active_tab.name = name; @@ -5495,7 +5579,7 @@ pub(crate) fn screen_thread_main( // 4. Close tabs that aren't in the layout if !apply_only_to_focused_tab { for tab_index in tabs_to_close { - screen.close_tab_at_index(tab_index)?; + screen.close_tab_by_id(tab_index)?; } } }, @@ -5606,7 +5690,7 @@ pub(crate) fn screen_thread_main( client_id, completion_tx, ) => { - let tab_index = screen.active_tab_indices.values().next().unwrap_or(&1); + let tab_index = screen.active_tab_ids.values().next().unwrap_or(&1); let size = Size::default(); let should_float = Some(false); let should_be_opened_in_place = false; @@ -5637,7 +5721,7 @@ pub(crate) fn screen_thread_main( floating_pane_coordinates, client_id, completion_tx, - ) => match screen.active_tab_indices.values().next() { + ) => match screen.active_tab_ids.values().next() { Some(tab_index) => { let size = Size::default(); let should_float = Some(true); @@ -5674,7 +5758,7 @@ pub(crate) fn screen_thread_main( skip_cache, client_id, completion_tx, - ) => match screen.active_tab_indices.values().next() { + ) => match screen.active_tab_ids.values().next() { Some(tab_index) => { let size = Size::default(); let should_float = None; @@ -5705,7 +5789,7 @@ pub(crate) fn screen_thread_main( }, }, ScreenInstruction::StartOrReloadPluginPane(run_plugin, pane_title, completion_tx) => { - let tab_index = screen.active_tab_indices.values().next().unwrap_or(&1); + let tab_index = screen.active_tab_ids.values().next().unwrap_or(&1); let size = Size::default(); let should_float = Some(false); @@ -5758,7 +5842,7 @@ pub(crate) fn screen_thread_main( close_replaced_pane, ); } - if screen.active_tab_indices.is_empty() && tab_index.is_none() { + if screen.active_tab_ids.is_empty() && tab_index.is_none() { pending_events_waiting_for_client.push(ScreenInstruction::AddPlugin( maybe_should_float, should_be_in_place, @@ -5895,7 +5979,7 @@ pub(crate) fn screen_thread_main( completion_tx, ) => match pane_id_to_replace { Some(pane_id_to_replace) if should_open_in_place => { - match screen.active_tab_indices.values().next() { + match screen.active_tab_ids.values().next() { Some(tab_index) => { let size = Size::default(); screen @@ -5925,14 +6009,14 @@ pub(crate) fn screen_thread_main( } }, _ => { - let client_id = if screen.active_tab_indices.contains_key(&client_id) { + let client_id = if screen.active_tab_ids.contains_key(&client_id) { Some(client_id) } else { screen.get_first_client_id() }; let client_id_and_focused_tab = client_id.and_then(|client_id| { screen - .active_tab_indices + .active_tab_ids .get(&client_id) .map(|tab_index| (*tab_index, client_id)) }); @@ -5984,7 +6068,7 @@ pub(crate) fn screen_thread_main( client_id, completion_tx, ) => match pane_id_to_replace { - Some(pane_id_to_replace) => match screen.active_tab_indices.values().next() { + Some(pane_id_to_replace) => match screen.active_tab_ids.values().next() { Some(tab_index) => { let size = Size::default(); screen @@ -6013,14 +6097,14 @@ pub(crate) fn screen_thread_main( }, }, None => { - let client_id = if screen.active_tab_indices.contains_key(&client_id) { + let client_id = if screen.active_tab_ids.contains_key(&client_id) { Some(client_id) } else { screen.get_first_client_id() }; let client_id_and_focused_tab = client_id.and_then(|client_id| { screen - .active_tab_indices + .active_tab_ids .get(&client_id) .map(|tab_index| (*tab_index, client_id)) }); @@ -6124,12 +6208,15 @@ pub(crate) fn screen_thread_main( _completion_tx, // the action ends here, dropping this will release anything // waiting for it ) => { - match screen.tabs.get_mut(&tab_index.saturating_sub(1)) { + // tab_index here is 1-based user input representing display position + let tab_position = tab_index.saturating_sub(1); // Convert to 0-based + + match screen.get_tab_by_position_mut(tab_position) { Some(tab) => { tab.name = String::from_utf8_lossy(&new_name).to_string(); }, None => { - log::error!("Failed to find tab with index: {:?}", tab_index); + log::error!("Failed to find tab at position: {}", tab_position); }, } screen.log_and_report_session_state(false)?; @@ -6225,7 +6312,7 @@ pub(crate) fn screen_thread_main( name: screen.session_name.clone(), tabs: tab_infos, panes: pane_manifest, - connected_clients: screen.active_tab_indices.keys().len(), + connected_clients: screen.active_tab_ids.keys().len(), is_current_session: true, available_layouts, web_clients_allowed: screen.web_sharing.web_clients_allowed(), @@ -6332,7 +6419,7 @@ pub(crate) fn screen_thread_main( // set the env variable set_session_name(name.clone()); let connected_client_ids: Vec<ClientId> = - screen.active_tab_indices.keys().copied().collect(); + screen.active_tab_ids.keys().copied().collect(); for client_id in connected_client_ids { if let Some(os_input) = &mut screen.bus.os_input { let _ = os_input.send_to_client( @@ -6593,7 +6680,14 @@ pub(crate) fn screen_thread_main( screen.render(None)?; }, ScreenInstruction::CloseTabWithIndex(tab_index) => { - screen.close_tab_at_index(tab_index).non_fatal() + // tab_index here means display position (0-based) per API convention + // Must map to stable ID for close_tab_by_id() + + if let Some(tab_id) = screen.get_tab_id_at_position(tab_index) { + screen.close_tab_by_id(tab_id).non_fatal(); + } else { + log::error!("Failed to find tab at position: {}", tab_index); + } }, ScreenInstruction::BreakPanesToNewTab { pane_ids, diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs index a7d216b3..dcb57491 100644 --- a/zellij-server/src/tab/mod.rs +++ b/zellij-server/src/tab/mod.rs @@ -154,7 +154,7 @@ enum BufferedTabInstruction { } pub(crate) struct Tab { - pub index: usize, + pub id: usize, pub position: usize, pub name: String, pub prev_name: String, @@ -625,7 +625,7 @@ impl Tab { // FIXME: Still too many arguments for clippy to be happy... #[allow(clippy::too_many_arguments)] pub fn new( - index: usize, + id: usize, position: usize, name: String, display_area: Size, @@ -663,7 +663,7 @@ impl Tab { web_server_port: u16, ) -> Self { let name = if name.is_empty() { - format!("Tab #{}", index + 1) + format!("Tab #{}", id + 1) } else { name }; @@ -714,7 +714,7 @@ impl Tab { let swap_layouts = SwapLayouts::new(swap_layouts, display_area.clone()); Tab { - index, + id, position, tiled_panes, floating_panes, @@ -1325,7 +1325,7 @@ impl Tab { let name = None; let client_id_or_tab_index = match client_id { Some(client_id) => ClientTabIndexOrPaneId::ClientId(client_id), - None => ClientTabIndexOrPaneId::TabIndex(self.index), + None => ClientTabIndexOrPaneId::TabIndex(self.id), }; let should_start_suppressed = false; let instruction = PtyInstruction::SpawnTerminal( @@ -3155,7 +3155,7 @@ impl Tab { selectable_tiled_panes.count() > 0 } pub fn resize_whole_tab(&mut self, new_screen_size: Size) -> Result<()> { - let err_context = || format!("failed to resize whole tab (index {})", self.index); + let err_context = || format!("failed to resize whole tab (id {})", self.id); self.floating_panes.resize(new_screen_size); // we need to do this explicitly because floating_panes.resize does not do this self.floating_panes diff --git a/zellij-server/src/unit/screen_tests.rs b/zellij-server/src/unit/screen_tests.rs index a3aa89c9..0e1ce219 100644 --- a/zellij-server/src/unit/screen_tests.rs +++ b/zellij-server/src/unit/screen_tests.rs @@ -1086,6 +1086,91 @@ fn wrapping_move_of_active_tab_to_right() { } #[test] +fn tab_id_remains_stable_after_switch() { + // Test that tab IDs remain stable when switching tabs, only positions change + let mut screen = create_fixed_size_screen(); + + new_tab(&mut screen, 1, 0); + new_tab(&mut screen, 2, 1); + new_tab(&mut screen, 3, 2); + + // Verify initial state: IDs should be 0, 1, 2 + let initial_tab_ids: Vec<usize> = screen.tabs.keys().copied().collect(); + assert_eq!( + initial_tab_ids, + vec![0, 1, 2], + "Initial tab IDs should be 0, 1, 2" + ); + + // Verify initial positions match IDs + assert_eq!(screen.tabs.get(&0).unwrap().id, 0); + assert_eq!(screen.tabs.get(&0).unwrap().position, 0); + assert_eq!(screen.tabs.get(&1).unwrap().id, 1); + assert_eq!(screen.tabs.get(&1).unwrap().position, 1); + assert_eq!(screen.tabs.get(&2).unwrap().id, 2); + assert_eq!(screen.tabs.get(&2).unwrap().position, 2); + + // Move active tab (position 2, ID 2) to right, which wraps to position 0 + // This switches tabs at positions 2 and 0 (tab IDs 2 and 0) + screen.move_active_tab_to_right(1).expect("TEST"); + + // Verify BTreeMap keys (IDs) remain unchanged + let after_switch_tab_ids: Vec<usize> = screen.tabs.keys().copied().collect(); + assert_eq!( + after_switch_tab_ids, + vec![0, 1, 2], + "Tab IDs in BTreeMap should remain 0, 1, 2 after switch" + ); + + // Verify IDs remain stable but positions are swapped + // Tab 0: was at position 0, now at position 2 (swapped with tab 2) + assert_eq!( + screen.tabs.get(&0).unwrap().id, + 0, + "Tab with ID 0 should still have ID 0" + ); + assert_eq!( + screen.tabs.get(&0).unwrap().position, + 2, + "Tab with ID 0 should now be at position 2" + ); + + // Tab 1: remains unchanged at position 1 + assert_eq!( + screen.tabs.get(&1).unwrap().id, + 1, + "Tab with ID 1 should still have ID 1" + ); + assert_eq!( + screen.tabs.get(&1).unwrap().position, + 1, + "Tab with ID 1 should remain at position 1" + ); + + // Tab 2: was at position 2, now at position 0 (swapped with tab 0) + assert_eq!( + screen.tabs.get(&2).unwrap().id, + 2, + "Tab with ID 2 should still have ID 2" + ); + assert_eq!( + screen.tabs.get(&2).unwrap().position, + 0, + "Tab with ID 2 should now be at position 0" + ); + + // Verify that lookup by position works correctly after switch + let tab_at_pos_0 = screen.tabs.values().find(|t| t.position == 0).unwrap(); + assert_eq!(tab_at_pos_0.id, 2, "Tab at position 0 should have ID 2"); + + let tab_at_pos_1 = screen.tabs.values().find(|t| t.position == 1).unwrap(); + assert_eq!(tab_at_pos_1.id, 1, "Tab at position 1 should have ID 1"); + + let tab_at_pos_2 = screen.tabs.values().find(|t| t.position == 2).unwrap(); + assert_eq!(tab_at_pos_2.id, 0, "Tab at position 2 should have ID 0"); +} + +#[test] fn move_focus_right_at_right_screen_edge_changes_tab() { let size = Size { cols: 121, @@ -1431,7 +1516,7 @@ fn attach_after_first_tab_closed() { } new_tab(&mut screen, 2, 1); - screen.close_tab_at_index(0).expect("TEST"); + screen.close_tab_by_id(0).expect("TEST"); screen.remove_client(1).expect("TEST"); screen.add_client(1, false).expect("TEST"); } diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap index 15eaadfe..c1669de6 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap @@ -1,6 +1,5 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 2929 expression: "format!(\"{:#?}\", plugin_rename_tab_instruction)" --- Some( @@ -32,6 +31,7 @@ Some( display_area_columns: 80, selectable_tiled_panes_count: 2, selectable_floating_panes_count: 0, + tab_id: 0, }, ], ), diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap index dc05c40b..f2365e71 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap @@ -1,6 +1,5 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 2979 expression: "format!(\"{:#?}\", plugin_undo_rename_tab_instruction)" --- Some( @@ -32,6 +31,7 @@ Some( display_area_columns: 80, selectable_tiled_panes_count: 2, selectable_floating_panes_count: 0, + tab_id: 0, }, ], ), diff --git a/zellij-utils/assets/prost/api.event.rs b/zellij-utils/assets/prost/api.event.rs index 03a3597c..56d0dc6c 100644 --- a/zellij-utils/assets/prost/api.event.rs +++ b/zellij-utils/assets/prost/api.event.rs @@ -585,6 +585,8 @@ pub struct TabInfo { pub selectable_tiled_panes_count: u32, #[prost(uint32, tag="16")] pub selectable_floating_panes_count: u32, + #[prost(uint32, tag="17")] + pub tab_id: u32, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] diff --git a/zellij-utils/src/data.rs b/zellij-utils/src/data.rs index 874eda10..fa4383df 100644 --- a/zellij-utils/src/data.rs +++ b/zellij-utils/src/data.rs @@ -2184,6 +2184,8 @@ pub struct TabInfo { pub selectable_tiled_panes_count: usize, /// The number of selectable (eg. not the UI bars) floating panes currently in this tab pub selectable_floating_panes_count: usize, + /// The stable identifier for this tab + pub tab_id: usize, } /// The `PaneManifest` contains a dictionary of panes, indexed by the tab position (0 indexed). diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index fb152dd1..6915c79f 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -5531,6 +5531,7 @@ impl TabInfo { optional_int_node!("selectable_tiled_panes_count", usize).unwrap_or(0); let selectable_floating_panes_count = optional_int_node!("selectable_floating_panes_count", usize).unwrap_or(0); + let tab_id = optional_int_node!("tab_id", usize).unwrap_or(0); Ok(TabInfo { position, name, @@ -5548,6 +5549,7 @@ impl TabInfo { display_area_columns, selectable_tiled_panes_count, selectable_floating_panes_count, + tab_id, }) } pub fn encode_to_kdl(&self) -> KdlDocument { @@ -5625,6 +5627,10 @@ impl TabInfo { .nodes_mut() .push(selectable_floating_panes_count); + let mut tab_id = KdlNode::new("tab_id"); + tab_id.push(self.tab_id as i64); + kdl_doucment.nodes_mut().push(tab_id); + kdl_doucment } } @@ -5974,6 +5980,7 @@ fn serialize_and_deserialize_session_info_with_data() { display_area_columns: 10, selectable_tiled_panes_count: 10, selectable_floating_panes_count: 10, + tab_id: 0, }, TabInfo { position: 1, @@ -5992,6 +5999,7 @@ fn serialize_and_deserialize_session_info_with_data() { display_area_columns: 10, selectable_tiled_panes_count: 10, selectable_floating_panes_count: 10, + tab_id: 1, }, ], panes: PaneManifest { panes }, diff --git a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__serialize_and_deserialize_session_info_with_data.snap b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__serialize_and_deserialize_session_info_with_data.snap index 44b2e8bf..f68ffb74 100644 --- a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__serialize_and_deserialize_session_info_with_data.snap +++ b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__serialize_and_deserialize_session_info_with_data.snap @@ -21,6 +21,7 @@ tabs { is_swap_layout_dirty true selectable_tiled_panes_count 10 selectable_floating_panes_count 10 + tab_id 0 } tab { position 1 @@ -38,6 +39,7 @@ tabs { is_swap_layout_dirty false selectable_tiled_panes_count 10 selectable_floating_panes_count 10 + tab_id 1 } } panes { diff --git a/zellij-utils/src/plugin_api/event.proto b/zellij-utils/src/plugin_api/event.proto index f5dadcb9..ff79d144 100644 --- a/zellij-utils/src/plugin_api/event.proto +++ b/zellij-utils/src/plugin_api/event.proto @@ -428,6 +428,7 @@ message TabInfo { uint32 display_area_columns = 14; uint32 selectable_tiled_panes_count = 15; uint32 selectable_floating_panes_count = 16; + uint32 tab_id = 17; } message ModeUpdatePayload { diff --git a/zellij-utils/src/plugin_api/event.rs b/zellij-utils/src/plugin_api/event.rs index 80d77e56..0fc31448 100644 --- a/zellij-utils/src/plugin_api/event.rs +++ b/zellij-utils/src/plugin_api/event.rs @@ -1605,6 +1605,7 @@ impl TryFrom<ProtobufTabInfo> for TabInfo { selectable_tiled_panes_count: protobuf_tab_info.selectable_tiled_panes_count as usize, selectable_floating_panes_count: protobuf_tab_info.selectable_floating_panes_count as usize, + tab_id: protobuf_tab_info.tab_id as usize, }) } } @@ -1633,6 +1634,7 @@ impl TryFrom<TabInfo> for ProtobufTabInfo { display_area_columns: tab_info.display_area_columns as u32, selectable_tiled_panes_count: tab_info.selectable_tiled_panes_count as u32, selectable_floating_panes_count: tab_info.selectable_floating_panes_count as u32, + tab_id: tab_info.tab_id as u32, }) } } @@ -2118,6 +2120,7 @@ fn serialize_tab_update_event_with_non_default_values() { display_area_columns: 10, selectable_tiled_panes_count: 10, selectable_floating_panes_count: 10, + tab_id: 0, }, TabInfo { position: 1, @@ -2136,6 +2139,7 @@ fn serialize_tab_update_event_with_non_default_values() { display_area_columns: 10, selectable_tiled_panes_count: 10, selectable_floating_panes_count: 10, + tab_id: 1, }, TabInfo::default(), ]); @@ -2409,6 +2413,7 @@ fn serialize_session_update_event_with_non_default_values() { display_area_columns: 10, selectable_tiled_panes_count: 10, selectable_floating_panes_count: 10, + tab_id: 0, }, TabInfo { position: 1, @@ -2427,6 +2432,7 @@ fn serialize_session_update_event_with_non_default_values() { display_area_columns: 10, selectable_tiled_panes_count: 10, selectable_floating_panes_count: 10, + tab_id: 1, }, TabInfo::default(), ]; |
