Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scm: select node based on active editor #11560

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/scm/src/browser/scm-tree-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,18 @@ export class ScmTreeWidget extends TreeWidget {
}
}

selectNodeByUri(uri: URI): void {
for (const group of this.model.groups) {
const sourceUri = new URI(uri.path.toString());
const id = `${group.id}:${sourceUri.toString()}`;
const node = this.model.getNode(id);
if (SelectableTreeNode.is(node)) {
this.model.selectNode(node);
return;
}
}
}

protected getFirstSelectableNode(): SelectableTreeNode | undefined {
if (this.model.root) {
const root = this.model.root as ScmFileChangeRootNode;
Expand Down
9 changes: 8 additions & 1 deletion packages/scm/src/browser/scm-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Message } from '@theia/core/shared/@phosphor/messaging';
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
import { DisposableCollection } from '@theia/core/lib/common/disposable';
import {
BaseWidget, Widget, StatefulWidget, Panel, PanelLayout, MessageLoop, CompositeTreeNode, SelectableTreeNode,
BaseWidget, Widget, StatefulWidget, Panel, PanelLayout, MessageLoop, CompositeTreeNode, SelectableTreeNode, ApplicationShell, NavigatableWidget,
} from '@theia/core/lib/browser';
import { ScmCommitWidget } from './scm-commit-widget';
import { ScmAmendWidget } from './scm-amend-widget';
Expand All @@ -37,6 +37,7 @@ export class ScmWidget extends BaseWidget implements StatefulWidget {

static ID = 'scm-view';

@inject(ApplicationShell) protected readonly shell: ApplicationShell;
@inject(ScmService) protected readonly scmService: ScmService;
@inject(ScmCommitWidget) protected readonly commitWidget: ScmCommitWidget;
@inject(ScmTreeWidget) readonly resourceWidget: ScmTreeWidget;
Expand Down Expand Up @@ -84,6 +85,12 @@ export class ScmWidget extends BaseWidget implements StatefulWidget {
this.updateViewMode(e.newValue);
}
}));
this.toDispose.push(this.shell.onDidChangeCurrentWidget(({ newValue }) => {
const uri = NavigatableWidget.getUri(newValue || undefined);
if (uri) {
this.resourceWidget.selectNodeByUri(uri);
}
}));

}

Expand Down