Skip to content

Commit 6e812ce

Browse files
committed
Developed for support enable loop diff result from the beginning or end of document microsoft#163331
1 parent c616f13 commit 6e812ce

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/vs/editor/browser/widget/diffNavigator.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ export interface Options {
2323
followsCaret?: boolean;
2424
ignoreCharChanges?: boolean;
2525
alwaysRevealFirst?: boolean;
26+
findResultLoop?: boolean;
2627
}
2728

2829
const defaultOptions: Options = {
2930
followsCaret: true,
3031
ignoreCharChanges: true,
31-
alwaysRevealFirst: true
32+
alwaysRevealFirst: true,
33+
findResultLoop: true
3234
};
3335

3436
export interface IDiffNavigator {
@@ -216,13 +218,31 @@ export class DiffNavigator extends Disposable implements IDiffNavigator {
216218
}
217219

218220
next(scrollType: ScrollType = ScrollType.Smooth): void {
221+
if (!this.canNavigateNext()) {
222+
return;
223+
}
219224
this._move(true, scrollType);
220225
}
221226

222227
previous(scrollType: ScrollType = ScrollType.Smooth): void {
228+
if (!this.canNavigatePrevious()) {
229+
return;
230+
}
223231
this._move(false, scrollType);
224232
}
225233

234+
canNavigateNext(): boolean {
235+
return this.canNavigateLoop() || this.nextIdx < this.ranges.length - 1;
236+
}
237+
238+
canNavigatePrevious(): boolean {
239+
return this.canNavigateLoop() || this.nextIdx !== 0;
240+
}
241+
242+
canNavigateLoop(): boolean {
243+
return Boolean(this._options.findResultLoop);
244+
}
245+
226246
override dispose(): void {
227247
super.dispose();
228248
this.ranges = [];

src/vs/workbench/browser/parts/editor/textDiffEditor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { localize } from 'vs/nls';
77
import { deepClone } from 'vs/base/common/objects';
88
import { isObject, assertIsDefined, withUndefinedAsNull, withNullAsUndefined } from 'vs/base/common/types';
99
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
10-
import { IDiffEditorOptions, IEditorOptions as ICodeEditorOptions } from 'vs/editor/common/config/editorOptions';
10+
import { IDiffEditorOptions, EditorOption, IEditorOptions as ICodeEditorOptions } from 'vs/editor/common/config/editorOptions';
1111
import { AbstractTextEditor, IEditorConfiguration } from 'vs/workbench/browser/parts/editor/textEditor';
1212
import { TEXT_DIFF_EDITOR_ID, IEditorFactoryRegistry, EditorExtensions, ITextDiffEditorPane, IEditorOpenContext, EditorInputCapabilities, isEditorInput, isTextEditorViewState } from 'vs/workbench/common/editor';
1313
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
@@ -132,7 +132,8 @@ export class TextDiffEditor extends AbstractTextEditor<IDiffEditorViewState> imp
132132

133133
// Diff navigator
134134
this.diffNavigator = new DiffNavigator(control, {
135-
alwaysRevealFirst: !optionsGotApplied && !hasPreviousViewState // only reveal first change if we had no options or viewstate
135+
alwaysRevealFirst: !optionsGotApplied && !hasPreviousViewState, // only reveal first change if we had no options or viewstate
136+
findResultLoop: this.getMainControl()?.getOption(EditorOption.find).loop
136137
});
137138
this.diffNavigatorDisposables.add(this.diffNavigator);
138139

0 commit comments

Comments
 (0)