Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function DiffPane({

const {
composerAnnotationsByItemId,
onSelectedLinesChange,
onLineSelectionEnd,
onGutterUtilityClick,
clear: clearComposer,
submit: submitComposer,
Expand Down Expand Up @@ -127,8 +127,9 @@ export function DiffPane({
enableLineSelection: true,
enableGutterUtility: true,
onGutterUtilityClick,
onLineSelectionEnd,
}),
[options, onGutterUtilityClick],
[options, onGutterUtilityClick, onLineSelectionEnd],
);

const renderHeaderPrefix = useCallback(
Expand Down Expand Up @@ -250,7 +251,6 @@ export function DiffPane({
style={style}
items={items}
options={codeViewOptions}
onSelectedLinesChange={onSelectedLinesChange}
renderHeaderPrefix={renderHeaderPrefix}
renderHeaderMetadata={renderHeaderMetadata}
renderAnnotation={renderAnnotation}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {
CodeViewLineSelection,
CodeViewOptions,
DiffLineAnnotation,
SelectedLineRange,
} from "@pierre/diffs";
Expand Down Expand Up @@ -55,12 +55,16 @@ interface UseDiffCommentComposerArgs {
) => Promise<{ terminalId: string } | null>;
}

type OnLineSelectionEnd = NonNullable<
CodeViewOptions<DiffAnnotationMetadata>["onLineSelectionEnd"]
>;

interface UseDiffCommentComposerResult {
composerAnnotationsByItemId: ReadonlyMap<
string,
DiffLineAnnotation<DiffAnnotationMetadata>[]
> | null;
onSelectedLinesChange: (selection: CodeViewLineSelection | null) => void;
onLineSelectionEnd: OnLineSelectionEnd;
onGutterUtilityClick: () => void;
clear: () => void;
submit: (input: DiffCommentSubmitInput) => Promise<void>;
Expand Down Expand Up @@ -102,27 +106,24 @@ export function useDiffCommentComposer({
[clear],
);

const onSelectedLinesChange = useCallback(
(selection: CodeViewLineSelection | null) => {
if (!selection) {
const onLineSelectionEnd = useCallback<OnLineSelectionEnd>(
(range, context) => {
if (context.type !== "diff") return;
if (!range) {
setComposer(null);
return;
}
setComposer({ itemId: selection.id, range: selection.range });
setComposer({ itemId: context.item.id, range });
},
[],
);

// Pierre gates the gutter "+" button's pointer flow behind a non-null
// onGutterUtilityClick (InteractionManager.startGutterSelectionFromPointerDown
// early-returns otherwise). We mirror the open from the CodeView's
// current selection — pierre updates that during the pointer session.
const onGutterUtilityClick = useCallback(() => {
const selection = codeViewRef.current?.getSelectedLines();
if (selection) {
setComposer({ itemId: selection.id, range: selection.range });
}
}, [codeViewRef]);
// early-returns otherwise). The gutter pointer-up path also fires
// notifySelectionEnd → onLineSelectionEnd, so the open is handled there;
// this stays as a required stub.
const onGutterUtilityClick = useCallback(() => {}, []);

const composerAnnotationsByItemId = useMemo(() => {
if (!composer) return null;
Expand Down Expand Up @@ -204,7 +205,7 @@ export function useDiffCommentComposer({

return {
composerAnnotationsByItemId,
onSelectedLinesChange,
onLineSelectionEnd,
onGutterUtilityClick,
clear,
submit,
Expand Down
Loading