diff --git a/src/view/treeNodes/directoryTreeNode.ts b/src/view/treeNodes/directoryTreeNode.ts index 97098a15ca..b24e8e9b75 100644 --- a/src/view/treeNodes/directoryTreeNode.ts +++ b/src/view/treeNodes/directoryTreeNode.ts @@ -124,7 +124,7 @@ export class DirectoryTreeNode extends TreeNode implements vscode.TreeItem { if (!child.allChildrenViewed()) { return false; } - } else if (child.checkboxState.state !== vscode.TreeItemCheckboxState.Checked) { + } else if (!child.checkboxState || child.checkboxState.state !== vscode.TreeItemCheckboxState.Checked) { return false; } } diff --git a/src/view/treeNodes/fileChangeNode.ts b/src/view/treeNodes/fileChangeNode.ts index 350471690b..0b457fdb12 100644 --- a/src/view/treeNodes/fileChangeNode.ts +++ b/src/view/treeNodes/fileChangeNode.ts @@ -75,7 +75,7 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem { public command: vscode.Command; public opts: vscode.TextDocumentShowOptions; - public checkboxState: { state: vscode.TreeItemCheckboxState; tooltip?: string; accessibilityInformation: vscode.AccessibilityInformation }; + public checkboxState?: { state: vscode.TreeItemCheckboxState; tooltip?: string; accessibilityInformation: vscode.AccessibilityInformation }; get status(): GitChangeType { return this.changeModel.status; @@ -155,13 +155,28 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem { } } + /** + * Check if this file node is under a commit node in the tree hierarchy. + * Files under commit nodes should not have checkboxes. + */ + private isUnderCommitNode(): boolean { + // If the file's sha is different from the PR's head sha, it's from an older commit + // and should not have a checkbox + return this.changeModel.sha !== undefined && this.changeModel.sha !== this.pullRequest.head?.sha; + } + updateViewed(viewed: ViewedState) { this.changeModel.updateViewed(viewed); this.contextValue = `${Schemes.FileChange}:${GitChangeType[this.changeModel.status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed' }`; - this.checkboxState = viewed === ViewedState.VIEWED ? - { state: vscode.TreeItemCheckboxState.Checked, tooltip: vscode.l10n.t('Mark File as Unviewed'), accessibilityInformation: { label: vscode.l10n.t('Mark file {0} as unviewed', this.label ?? '') } } : - { state: vscode.TreeItemCheckboxState.Unchecked, tooltip: vscode.l10n.t('Mark File as Viewed'), accessibilityInformation: { label: vscode.l10n.t('Mark file {0} as viewed', this.label ?? '') } }; + // Don't show checkboxes for files under commit nodes + if (!this.isUnderCommitNode()) { + this.checkboxState = viewed === ViewedState.VIEWED ? + { state: vscode.TreeItemCheckboxState.Checked, tooltip: vscode.l10n.t('Mark File as Unviewed'), accessibilityInformation: { label: vscode.l10n.t('Mark file {0} as unviewed', this.label ?? '') } } : + { state: vscode.TreeItemCheckboxState.Unchecked, tooltip: vscode.l10n.t('Mark File as Viewed'), accessibilityInformation: { label: vscode.l10n.t('Mark file {0} as viewed', this.label ?? '') } }; + } else { + this.checkboxState = undefined; + } this.pullRequestManager.setFileViewedContext(); } diff --git a/src/view/treeNodes/treeUtils.ts b/src/view/treeNodes/treeUtils.ts index 3bde5a5863..94920c8718 100644 --- a/src/view/treeNodes/treeUtils.ts +++ b/src/view/treeNodes/treeUtils.ts @@ -35,9 +35,10 @@ export namespace TreeUtils { continue; } if (!checkedNodes.includes(selected) && !uncheckedNodes.includes(selected)) { - if (selected.checkboxState.state === vscode.TreeItemCheckboxState.Unchecked) { + // Only process files that have checkboxes (files without checkboxState, like those under commits, are skipped) + if (selected.checkboxState?.state === vscode.TreeItemCheckboxState.Unchecked) { checkedNodes.push(selected); - } else { + } else if (selected.checkboxState?.state === vscode.TreeItemCheckboxState.Checked) { uncheckedNodes.push(selected); } }