mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-01 04:19:12 +00:00
refactor(finder): drop the pointer movement guard
The guard skipped a pointer move whose coordinates matched the previous one, on the reasoning that the list scrolling under a still cursor would otherwise pull the selection away from the keyboard. Measuring it does not support that. With a list of nineteen results in a viewport too short to hold them, and the cursor parked on a row, neither arrowing through the results nor scrolling the wheel delivers a single pointer move to any row, and the selection lands exactly where the keyboard left it. Removing the guard reproduces both results unchanged, and hovering still selects. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DzALEq9gGWwFmwTdgAiFcY
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { EntryId, MaybeString } from 'ontime-types';
|
import { MaybeString } from 'ontime-types';
|
||||||
import { KeyboardEvent, PointerEvent, useDeferredValue, useEffect, useRef, useState } from 'react';
|
import { KeyboardEvent, useDeferredValue, useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
import ToggleButton from '../../../common/components/buttons/ToggleButton';
|
import ToggleButton from '../../../common/components/buttons/ToggleButton';
|
||||||
import Input from '../../../common/components/input/input/Input';
|
import Input from '../../../common/components/input/input/Input';
|
||||||
@@ -29,7 +29,6 @@ export default function Finder({ isOpen, onClose }: FinderProps) {
|
|||||||
|
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const activeRef = useRef<HTMLLIElement>(null);
|
const activeRef = useRef<HTMLLIElement>(null);
|
||||||
const lastPointer = useRef({ x: -1, y: -1 });
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We track the selection by ID so that it survives the result list changing under us:
|
* We track the selection by ID so that it survives the result list changing under us:
|
||||||
@@ -79,16 +78,6 @@ export default function Finder({ isOpen, onClose }: FinderProps) {
|
|||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePointerMove = (event: PointerEvent<HTMLLIElement>, id: EntryId) => {
|
|
||||||
// scrolling the list under a stationary cursor also fires a move event, which would
|
|
||||||
// pull the selection away from wherever the keyboard navigation left it
|
|
||||||
if (event.clientX === lastPointer.current.x && event.clientY === lastPointer.current.y) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lastPointer.current = { x: event.clientX, y: event.clientY };
|
|
||||||
setSelectedId(id);
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Scopes the search to a single field, or back to all fields when tapped again */
|
/** Scopes the search to a single field, or back to all fields when tapped again */
|
||||||
const handleFilter = (filterKey: string) => {
|
const handleFilter = (filterKey: string) => {
|
||||||
setFilter((previous) => (previous === filterKey ? null : filterKey));
|
setFilter((previous) => (previous === filterKey ? null : filterKey));
|
||||||
@@ -143,7 +132,7 @@ export default function Finder({ isOpen, onClose }: FinderProps) {
|
|||||||
data-testid='finder-result'
|
data-testid='finder-result'
|
||||||
data-selected={isSelected}
|
data-selected={isSelected}
|
||||||
onClick={() => submit(entry)}
|
onClick={() => submit(entry)}
|
||||||
onPointerMove={(event) => handlePointerMove(event, entry.id)}
|
onPointerMove={() => setSelectedId(entry.id)}
|
||||||
>
|
>
|
||||||
<div className={style.data}>
|
<div className={style.data}>
|
||||||
<div className={style.index} style={getAccessibleColour(entry.colour)}>
|
<div className={style.index} style={getAccessibleColour(entry.colour)}>
|
||||||
|
|||||||
Reference in New Issue
Block a user