Skip to content

Commit 5fb81bd

Browse files
fixed a bug with deleting the last tab
1 parent 3041852 commit 5fb81bd

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/main/java/nge/lk/mods/simpletabs/tabs/TabDisplay.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import net.minecraft.util.math.MathHelper;
99
import org.lwjgl.input.Mouse;
1010

11-
import java.util.Iterator;
1211
import java.util.Map.Entry;
1312

1413
/**
@@ -110,9 +109,7 @@ public void handleClick(final int mouseButton) {
110109
assert tabUnderMouse >= 0 : "unchecked flag value";
111110

112111
int skip = tabManager.getTabOffset() + tabUnderMouse;
113-
final Iterator<Entry<String, ChatTab>> it = tabManager.getActiveTabGroup().iterator();
114-
while (it.hasNext()) {
115-
final Entry<String, ChatTab> tab = it.next();
112+
for (final Entry<String, ChatTab> tab : tabManager.getActiveTabGroup()) {
116113
if (skip-- > 0) {
117114
continue;
118115
}
@@ -126,7 +123,7 @@ public void handleClick(final int mouseButton) {
126123
tabManager.editTab(tab.getKey(), tab.getValue());
127124
} else if (mouseButton == 2) {
128125
// Middle mouse button.
129-
it.remove();
126+
tabManager.deleteTab(tab.getKey());
130127
resetSelectedTab();
131128
tabManager.saveState();
132129
}

src/main/java/nge/lk/mods/simpletabs/tabs/TabManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ public void makeTabActive(final String key) {
214214
// Invariant: The current tab is valid, so no change is needed even if the tab name doesn't exist.
215215
}
216216

217+
/**
218+
* Deletes the tab with the given name.
219+
*
220+
* @param key The name.
221+
*/
222+
public void deleteTab(final String key) {
223+
if (doesTabExistInActiveGroup(key)) {
224+
tabs.get(activeGroup).remove(key);
225+
}
226+
}
227+
217228
public void resetSelectedTab() {
218229
activeTab = tabs.get(activeGroup).isEmpty() ? null : tabs.get(activeGroup).keySet().stream().findFirst().get();
219230
tabOffset = 0;
@@ -279,6 +290,11 @@ public ChatTab getActiveChat() {
279290
return tabs.get(activeGroup).get(activeTab);
280291
}
281292

293+
/**
294+
* Fetches the prefix of the active tab.
295+
*
296+
* @return The prefix.
297+
*/
282298
public String getActivePrefix() {
283299
if (getActiveChat() != null) {
284300
return getActiveChat().getPrefix();

0 commit comments

Comments
 (0)