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

Use DiffEditor DiffNavigator to navigate diffs #14889

Merged
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
49 changes: 44 additions & 5 deletions packages/scm/src/browser/scm-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ import { ScmCommand } from './scm-provider';
import { ScmDecorationsService } from '../browser/decorations/scm-decorations-service';
import { nls } from '@theia/core/lib/common/nls';
import { isHighContrast } from '@theia/core/lib/common/theme';
import { EditorMainMenu } from '@theia/editor/lib/browser';
import { EditorMainMenu, EditorWidget } from '@theia/editor/lib/browser';
import { DirtyDiffNavigator } from './dirty-diff/dirty-diff-navigator';
import { MonacoDiffEditor } from '@theia/monaco/lib/browser/monaco-diff-editor';

export const SCM_WIDGET_FACTORY_ID = ScmWidget.ID;
export const SCM_VIEW_CONTAINER_ID = 'scm-view-container';
Expand Down Expand Up @@ -95,12 +96,14 @@ export namespace SCM_COMMANDS {
export const GOTO_NEXT_CHANGE = Command.toDefaultLocalizedCommand({
id: 'workbench.action.editor.nextChange',
category: 'Source Control',
label: 'Go to Next Change'
label: 'Go to Next Change',
iconClass: codicon('arrow-down')
});
export const GOTO_PREVIOUS_CHANGE = Command.toDefaultLocalizedCommand({
id: 'workbench.action.editor.previousChange',
category: 'Source Control',
label: 'Go to Previous Change'
label: 'Go to Previous Change',
iconClass: codicon('arrow-up')
});
export const SHOW_NEXT_CHANGE = Command.toDefaultLocalizedCommand({
id: 'editor.action.dirtydiff.next',
Expand Down Expand Up @@ -198,10 +201,34 @@ export class ScmContribution extends AbstractViewContribution<ScmWidget> impleme
// This is consistent with behavior in VS Code, and also with other similar commands (such as `Next Problem/Previous Problem`) in Theia.
// See https://github.com/eclipse-theia/theia/pull/13104#discussion_r1497316614 for a detailed discussion.
commandRegistry.registerCommand(SCM_COMMANDS.GOTO_NEXT_CHANGE, {
execute: () => this.dirtyDiffNavigator.gotoNextChange()
execute: widget => {
if (widget instanceof EditorWidget && widget.editor instanceof MonacoDiffEditor) {
widget.editor.diffNavigator.next();
} else {
this.dirtyDiffNavigator.gotoNextChange();
}
},
isEnabled: widget => {
if (widget instanceof EditorWidget && widget.editor instanceof MonacoDiffEditor) {
return widget.editor.diffNavigator.hasNext();
}
return true;
}
});
commandRegistry.registerCommand(SCM_COMMANDS.GOTO_PREVIOUS_CHANGE, {
execute: () => this.dirtyDiffNavigator.gotoPreviousChange()
execute: widget => {
if (widget instanceof EditorWidget && widget.editor instanceof MonacoDiffEditor) {
widget.editor.diffNavigator.previous();
} else {
this.dirtyDiffNavigator.gotoPreviousChange();
}
},
isEnabled: widget => {
if (widget instanceof EditorWidget && widget.editor instanceof MonacoDiffEditor) {
return widget.editor.diffNavigator.hasPrevious();
}
return true;
}
});
commandRegistry.registerCommand(SCM_COMMANDS.SHOW_NEXT_CHANGE, {
execute: () => this.dirtyDiffNavigator.showNextChange()
Expand Down Expand Up @@ -272,6 +299,18 @@ export class ScmContribution extends AbstractViewContribution<ScmWidget> impleme
}
});

registry.registerItem({
id: SCM_COMMANDS.GOTO_PREVIOUS_CHANGE.id,
command: SCM_COMMANDS.GOTO_PREVIOUS_CHANGE.id,
isVisible: widget => widget instanceof EditorWidget && widget.editor instanceof MonacoDiffEditor,
});

registry.registerItem({
id: SCM_COMMANDS.GOTO_NEXT_CHANGE.id,
command: SCM_COMMANDS.GOTO_NEXT_CHANGE.id,
isVisible: widget => widget instanceof EditorWidget && widget.editor instanceof MonacoDiffEditor,
});

registry.registerItem({
...SCM_COMMANDS.COLLAPSE_ALL,
command: SCM_COMMANDS.COLLAPSE_ALL.id
Expand Down
Loading