Skip to content
Draft
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
23 changes: 23 additions & 0 deletions src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,22 @@ export function App({
[activeAddNoteTarget, review.startUserNote],
);

/** Start editing the active user note and move keyboard focus into it. */
const editActiveNote = useCallback(() => {
const draft = review.editActiveNote();
if (draft) {
setFocusArea("note");
}
}, [review.editActiveNote]);

/** Start a reply draft for the active review note and move keyboard focus into it. */
const replyToActiveNote = useCallback(() => {
const draft = review.replyToActiveNote();
if (draft) {
setFocusArea("note");
}
}, [review.replyToActiveNote]);

/** Mark the inline draft note textarea as the active keyboard input. */
const focusDraftNote = useCallback(() => {
setFocusArea("note");
Expand Down Expand Up @@ -685,11 +701,14 @@ export function App({
useAppKeyboardShortcuts({
activeMenuId,
activateCurrentMenuItem,
canEditActiveNote: review.activeNoteCanEdit,
canRefreshCurrentInput,
canReplyToActiveNote: Boolean(review.activeNoteId),
closeHelp,
closeMenu,
cycleTheme,
cancelDraftNote,
editActiveNote,
focusArea,
focusFilter,
moveToAnnotatedHunk,
Expand All @@ -699,6 +718,7 @@ export function App({
openMenu,
pagerMode,
requestQuit,
replyToActiveNote,
scrollCodeHorizontally,
saveDraftNote,
scrollDiff,
Expand Down Expand Up @@ -872,6 +892,7 @@ export function App({
scrollRef={diffScrollRef}
selectedFileId={selectedFile?.id}
selectedHunkIndex={selectedHunkIndex}
activeNoteId={review.activeNoteId}
scrollToNote={review.scrollToNote}
draftNote={review.draftNote}
draftNoteFocused={focusArea === "note"}
Expand All @@ -889,7 +910,9 @@ export function App({
theme={activeTheme}
width={diffPaneWidth}
onActiveAddNoteAffordanceChange={setActiveAddNoteTarget}
onEditActiveNote={editActiveNote}
onRemoveUserNote={review.removeUserNote}
onReplyToActiveNote={replyToActiveNote}
onSaveDraftNote={saveDraftNote}
onStartUserNoteAtHunk={startUserNote}
onUpdateDraftNote={review.updateDraftNote}
Expand Down
140 changes: 120 additions & 20 deletions src/ui/components/panes/AgentInlineNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ export function AgentInlineNote({
layout,
noteCount = 1,
noteIndex = 0,
active = false,
draft,
onClose,
onEdit,
onReply,
theme,
width,
}: {
Expand All @@ -133,6 +136,7 @@ export function AgentInlineNote({
layout: Exclude<LayoutMode, "auto">;
noteCount?: number;
noteIndex?: number;
active?: boolean;
draft?: {
body: string;
focused: boolean;
Expand All @@ -143,6 +147,8 @@ export function AgentInlineNote({
onSave: () => void;
};
onClose?: () => void;
onEdit?: () => void;
onReply?: () => void;
theme: AppTheme;
width: number;
}) {
Expand Down Expand Up @@ -192,6 +198,7 @@ export function AgentInlineNote({

const closeText = onClose ? "[x]" : "";
const titleText = `${inlineNoteTitle(annotation, noteIndex, noteCount)} - ${annotationRangeLabel(annotation, file)}`;
const savedDisplayTitleText = active ? `› ${titleText}` : titleText;
const splitWidths = splitColumnWidths(width);
const canDockRight = layout === "split" && anchorSide === "new" && width >= 84;
const canDockLeft = layout === "split" && anchorSide === "old" && width >= 84;
Expand Down Expand Up @@ -257,15 +264,29 @@ export function AgentInlineNote({
: []),
];
const savedTitleText = fitText(
` ${titleText} `,
` ${savedDisplayTitleText} `,
Math.max(0, boxWidth - 4 - closeGapWidth - closeWidth),
);
const savedTopBorderSuffixWidth = Math.max(
0,
boxWidth - 3 - savedTitleText.length - closeGapWidth - closeWidth,
);
const savedTopPrefixWidth = 2 + savedTitleText.length + savedTopBorderSuffixWidth;
const replyButtonText = "[ Reply (r) ]";
const editButtonText = "[ Edit (e) ]";
const bottomBorderAction = annotation.editable
? ` ${replyButtonText} ${editButtonText} `
: ` ${replyButtonText} `;
const bottomBorderActionFits = active && boxWidth - 2 >= bottomBorderAction.length + 2;
const bottomBorderLeftWidth = bottomBorderActionFits
? Math.max(1, boxWidth - 2 - bottomBorderAction.length - 1)
: Math.max(0, boxWidth - 2);
const bottomBorderRightWidth = bottomBorderActionFits
? Math.max(0, boxWidth - 2 - bottomBorderAction.length - bottomBorderLeftWidth)
: 0;
const bottomBorder = `╰${"─".repeat(Math.max(0, boxWidth - 2))}╯`;
const savedBorderColor = theme.noteBorder;
const savedHeaderBackground = theme.panel;

if (draft) {
const draftVisibleLineCount = draftVisibleRows;
Expand Down Expand Up @@ -504,7 +525,7 @@ export function AgentInlineNote({
<text>{" ".repeat(boxLeft)}</text>
</box>
<box style={{ width: 1, height: 1, backgroundColor: theme.panel }}>
<text fg={theme.noteBorder} bg={theme.panel}>
<text fg={savedBorderColor} bg={theme.panel}>
</text>
</box>
Expand All @@ -516,7 +537,7 @@ export function AgentInlineNote({
</box>
<box style={{ width: 1, height: 1, backgroundColor: theme.panel }} />
<box style={{ width: 1, height: 1, backgroundColor: theme.panel }}>
<text fg={theme.noteBorder} bg={theme.panel}>
<text fg={savedBorderColor} bg={theme.panel}>
</text>
</box>
Expand All @@ -529,36 +550,48 @@ export function AgentInlineNote({
<box style={{ width: boxLeft, height: 1, backgroundColor: theme.panel }}>
<text>{" ".repeat(boxLeft)}</text>
</box>
<box style={{ width: savedTopPrefixWidth, height: 1, backgroundColor: theme.panel }}>
<box
style={{
width: savedTopPrefixWidth,
height: 1,
backgroundColor: savedHeaderBackground,
}}
>
<text>
<span fg={theme.noteBorder} bg={theme.panel}>
<span fg={savedBorderColor} bg={savedHeaderBackground}>
╭─
</span>
<span fg={theme.noteTitleText} bg={theme.panel}>
{savedTitleText}
</span>
<span fg={theme.noteBorder} bg={theme.panel}>
{active ? (
<strong fg={theme.noteTitleText} bg={savedHeaderBackground}>
{savedTitleText}
</strong>
) : (
<span fg={theme.noteTitleText} bg={savedHeaderBackground}>
{savedTitleText}
</span>
)}
<span fg={savedBorderColor} bg={savedHeaderBackground}>
{"─".repeat(savedTopBorderSuffixWidth)}
</span>
</text>
</box>
{closeText ? (
<box style={{ width: closeGapWidth, height: 1, backgroundColor: theme.panel }}>
<text bg={theme.panel}>{" ".repeat(closeGapWidth)}</text>
<box style={{ width: closeGapWidth, height: 1, backgroundColor: savedHeaderBackground }}>
<text bg={savedHeaderBackground}>{" ".repeat(closeGapWidth)}</text>
</box>
) : null}
{closeText ? (
<box
onMouseUp={onClose}
style={{ width: closeWidth, height: 1, backgroundColor: theme.panel }}
style={{ width: closeWidth, height: 1, backgroundColor: savedHeaderBackground }}
>
<text fg={theme.noteTitleText} bg={theme.panel}>
<text fg={theme.noteTitleText} bg={savedHeaderBackground}>
{closeText}
</text>
</box>
) : null}
<box style={{ width: 1, height: 1, backgroundColor: theme.panel }}>
<text fg={theme.noteBorder} bg={theme.panel}>
<box style={{ width: 1, height: 1, backgroundColor: savedHeaderBackground }}>
<text fg={savedBorderColor} bg={savedHeaderBackground}>
</text>
</box>
Expand All @@ -574,11 +607,78 @@ export function AgentInlineNote({
<box style={{ width: boxLeft, height: 1, backgroundColor: theme.panel }}>
<text>{" ".repeat(boxLeft)}</text>
</box>
<box style={{ width: boxWidth, height: 1, backgroundColor: theme.panel }}>
<text fg={theme.noteBorder} bg={theme.panel}>
{bottomBorder}
</text>
</box>
{bottomBorderActionFits ? (
<box
style={{
width: boxWidth,
height: 1,
flexDirection: "row",
backgroundColor: theme.panel,
}}
>
<box style={{ width: 1, height: 1, backgroundColor: theme.panel }}>
<text fg={savedBorderColor} bg={theme.panel}>
</text>
</box>
<box style={{ width: bottomBorderLeftWidth, height: 1, backgroundColor: theme.panel }}>
<text fg={savedBorderColor} bg={theme.panel}>
{"─".repeat(bottomBorderLeftWidth)}
</text>
</box>
<box style={{ width: 1, height: 1, backgroundColor: theme.panel }}>
<text fg={savedBorderColor} bg={theme.panel}>
{" "}
</text>
</box>
<box
onMouseUp={onReply}
style={{ width: replyButtonText.length, height: 1, backgroundColor: theme.panel }}
>
<text fg={theme.noteTitleText} bg={theme.panel}>
{replyButtonText}
</text>
</box>
{annotation.editable ? (
<box style={{ width: 1, height: 1, backgroundColor: theme.panel }}>
<text fg={savedBorderColor} bg={theme.panel}>
{" "}
</text>
</box>
) : null}
{annotation.editable ? (
<box
onMouseUp={onEdit}
style={{ width: editButtonText.length, height: 1, backgroundColor: theme.panel }}
>
<text fg={theme.noteTitleText} bg={theme.panel}>
{editButtonText}
</text>
</box>
) : null}
<box style={{ width: 1, height: 1, backgroundColor: theme.panel }}>
<text fg={savedBorderColor} bg={theme.panel}>
{" "}
</text>
</box>
<box style={{ width: bottomBorderRightWidth, height: 1, backgroundColor: theme.panel }}>
<text fg={savedBorderColor} bg={theme.panel}>
{"─".repeat(bottomBorderRightWidth)}
</text>
</box>
<box style={{ width: 1, height: 1, backgroundColor: theme.panel }}>
<text fg={savedBorderColor} bg={theme.panel}>
</text>
</box>
</box>
) : (
<box style={{ width: boxWidth, height: 1, backgroundColor: theme.panel }}>
<text fg={savedBorderColor} bg={theme.panel}>
{bottomBorder}
</text>
</box>
)}
</box>
</box>
);
Expand Down
Loading
Loading