Skip to content

Commit

Permalink
Fixes #2814 moves selection firing to base
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Oct 18, 2023
1 parent d769f2b commit a04ab4d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed

- Fixes [#2952](https://github.com/gitkraken/vscode-gitlens/issues/2952) - Inline blame not working because of missing ignoreRevsFile
- Fixes [#2814](https://github.com/gitkraken/vscode-gitlens/issues/2814) - GitLens Inspect: "Files Changed" not following when switching between commits in File History

## [14.4.0] - 2023-10-13

Expand Down
53 changes: 1 addition & 52 deletions src/views/commitsView.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import type {
CancellationToken,
ConfigurationChangeEvent,
TreeViewSelectionChangeEvent,
TreeViewVisibilityChangeEvent,
} from 'vscode';
import type { CancellationToken, ConfigurationChangeEvent } from 'vscode';
import { Disposable, ProgressLocation, ThemeIcon, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import type { CommitsViewConfig, ViewFilesLayout } from '../config';
import { Commands, GlyphChars } from '../constants';
Expand All @@ -24,10 +19,7 @@ import { disposableInterval } from '../system/function';
import type { UsageChangeEvent } from '../telemetry/usageTracker';
import { BranchNode } from './nodes/branchNode';
import { BranchTrackingStatusNode } from './nodes/branchTrackingStatusNode';
import { CommitFileNode } from './nodes/commitFileNode';
import { CommitNode } from './nodes/commitNode';
import { CommandMessageNode } from './nodes/common';
import { FileRevisionAsCommitNode } from './nodes/fileRevisionAsCommitNode';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
Expand Down Expand Up @@ -305,49 +297,6 @@ export class CommitsView extends ViewBase<'commits', CommitsViewNode, CommitsVie
return true;
}

protected override onSelectionChanged(e: TreeViewSelectionChangeEvent<ViewNode>) {
super.onSelectionChanged(e);
this.notifySelections();
}

protected override onVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
super.onVisibilityChanged(e);

if (e.visible) {
this.notifySelections();
}
}

private notifySelections() {
const node = this.selection?.[0];
if (node == null) return;

if (node instanceof CommitNode || node instanceof FileRevisionAsCommitNode || node instanceof CommitFileNode) {
this.container.events.fire(
'commit:selected',
{
commit: node.commit,
interaction: 'passive',
preserveFocus: true,
preserveVisibility: true,
},
{ source: this.id },
);
}

if (node instanceof FileRevisionAsCommitNode || node instanceof CommitFileNode) {
this.container.events.fire(
'file:selected',
{
uri: node.uri,
preserveFocus: true,
preserveVisibility: true,
},
{ source: this.id },
);
}
}

async findCommit(commit: GitCommit | { repoPath: string; ref: string }, token?: CancellationToken) {
const { repoPath } = commit;

Expand Down
52 changes: 1 addition & 51 deletions src/views/stashesView.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import type {
CancellationToken,
ConfigurationChangeEvent,
Disposable,
TreeViewSelectionChangeEvent,
TreeViewVisibilityChangeEvent,
} from 'vscode';
import type { CancellationToken, ConfigurationChangeEvent, Disposable } from 'vscode';
import { ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import type { StashesViewConfig, ViewFilesLayout } from '../config';
import { Commands } from '../constants';
Expand All @@ -18,8 +12,6 @@ import { executeCommand } from '../system/command';
import { configuration } from '../system/configuration';
import { gate } from '../system/decorators/gate';
import { StashesNode } from './nodes/stashesNode';
import { StashFileNode } from './nodes/stashFileNode';
import { StashNode } from './nodes/stashNode';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
Expand Down Expand Up @@ -155,48 +147,6 @@ export class StashesView extends ViewBase<'stashes', StashesViewNode, StashesVie
return true;
}

protected override onSelectionChanged(e: TreeViewSelectionChangeEvent<ViewNode>) {
super.onSelectionChanged(e);
this.notifySelections();
}

protected override onVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
super.onVisibilityChanged(e);
if (e.visible) {
this.notifySelections();
}
}

private notifySelections() {
const node = this.selection?.[0];
if (node == null) return;

if (node instanceof StashNode || node instanceof StashFileNode) {
this.container.events.fire(
'commit:selected',
{
commit: node.commit,
interaction: 'passive',
preserveFocus: true,
preserveVisibility: true,
},
{ source: this.id },
);
}

if (node instanceof StashFileNode) {
this.container.events.fire(
'file:selected',
{
uri: node.uri,
preserveFocus: true,
preserveVisibility: true,
},
{ source: this.id },
);
}
}

findStash(stash: GitStashReference, token?: CancellationToken) {
const { repoPath } = stash;

Expand Down
40 changes: 40 additions & 0 deletions src/views/viewBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ export abstract class ViewBase<

protected onSelectionChanged(e: TreeViewSelectionChangeEvent<ViewNode>) {
this._onDidChangeSelection.fire(e);
this.notifySelections();
}

protected onVisibilityChanged(e: TreeViewVisibilityChangeEvent) {
Expand All @@ -414,6 +415,45 @@ export abstract class ViewBase<
}

this._onDidChangeVisibility.fire(e);
if (e.visible) {
this.notifySelections();
}
}

private notifySelections() {
const node = this.selection?.[0];
if (node == null) return;

if (
node.is('commit') ||
node.is('stash') ||
node.is('file-commit') ||
node.is('commit-file') ||
node.is('stash-file')
) {
this.container.events.fire(
'commit:selected',
{
commit: node.commit,
interaction: 'passive',
preserveFocus: true,
preserveVisibility: true,
},
{ source: this.id },
);
}

if (node.is('file-commit') || node.is('commit-file') || node.is('stash-file')) {
this.container.events.fire(
'file:selected',
{
uri: node.uri,
preserveFocus: true,
preserveVisibility: true,
},
{ source: this.id },
);
}
}

get activeSelection(): ViewNode | undefined {
Expand Down

0 comments on commit a04ab4d

Please sign in to comment.