Skip to content

Commit 76b9db0

Browse files
Copilotalexr00
andcommitted
Hide mark as viewed checkboxes on files under commit nodes
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 6d6baff commit 76b9db0

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/view/treeNodes/fileChangeNode.ts

Lines changed: 25 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,34 @@ 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+
let current = this.parent;
164+
while (current instanceof TreeNode) {
165+
// CommitNode has contextValue set to 'commit'
166+
if ((current as vscode.TreeItem).contextValue === 'commit') {
167+
return true;
168+
}
169+
current = current.parent;
170+
}
171+
return false;
172+
}
173+
158174
updateViewed(viewed: ViewedState) {
159175
this.changeModel.updateViewed(viewed);
160176
this.contextValue = `${Schemes.FileChange}:${GitChangeType[this.changeModel.status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed'
161177
}`;
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 ?? '') } };
178+
// Don't show checkboxes for files under commit nodes
179+
if (!this.isUnderCommitNode()) {
180+
this.checkboxState = viewed === ViewedState.VIEWED ?
181+
{ state: vscode.TreeItemCheckboxState.Checked, tooltip: vscode.l10n.t('Mark File as Unviewed'), accessibilityInformation: { label: vscode.l10n.t('Mark file {0} as unviewed', this.label ?? '') } } :
182+
{ state: vscode.TreeItemCheckboxState.Unchecked, tooltip: vscode.l10n.t('Mark File as Viewed'), accessibilityInformation: { label: vscode.l10n.t('Mark file {0} as viewed', this.label ?? '') } };
183+
} else {
184+
this.checkboxState = undefined;
185+
}
165186
this.pullRequestManager.setFileViewedContext();
166187
}
167188

0 commit comments

Comments
 (0)