diff --git a/src/main/kotlin/app/termora/MyTabbedPane.kt b/src/main/kotlin/app/termora/MyTabbedPane.kt index d3168b2..d07ee99 100644 --- a/src/main/kotlin/app/termora/MyTabbedPane.kt +++ b/src/main/kotlin/app/termora/MyTabbedPane.kt @@ -32,6 +32,25 @@ class MyTabbedPane : FlatTabbedPane() { addMouseMotionListener(dragMouseAdaptor) } + override fun processMouseEvent(e: MouseEvent) { + // Shift + Click ===> close tab + if (e.id == MouseEvent.MOUSE_CLICKED && SwingUtilities.isLeftMouseButton(e) && isShiftPressedOnly(e.modifiersEx)) { + val index = indexAtLocation(e.x, e.y) + if (index >= 0) { + tabCloseCallback?.accept(this, index) + return + } + } + super.processMouseEvent(e) + } + + private fun isShiftPressedOnly(modifiersEx: Int): Boolean { + return (modifiersEx and InputEvent.ALT_DOWN_MASK) == 0 + && (modifiersEx and InputEvent.ALT_GRAPH_DOWN_MASK) == 0 + && (modifiersEx and InputEvent.CTRL_DOWN_MASK) == 0 + && (modifiersEx and InputEvent.SHIFT_DOWN_MASK) != 0 + } + override fun setSelectedIndex(index: Int) { val oldIndex = selectedIndex super.setSelectedIndex(index)