Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,19 @@ private TabsInfo(IdeFrameImpl @NotNull [] frames, @NotNull Map<IdeFrameImpl, Pro

IdeFrameImpl[] frames = new IdeFrameImpl[length];

for (int i = 0, founded = 0; i < allLength && founded < length; i++) {
int found = 0;
for (int i = 0; i < allLength && found < length; i++) {
int index = Foundation.invoke(tabs, "indexOfObject:", allWindows[i]).intValue();
if (index != -1) {
frames[index] = allFrames[i];
founded++;
found++;
}
}

if (found != length) {
return null; // native tab group and IDE frames are not synchronized yet
}

return new TabsInfo(frames, helpersMap);
}

Expand All @@ -171,7 +176,7 @@ private void updateTabBars(boolean create) {
int index = ArrayUtil.indexOfIdentity(info.frames, myFrame);

for (IdeFrameImpl frame : info.frames) {
if (frame == myFrame || isTabsNotVisible(frame)) {
if (isTabsNotVisible(frame)) {
createTabBarsForFrame(frame, info.helpersMap.get(frame), info.frames);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ public void createTabsForFrame(IdeFrameImpl @NotNull [] tabFrames) {
}

public void insertTabForFrame(@NotNull IdeFrameImpl tab, int index) {
if (myIndexes.containsKey(tab)) {
return;
}

createTabItem(tab, index, false);
recalculateIndexes();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ui.mac;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.wm.impl.IdeFrameImpl;
import com.intellij.testFramework.junit5.RunInEdt;
import com.intellij.testFramework.junit5.TestApplication;
import com.intellij.testFramework.junit5.TestDisposable;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

@RunInEdt
@TestApplication
public class WindowTabsComponentTest {
@Test
void insertingExistingFrameDoesNotCreateDuplicate(@TestDisposable Disposable disposable) {
IdeFrameImpl firstFrame = new IdeFrameImpl();
IdeFrameImpl secondFrame = new IdeFrameImpl();
try {
WindowTabsComponent tabs = new WindowTabsComponent(firstFrame, null, disposable);
tabs.createTabsForFrame(new IdeFrameImpl[]{firstFrame, secondFrame});

tabs.insertTabForFrame(secondFrame, 1);

assertEquals(2, tabs.getTabCount());
}
finally {
firstFrame.dispose();
secondFrame.dispose();
}
}
}