Skip to content
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
22 changes: 21 additions & 1 deletion src/vs/editor/browser/widget/diffNavigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export interface Options {
followsCaret?: boolean;
ignoreCharChanges?: boolean;
alwaysRevealFirst?: boolean;
findResultLoop?: boolean;
}

const defaultOptions: Options = {
followsCaret: true,
ignoreCharChanges: true,
alwaysRevealFirst: true
alwaysRevealFirst: true,
findResultLoop: true
};

export interface IDiffNavigator {
Expand Down Expand Up @@ -216,13 +218,31 @@ export class DiffNavigator extends Disposable implements IDiffNavigator {
}

next(scrollType: ScrollType = ScrollType.Smooth): void {
if (!this.canNavigateNext()) {
return;
}
this._move(true, scrollType);
}

previous(scrollType: ScrollType = ScrollType.Smooth): void {
if (!this.canNavigatePrevious()) {
return;
}
this._move(false, scrollType);
}

canNavigateNext(): boolean {
return this.canNavigateLoop() || this.nextIdx < this.ranges.length - 1;
}

canNavigatePrevious(): boolean {
return this.canNavigateLoop() || this.nextIdx !== 0;
}

canNavigateLoop(): boolean {
return Boolean(this._options.findResultLoop);
}

override dispose(): void {
super.dispose();
this.ranges = [];
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ export interface IEditorFindOptions {
*/
globalFindClipboard?: boolean;
/**
* Controls whether the search automatically restarts from the beginning (or the end) when no further matches can be found
* Controls whether the search result and diff result automatically restarts from the beginning (or the end) when no further matches can be found
*/
loop?: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3703,7 +3703,7 @@ declare namespace monaco.editor {
autoFindInSelection?: 'never' | 'always' | 'multiline';
addExtraSpaceOnTop?: boolean;
/**
* Controls whether the search automatically restarts from the beginning (or the end) when no further matches can be found
* Controls whether the search result and diff result automatically restarts from the beginning (or the end) when no further matches can be found
*/
loop?: boolean;
}
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/browser/parts/editor/textDiffEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { localize } from 'vs/nls';
import { deepClone } from 'vs/base/common/objects';
import { isObject, assertIsDefined, withUndefinedAsNull, withNullAsUndefined } from 'vs/base/common/types';
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { IDiffEditorOptions, IEditorOptions as ICodeEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IDiffEditorOptions, EditorOption, IEditorOptions as ICodeEditorOptions } from 'vs/editor/common/config/editorOptions';
import { AbstractTextEditor, IEditorConfiguration } from 'vs/workbench/browser/parts/editor/textEditor';
import { TEXT_DIFF_EDITOR_ID, IEditorFactoryRegistry, EditorExtensions, ITextDiffEditorPane, IEditorOpenContext, EditorInputCapabilities, isEditorInput, isTextEditorViewState } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
Expand Down Expand Up @@ -132,7 +132,8 @@ export class TextDiffEditor extends AbstractTextEditor<IDiffEditorViewState> imp

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

Expand Down