This commit is contained in:
İsmail Arılık 2021-11-26 13:53:36 -08:00 committed by GitHub
commit 5a97aafea5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 89 additions and 8 deletions

View file

@ -20,6 +20,7 @@ import { IEditorWhitespace } from 'vs/editor/common/viewLayout/linesLayout';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IDiffComputationResult } from 'vs/editor/common/services/editorWorkerService';
import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
/**
* A view zone is a full horizontal rectangle that 'pushes' text down.
@ -988,6 +989,15 @@ export interface IDiffEditor extends editorCommon.IEditor {
* @internal
*/
readonly maxComputationTime: number;
/**
* Controls whether the changes movement automatically restarts from the beginning (or the end) when no further changes can be found.
* @internal
*/
readonly changesLoop: boolean;
/**
* @internal
*/
readonly contextKeyService: IContextKeyService;
/**
* @see {@link ICodeEditor.getDomNode}

View file

@ -267,7 +267,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
originalEditable: false,
diffCodeLens: false,
renderOverviewRuler: true,
diffWordWrap: 'inherit'
diffWordWrap: 'inherit',
changesLoop: true
});
if (typeof options.isInEmbeddedEditor !== 'undefined') {
@ -376,6 +377,14 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
return this._options.maxComputationTime;
}
public get changesLoop(): boolean {
return this._options.changesLoop;
}
public get contextKeyService(): IContextKeyService {
return this._contextKeyService;
}
public getContentHeight(): number {
return this._modifiedEditor.getContentHeight();
}
@ -2502,6 +2511,7 @@ function validateDiffEditorOptions(options: Readonly<IDiffEditorOptions>, defaul
diffCodeLens: validateBooleanOption(options.diffCodeLens, defaults.diffCodeLens),
renderOverviewRuler: validateBooleanOption(options.renderOverviewRuler, defaults.renderOverviewRuler),
diffWordWrap: validateDiffWordWrap(options.diffWordWrap, defaults.diffWordWrap),
changesLoop: validateBooleanOption(options.changesLoop, defaults.changesLoop),
};
}
@ -2517,6 +2527,7 @@ function changedDiffEditorOptions(a: ValidDiffEditorBaseOptions, b: ValidDiffEdi
diffCodeLens: (a.diffCodeLens !== b.diffCodeLens),
renderOverviewRuler: (a.renderOverviewRuler !== b.renderOverviewRuler),
diffWordWrap: (a.diffWordWrap !== b.diffWordWrap),
changesLoop: (a.changesLoop !== b.changesLoop),
};
}

View file

@ -11,6 +11,7 @@ import { IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { Range } from 'vs/editor/common/core/range';
import { ILineChange, ScrollType } from 'vs/editor/common/editorCommon';
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
interface IDiffRange {
@ -45,6 +46,8 @@ export class DiffNavigator extends Disposable implements IDiffNavigator {
private readonly _editor: IDiffEditor;
private readonly _options: Options;
private readonly _onDidUpdate = this._register(new Emitter<this>());
private readonly _canNavigateBackKey: IContextKey<boolean>;
private readonly _canNavigateForwardKey: IContextKey<boolean>;
readonly onDidUpdate: Event<this> = this._onDidUpdate.event;
@ -59,6 +62,9 @@ export class DiffNavigator extends Disposable implements IDiffNavigator {
this._editor = editor;
this._options = objects.mixin(options, defaultOptions, false);
this._canNavigateBackKey = this._editor.contextKeyService.createKey('canNavigateDiffBack', true);
this._canNavigateForwardKey = this._editor.contextKeyService.createKey('canNavigateDiffForward', true);
this.disposed = false;
this.nextIdx = -1;
@ -208,6 +214,21 @@ export class DiffNavigator extends Disposable implements IDiffNavigator {
} finally {
this.ignoreSelectionChange = false;
}
this._canNavigateBackKey.set(this._canNavigateBack());
this._canNavigateForwardKey.set(this._canNavigateForward());
}
private _canNavigateInLoop(): boolean {
return this.canNavigate() && this._editor.changesLoop;
}
private _canNavigateBack(): boolean {
return this._canNavigateInLoop() || (this.nextIdx !== 0);
}
private _canNavigateForward(): boolean {
return this._canNavigateInLoop() || (this.nextIdx !== this.ranges.length - 1);
}
canNavigate(): boolean {
@ -215,11 +236,15 @@ export class DiffNavigator extends Disposable implements IDiffNavigator {
}
next(scrollType: ScrollType = ScrollType.Smooth): void {
this._move(true, scrollType);
if (this._canNavigateForward()) {
this._move(true, scrollType);
}
}
previous(scrollType: ScrollType = ScrollType.Smooth): void {
this._move(false, scrollType);
if (this._canNavigateBack()) {
this._move(false, scrollType);
}
}
override dispose(): void {

View file

@ -627,7 +627,12 @@ const editorConfiguration: IConfigurationNode = {
nls.localize('wordWrap.on', "Lines will wrap at the viewport width."),
nls.localize('wordWrap.inherit', "Lines will wrap according to the `#editor.wordWrap#` setting."),
]
}
},
'diffEditor.changesLoop': {
type: 'boolean',
default: true,
description: nls.localize('changesLoop', "Controls whether the changes movement automatically restarts from the beginning (or the end) when no further changes can be found.")
},
}
};

View file

@ -700,6 +700,10 @@ export interface IDiffEditorBaseOptions {
* Control the wrapping of the diff editor.
*/
diffWordWrap?: 'off' | 'on' | 'inherit';
/**
* Controls whether the changes movement automatically restarts from the beginning (or the end) when no further changes can be found.
*/
changesLoop?: boolean;
}
/**

4
src/vs/monaco.d.ts vendored
View file

@ -3352,6 +3352,10 @@ declare namespace monaco.editor {
* Control the wrapping of the diff editor.
*/
diffWordWrap?: 'off' | 'on' | 'inherit';
/**
* Controls whether the changes movement automatically restarts from the beginning (or the end) when no further changes can be found.
*/
changesLoop?: boolean;
}
/**

View file

@ -489,25 +489,47 @@ const previousChangeIcon = registerIcon('diff-editor-previous-change', Codicon.a
const nextChangeIcon = registerIcon('diff-editor-next-change', Codicon.arrowDown, localize('nextChangeIcon', 'Icon for the next change action in the diff editor.'));
const toggleWhitespace = registerIcon('diff-editor-toggle-whitespace', Codicon.whitespace, localize('toggleWhitespace', 'Icon for the toggle whitespace action in the diff editor.'));
// Diff Editor Title Menu: Previous Change
// Diff Editor Title Menu: Previous Change (Enabled)
appendEditorToolItem(
{
id: GOTO_PREVIOUS_CHANGE,
title: localize('navigate.prev.label', "Previous Change"),
icon: previousChangeIcon
},
TextCompareEditorActiveContext,
ContextKeyExpr.and(TextCompareEditorActiveContext, ContextKeyExpr.equals('canNavigateDiffBack', true)),
10
);
// Diff Editor Title Menu: Next Change
// Diff Editor Title Menu: Previous Change (Disabled)
appendEditorToolItem(
{
id: GOTO_PREVIOUS_CHANGE,
title: localize('navigate.prev.label', "Previous Change"),
icon: ThemeIcon.modify(previousChangeIcon, 'disabled')
},
ContextKeyExpr.and(TextCompareEditorActiveContext, ContextKeyExpr.equals('canNavigateDiffBack', false)),
10
);
// Diff Editor Title Menu: Next Change (Enabled)
appendEditorToolItem(
{
id: GOTO_NEXT_CHANGE,
title: localize('navigate.next.label', "Next Change"),
icon: nextChangeIcon
},
TextCompareEditorActiveContext,
ContextKeyExpr.and(TextCompareEditorActiveContext, ContextKeyExpr.equals('canNavigateDiffForward', true)),
11
);
// Diff Editor Title Menu: Next Change (Disabled)
appendEditorToolItem(
{
id: GOTO_NEXT_CHANGE,
title: localize('navigate.next.label', "Next Change"),
icon: ThemeIcon.modify(nextChangeIcon, 'disabled')
},
ContextKeyExpr.and(TextCompareEditorActiveContext, ContextKeyExpr.equals('canNavigateDiffForward', false)),
11
);