mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-02 02:34:24 +00:00
Scroll a pane's tab row with the wheel
- Turn the wheel over the tabs to reach those past the pane's edge - Keep the shown tab in view as tabs change
This commit is contained in:
1 parent
df65c2d491
commit
2d0fd268de
1 file changed
+10
-1
@@ -1,4 +1,4 @@
|
|||||||
import { Activity, createContext, useContext, useRef, useState } from 'react'
|
import { Activity, createContext, useContext, useEffect, useRef, useState } from 'react'
|
||||||
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuTrigger } from '@/components/ui/context-menu'
|
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuTrigger } from '@/components/ui/context-menu'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { Glyph } from './Glyph'
|
import { Glyph } from './Glyph'
|
||||||
@@ -235,6 +235,10 @@ interface TabStripProps {
|
|||||||
function TabStrip({ pane, focused, single, change, viewLabel }: TabStripProps): React.JSX.Element {
|
function TabStrip({ pane, focused, single, change, viewLabel }: TabStripProps): React.JSX.Element {
|
||||||
const dragging = useContext(DraggingContext)
|
const dragging = useContext(DraggingContext)
|
||||||
const [insertAt, setInsertAt] = useState<number | null>(null)
|
const [insertAt, setInsertAt] = useState<number | null>(null)
|
||||||
|
const strip = useRef<HTMLDivElement>(null)
|
||||||
|
useEffect(() => {
|
||||||
|
strip.current?.querySelector('[aria-selected=true]')?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
|
||||||
|
}, [pane.activeId])
|
||||||
const indexAt = (event: React.DragEvent): number => {
|
const indexAt = (event: React.DragEvent): number => {
|
||||||
const tabs = [...event.currentTarget.querySelectorAll<HTMLElement>('[role=tab]')]
|
const tabs = [...event.currentTarget.querySelectorAll<HTMLElement>('[role=tab]')]
|
||||||
const after = tabs.findIndex((tab) => {
|
const after = tabs.findIndex((tab) => {
|
||||||
@@ -245,9 +249,14 @@ function TabStrip({ pane, focused, single, change, viewLabel }: TabStripProps):
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
ref={strip}
|
||||||
role="tablist"
|
role="tablist"
|
||||||
aria-label="Tabs"
|
aria-label="Tabs"
|
||||||
className="relative flex min-w-0 flex-1 items-stretch overflow-x-auto [scrollbar-width:none]"
|
className="relative flex min-w-0 flex-1 items-stretch overflow-x-auto [scrollbar-width:none]"
|
||||||
|
onWheel={(event) => {
|
||||||
|
// Tabs past the edge come into view as the wheel turns, as IntelliJ's tab row scrolls.
|
||||||
|
event.currentTarget.scrollLeft += event.deltaY + event.deltaX
|
||||||
|
}}
|
||||||
onDragOver={(event) => {
|
onDragOver={(event) => {
|
||||||
if (dragging.tabId === null) {
|
if (dragging.tabId === null) {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in new issue
Block a user