Skip to content

Commit 2f5e4fd

Browse files
agorischekCopilot
andcommitted
VS Code UI: playback honours playbackInViews: 'always' beside the table and text views
`viewControls` could ask for playback beside the table and text views in every mode, but the VS Code UI's `Playback` and its Space shortcut still required the Animated mode. Both now take `always` from the toolbar, as the default UI's `Playback` does. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 35e7cab commit 2f5e4fd

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎packages/host/vscode-ui/src/playback.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ const usesSpace =
3535
/**
3636
* Space toggles playback (`togglePlayback`) from the element whose `onKeyDown` calls this, for example a toolbar or the
3737
* stage's chrome: not from text fields or controls that use Space themselves (VSCode Elements included), and not from
38-
* overlays portaled out of it. Returns whether it handled the key. Does nothing unless comparing in animated mode.
38+
* overlays portaled out of it. Returns whether it handled the key. Does nothing unless comparing in animated mode, or
39+
* with `always` (playback beside the table and text views in every mode, `playbackInViews: 'always'`).
3940
*/
4041
export function handlePlaybackKey(
4142
event: KeyboardEvent<HTMLElement>,
4243
p: Pick<ProjectionController, 'comparing' | 'mode' | 'togglePlayback'>,
44+
always = false,
4345
): boolean {
4446
if (event.key !== ' ' || event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return false
45-
if (!p.comparing || p.mode !== 'animated') return false
47+
if (!p.comparing || (!always && p.mode !== 'animated')) return false
4648
const target = event.target
4749
if (!(target instanceof Element) || !event.currentTarget.contains(target) || target.closest(usesSpace)) return false
4850
event.preventDefault()
@@ -54,7 +56,8 @@ export function handlePlaybackKey(
5456
* Play, step and scrub an animated comparison, drawn like VS Code's debug toolbar: the play button in the debug
5557
* continue color (pause in the pause color), the steps as step back and step over, the "Transition" slider (Home and
5658
* End show either revision, Space on it plays and pauses; it takes the room the group has) and the percentage.
57-
* Renders nothing unless comparing in animated mode. `ends` shows the revision names at the slider's ends. `overflow`
59+
* Renders nothing unless comparing in animated mode, or with `always` (beside the table and text views in every mode,
60+
* `playbackInViews: 'always'`). `ends` shows the revision names at the slider's ends. `overflow`
5861
* moves the steps and the percentage into a "More playback controls" menu, keeping the play button and slider.
5962
*/
6063
export function Playback({
@@ -63,17 +66,19 @@ export function Playback({
6366
afterLabel,
6467
ends = true,
6568
overflow = false,
69+
always = false,
6670
}: {
6771
projection: ProjectionController
6872
beforeLabel: string
6973
afterLabel: string
7074
ends?: boolean
7175
overflow?: boolean
76+
always?: boolean
7277
}) {
7378
const id = useId()
7479
const [open, setOpen] = useState(false)
7580
const more = useRef<VscodeToolbarButton>(null)
76-
if (!p.comparing || p.mode !== 'animated') return null
81+
if (!p.comparing || (!always && p.mode !== 'animated')) return null
7782
const percent = Math.round(p.position * 100)
7883
const play = playButtonState(p, beforeLabel, afterLabel)
7984
const steps = p.stepEnds.length > 0

‎packages/host/vscode-ui/src/view/toolbar.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function ViewToolbar(toolbarProps: ViewToolbarProps) {
7373
ref={toolbar}
7474
layout={layout}
7575
style={toolbarGrid(layout, {start: Boolean(start), mode: modeRegion, playback: showPlayback})}
76-
onKeyDown={event => handlePlaybackKey(event, p)}
76+
onKeyDown={event => handlePlaybackKey(event, p, showPlayback)}
7777
>
7878
{start && <div className="phv-toolbar-start">{start}</div>}
7979
{modeRegion && (
@@ -90,6 +90,7 @@ export function ViewToolbar(toolbarProps: ViewToolbarProps) {
9090
afterLabel={afterLabel}
9191
ends={layout.sliderEnds}
9292
overflow={layout.playbackOverflow}
93+
always
9394
/>
9495
)}
9596
<div className="phv-toolbar-end">

0 commit comments

Comments
 (0)