Skip to content

Commit

Permalink
Merge pull request #26 from tylerjaques/middle-click-close
Browse files Browse the repository at this point in the history
Middle mouse click to close tabs
  • Loading branch information
NickRimmer authored Dec 19, 2023
2 parents 31f1c8f + 4199c56 commit bcd6801
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/ui/tab-button/tab-button.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { TabButtonProps } from './tab-button.types'
export const useTabButton = ({ onClickClose, onClickButton, onClickCloseOthers, onClickCloseOnRight, onClickCloseAll }: TabButtonProps) => {
const contextMenuRef = React.useRef<ContextMenuRef | null>(null)
const onClickButtonInternal = (e: React.MouseEvent<HTMLElement, MouseEvent>) => onClickButton ? onClickButton(e) : null

const onClickAuxInternal = (e: React.MouseEvent<HTMLElement, MouseEvent>) => {
if (e.button === 1) {
e.stopPropagation()
if (onClickClose) onClickClose(e)
}
}

const onClickCloseInternal = (e: React.MouseEvent<HTMLElement, MouseEvent>) => {
e.stopPropagation()
if (onClickClose) onClickClose(e)
Expand Down Expand Up @@ -33,6 +41,7 @@ export const useTabButton = ({ onClickClose, onClickButton, onClickCloseOthers,
return {
contextMenuRef,
onClickButton: onClickButtonInternal,
onClickAuxButton: onClickAuxInternal,
onClickClose: onClickCloseInternal,
onContextCloseTab,
onContextCloseOthers,
Expand Down
3 changes: 2 additions & 1 deletion src/ui/tab-button/tab-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTabButton } from './tab-button.hook'

export const TabButton: FC<TabButtonProps> = (props) => {
const { children, isActive, requestId, title, method, isHidden } = props
const { contextMenuRef, onClickButton, onClickClose, onContextCloseTab, onContextCloseOthers, onContextCloseOnRight, onContextCloseAll } = useTabButton(props)
const { contextMenuRef, onClickButton, onClickAuxButton, onClickClose, onContextCloseTab, onContextCloseOthers, onContextCloseOnRight, onContextCloseAll } = useTabButton(props)

return (
<ContextMenuContainer
Expand All @@ -22,6 +22,7 @@ export const TabButton: FC<TabButtonProps> = (props) => {
<div
className={`plugin-request-navigator-tab-button ${isActive ? 'active' : ''} ${isHidden ? 'hidden' : ''}`}
onClick={onClickButton}
onAuxClick={onClickAuxButton}
data-request-id={requestId}
data-title={title}
data-method={method}
Expand Down

0 comments on commit bcd6801

Please sign in to comment.