Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/widgets/dock_area/show/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ use crate::{
DockArea, Node, NodeIndex, Style, SurfaceIndex, TabAddAlign, TabIndex, TabStyle, TabViewer,
};

fn tab_body_id(dock_area_id: Id, path: NodePath, tab_id: Id) -> Id {
dock_area_id.with((path.surface, "surface")).with(tab_id)
}

impl<Tab> DockArea<'_, Tab> {
pub(super) fn show_leaf(
&mut self,
Expand Down Expand Up @@ -1218,7 +1222,7 @@ impl<Tab> DockArea<'_, Tab> {
// We are forced to use `Ui::new` because other methods (eg: push_id) always mix
// the provided id with their own which would cause tabs to change id when moved
// from node to node.
let id = self.id.with(tab_viewer.id(tab));
let id = tab_body_id(self.id, path, tab_viewer.id(tab));
ui.ctx().check_for_id_clash(id, body_rect, "a tab with id");
let ui = &mut Ui::new(
ui.ctx().clone(),
Expand Down Expand Up @@ -1313,3 +1317,31 @@ impl<Tab> DockArea<'_, Tab> {
}
}
}

#[cfg(test)]
mod tests {
use super::tab_body_id;
use crate::{NodeIndex, NodePath, SurfaceIndex};
use egui::Id;

#[test]
fn tab_body_ids_differ_between_surfaces() {
let dock_area_id = Id::new("dock-area");
let tab_id = Id::new("same-tab");
let node = NodeIndex::root();

let main = NodePath {
surface: SurfaceIndex::main(),
node,
};
let detached = NodePath {
surface: SurfaceIndex(1),
node,
};

assert_ne!(
tab_body_id(dock_area_id, main, tab_id),
tab_body_id(dock_area_id, detached, tab_id)
);
}
}