Skip to content

Commit 121ed42

Browse files
Copilotalexr00
andcommitted
Address code review feedback - add constant for sessionStorage key and improve comments
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 2f86ae1 commit 121ed42

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/@types/vscode.proposed.chatParticipantAdditions.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ declare module 'vscode' {
105105
isComplete?: boolean;
106106
toolSpecificData?: ChatTerminalToolInvocationData;
107107
fromSubAgent?: boolean;
108-
presentation?: 'hidden' | 'hiddenAfterComplete' | undefined;
109108

110109
constructor(toolName: string, toolCallId: string, isError?: boolean);
111110
}

webviews/common/context.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { EventType, ReviewEvent, SessionLinkInfo, TimelineEvent } from '../../sr
1212
import { IProjectItem, MergeMethod, ReadyForReview } from '../../src/github/interface';
1313
import { CancelCodingAgentReply, ChangeAssigneesReply, DeleteReviewResult, MergeArguments, MergeResult, ProjectItemsReply, PullRequest, ReadyForReviewReply, SubmitReviewReply } from '../../src/github/views';
1414

15+
// Key for tracking comment textarea focus state in sessionStorage
16+
// Also used in webviews/editorWebview/app.tsx
17+
const COMMENT_TEXTAREA_FOCUS_KEY = 'comment-textarea-had-focus';
18+
1519
export class PRContext {
1620
constructor(
1721
public pr: PullRequest | undefined = getState(),
@@ -415,7 +419,7 @@ export class PRContext {
415419
const commentTextarea = document.getElementById('comment-textarea');
416420
if (commentTextarea instanceof HTMLTextAreaElement) {
417421
// Check if there's a stored focus state
418-
const shouldRestoreFocus = sessionStorage.getItem('comment-textarea-had-focus') === 'true';
422+
const shouldRestoreFocus = sessionStorage.getItem(COMMENT_TEXTAREA_FOCUS_KEY) === 'true';
419423
if (shouldRestoreFocus) {
420424
commentTextarea.focus();
421425
}

webviews/editorWebview/app.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { Overview } from './overview';
1010
import { PullRequest } from '../../src/github/views';
1111
import PullRequestContext from '../common/context';
1212

13+
// Key for tracking comment textarea focus state in sessionStorage
14+
// Also used in webviews/common/context.tsx
15+
const COMMENT_TEXTAREA_FOCUS_KEY = 'comment-textarea-had-focus';
16+
1317
export function main() {
1418
render(<Root>{pr => <Overview {...pr} />}</Root>, document.getElementById('app'));
1519
}
@@ -26,16 +30,16 @@ export function Root({ children }) {
2630
useEffect(() => {
2731
const handleFocusIn = (e: FocusEvent) => {
2832
if (e.target instanceof HTMLTextAreaElement && e.target.id === 'comment-textarea') {
29-
sessionStorage.setItem('comment-textarea-had-focus', 'true');
33+
sessionStorage.setItem(COMMENT_TEXTAREA_FOCUS_KEY, 'true');
3034
}
3135
};
3236

3337
const handleFocusOut = (e: FocusEvent) => {
3438
if (e.target instanceof HTMLTextAreaElement && e.target.id === 'comment-textarea') {
35-
// Only clear the flag if we're switching to a non-textarea element
36-
// This prevents clearing when the webview loses focus
39+
// Only clear the flag if we're switching to another element within the webview
40+
// When switching to another editor group, relatedTarget will be null and we want to keep the flag
3741
if (e.relatedTarget instanceof HTMLElement) {
38-
sessionStorage.setItem('comment-textarea-had-focus', 'false');
42+
sessionStorage.setItem(COMMENT_TEXTAREA_FOCUS_KEY, 'false');
3943
}
4044
}
4145
};

0 commit comments

Comments
 (0)