Skip to content

Commit ebb1209

Browse files
Copilotalexr00
andauthored
Hide "Mark as Viewed" checkboxes on files under commit nodes (#8418)
* Initial plan * Hide mark as viewed checkboxes on files under commit nodes Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Fix compilation errors from optional checkboxState Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Address code review feedback - safer type checking Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Use sha comparison instead of parent tree traversal Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Revert proposed changes --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 28b8b10 commit ebb1209

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

src/view/treeNodes/directoryTreeNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class DirectoryTreeNode extends TreeNode implements vscode.TreeItem {
124124
if (!child.allChildrenViewed()) {
125125
return false;
126126
}
127-
} else if (child.checkboxState.state !== vscode.TreeItemCheckboxState.Checked) {
127+
} else if (!child.checkboxState || child.checkboxState.state !== vscode.TreeItemCheckboxState.Checked) {
128128
return false;
129129
}
130130
}

src/view/treeNodes/fileChangeNode.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
7575
public command: vscode.Command;
7676
public opts: vscode.TextDocumentShowOptions;
7777

78-
public checkboxState: { state: vscode.TreeItemCheckboxState; tooltip?: string; accessibilityInformation: vscode.AccessibilityInformation };
78+
public checkboxState?: { state: vscode.TreeItemCheckboxState; tooltip?: string; accessibilityInformation: vscode.AccessibilityInformation };
7979

8080
get status(): GitChangeType {
8181
return this.changeModel.status;
@@ -155,13 +155,28 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
155155
}
156156
}
157157

158+
/**
159+
* Check if this file node is under a commit node in the tree hierarchy.
160+
* Files under commit nodes should not have checkboxes.
161+
*/
162+
private isUnderCommitNode(): boolean {
163+
// If the file's sha is different from the PR's head sha, it's from an older commit
164+
// and should not have a checkbox
165+
return this.changeModel.sha !== undefined && this.changeModel.sha !== this.pullRequest.head?.sha;
166+
}
167+
158168
updateViewed(viewed: ViewedState) {
159169
this.changeModel.updateViewed(viewed);
160170
this.contextValue = `${Schemes.FileChange}:${GitChangeType[this.changeModel.status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed'
161171
}`;
162-
this.checkboxState = viewed === ViewedState.VIEWED ?
163-
{ state: vscode.TreeItemCheckboxState.Checked, tooltip: vscode.l10n.t('Mark File as Unviewed'), accessibilityInformation: { label: vscode.l10n.t('Mark file {0} as unviewed', this.label ?? '') } } :
164-
{ state: vscode.TreeItemCheckboxState.Unchecked, tooltip: vscode.l10n.t('Mark File as Viewed'), accessibilityInformation: { label: vscode.l10n.t('Mark file {0} as viewed', this.label ?? '') } };
172+
// Don't show checkboxes for files under commit nodes
173+
if (!this.isUnderCommitNode()) {
174+
this.checkboxState = viewed === ViewedState.VIEWED ?
175+
{ state: vscode.TreeItemCheckboxState.Checked, tooltip: vscode.l10n.t('Mark File as Unviewed'), accessibilityInformation: { label: vscode.l10n.t('Mark file {0} as unviewed', this.label ?? '') } } :
176+
{ state: vscode.TreeItemCheckboxState.Unchecked, tooltip: vscode.l10n.t('Mark File as Viewed'), accessibilityInformation: { label: vscode.l10n.t('Mark file {0} as viewed', this.label ?? '') } };
177+
} else {
178+
this.checkboxState = undefined;
179+
}
165180
this.pullRequestManager.setFileViewedContext();
166181
}
167182

src/view/treeNodes/treeUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ export namespace TreeUtils {
3535
continue;
3636
}
3737
if (!checkedNodes.includes(selected) && !uncheckedNodes.includes(selected)) {
38-
if (selected.checkboxState.state === vscode.TreeItemCheckboxState.Unchecked) {
38+
// Only process files that have checkboxes (files without checkboxState, like those under commits, are skipped)
39+
if (selected.checkboxState?.state === vscode.TreeItemCheckboxState.Unchecked) {
3940
checkedNodes.push(selected);
40-
} else {
41+
} else if (selected.checkboxState?.state === vscode.TreeItemCheckboxState.Checked) {
4142
uncheckedNodes.push(selected);
4243
}
4344
}

0 commit comments

Comments
 (0)