Skip to content

Commit

Permalink
Support Textual Selections in notebook find widget (microsoft#216840)
Browse files Browse the repository at this point in the history
* support textual selections in notebook find widget

* add textual selection decorations

* union type

* fix passed ranges, clear find scope text range decs

* organize imports pass

* remove auto find explorations
  • Loading branch information
Yoyokrazy authored and bricefriha committed Jun 26, 2024
1 parent 7ca3c05 commit 415f9d1
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Emitter, Event } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { INotebookFindScope, NotebookFindScopeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';

export interface INotebookFindChangeEvent {
markupInput?: boolean;
markupPreview?: boolean;
codeInput?: boolean;
codeOutput?: boolean;
searchInRanges?: boolean;
findScope?: boolean;
}

export class NotebookFindFilters extends Disposable {
Expand Down Expand Up @@ -70,31 +70,19 @@ export class NotebookFindFilters extends Disposable {
}
}

private _searchInRanges: boolean = false;
private _findScope: INotebookFindScope = { findScopeType: NotebookFindScopeType.None };

get searchInRanges(): boolean {
return this._searchInRanges;
get findScope(): INotebookFindScope {
return this._findScope;
}

set searchInRanges(value: boolean) {
if (this._searchInRanges !== value) {
this._searchInRanges = value;
this._onDidChange.fire({ searchInRanges: value });
set findScope(value: INotebookFindScope) {
if (this._findScope !== value) {
this._findScope = value;
this._onDidChange.fire({ findScope: true });
}
}

private _selectedRanges: ICellRange[] = [];

get selectedRanges(): ICellRange[] {
return this._selectedRanges;
}

set selectedRanges(value: ICellRange[]) {
if (this._selectedRanges !== value) {
this._selectedRanges = value;
this._onDidChange.fire({ searchInRanges: this._searchInRanges });
}
}

private readonly _initialMarkupInput: boolean;
private readonly _initialMarkupPreview: boolean;
Expand All @@ -106,17 +94,15 @@ export class NotebookFindFilters extends Disposable {
markupPreview: boolean,
codeInput: boolean,
codeOutput: boolean,
searchInRanges: boolean,
selectedRanges: ICellRange[]
findScope: INotebookFindScope
) {
super();

this._markupInput = markupInput;
this._markupPreview = markupPreview;
this._codeInput = codeInput;
this._codeOutput = codeOutput;
this._searchInRanges = searchInRanges;
this._selectedRanges = selectedRanges;
this._findScope = findScope;

this._initialMarkupInput = markupInput;
this._initialMarkupPreview = markupPreview;
Expand All @@ -125,7 +111,7 @@ export class NotebookFindFilters extends Disposable {
}

isModified(): boolean {
// do not include searchInRanges or selectedRanges in the check. This will incorrectly mark the filter icon as modified
// do not include findInSelection or either selectedRanges in the check. This will incorrectly mark the filter icon as modified
return (
this._markupInput !== this._initialMarkupInput
|| this._markupPreview !== this._initialMarkupPreview
Expand All @@ -139,7 +125,6 @@ export class NotebookFindFilters extends Disposable {
this._markupPreview = v.markupPreview;
this._codeInput = v.codeInput;
this._codeOutput = v.codeOutput;
this._searchInRanges = v.searchInRanges;
this._selectedRanges = v.selectedRanges;
this._findScope = v.findScope;
}
}
24 changes: 11 additions & 13 deletions src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { findFirstIdxMonotonousOrArrLen } from 'vs/base/common/arraysFind';
import { CancelablePromise, createCancelablePromise, Delayer } from 'vs/base/common/async';
import { INotebookEditor, CellEditState, CellFindMatchWithIndex, CellWebviewFindMatch, ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Range } from 'vs/editor/common/core/range';
import { FindMatch } from 'vs/editor/common/model';
import { PrefixSumComputer } from 'vs/editor/common/model/prefixSumComputer';
import { FindReplaceState, FindReplaceStateChangedEvent } from 'vs/editor/contrib/find/browser/findState';
import { CellKind, INotebookSearchOptions, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { findFirstIdxMonotonousOrArrLen } from 'vs/base/common/arraysFind';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { CancellationToken } from 'vs/base/common/cancellation';
import { NotebookFindFilters } from 'vs/workbench/contrib/notebook/browser/contrib/find/findFilters';
import { FindMatchDecorationModel } from 'vs/workbench/contrib/notebook/browser/contrib/find/findMatchDecorationModel';
import { CellEditState, CellFindMatchWithIndex, CellWebviewFindMatch, ICellViewModel, INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { CellKind, INotebookFindOptions, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';

export class CellFindMatchModel implements CellFindMatchWithIndex {
readonly cell: ICellViewModel;
Expand Down Expand Up @@ -115,7 +115,7 @@ export class FindModel extends Disposable {
}

private _updateCellStates(e: FindReplaceStateChangedEvent) {
if (!this._state.filters?.markupInput || !this._state.filters?.markupPreview || !this._state.filters?.searchInRanges || !this._state.filters?.selectedRanges) {
if (!this._state.filters?.markupInput || !this._state.filters?.markupPreview || !this._state.filters?.findScope) {
return;
}

Expand All @@ -127,7 +127,7 @@ export class FindModel extends Disposable {
}
// search markup sources first to decide if a markup cell should be in editing mode
const wordSeparators = this._configurationService.inspect<string>('editor.wordSeparators').value;
const options: INotebookSearchOptions = {
const options: INotebookFindOptions = {
regex: this._state.isRegex,
wholeWord: this._state.wholeWord,
caseSensitive: this._state.matchCase,
Expand All @@ -136,8 +136,7 @@ export class FindModel extends Disposable {
includeCodeInput: false,
includeMarkupPreview: false,
includeOutput: false,
searchInRanges: this._state.filters?.searchInRanges,
selectedRanges: this._state.filters?.selectedRanges
findScope: this._state.filters?.findScope,
};

const contentMatches = viewModel.find(this._state.searchString, options);
Expand Down Expand Up @@ -476,7 +475,7 @@ export class FindModel extends Disposable {
const val = this._state.searchString;
const wordSeparators = this._configurationService.inspect<string>('editor.wordSeparators').value;

const options: INotebookSearchOptions = {
const options: INotebookFindOptions = {
regex: this._state.isRegex,
wholeWord: this._state.wholeWord,
caseSensitive: this._state.matchCase,
Expand All @@ -485,8 +484,7 @@ export class FindModel extends Disposable {
includeCodeInput: this._state.filters?.codeInput ?? true,
includeMarkupPreview: !!this._state.filters?.markupPreview,
includeOutput: !!this._state.filters?.codeOutput,
searchInRanges: this._state.filters?.searchInRanges,
selectedRanges: this._state.filters?.selectedRanges
findScope: this._state.filters?.findScope,
};

ret = await this._notebookEditor.find(val, options, token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@
padding: 0 2px;
box-sizing: border-box;
}

.monaco-workbench .nb-findScope {
background-color: var(--vscode-editor-findRangeHighlightBackground);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { isEqual } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { ITextModel } from 'vs/editor/common/model';
import { FindStartFocusAction, getSelectionSearchString, IFindStartOptions, StartFindAction, StartFindReplaceAction } from 'vs/editor/contrib/find/browser/findController';
Expand All @@ -19,13 +20,12 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IShowNotebookFindWidgetOptions, NotebookFindContrib } from 'vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget';
import { INotebookCommandContext, NotebookMultiCellAction } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { registerNotebookContribution } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
import { CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellUri, NotebookFindScopeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INTERACTIVE_WINDOW_IS_ACTIVE_EDITOR, KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { INotebookCommandContext, NotebookMultiCellAction } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';

registerNotebookContribution(NotebookFindContrib.id, NotebookFindContrib);

Expand Down Expand Up @@ -78,12 +78,7 @@ registerAction2(class extends NotebookMultiCellAction {
}

const controller = editor.getContribution<NotebookFindContrib>(NotebookFindContrib.id);

if (context.selectedCells.length > 1) {
controller.show(undefined, { searchInRanges: true, selectedRanges: editor.getSelections() });
} else {
controller.show(undefined, { searchInRanges: false, selectedRanges: [] });
}
controller.show(undefined, { findScope: { findScopeType: NotebookFindScopeType.None } });
}
});

Expand Down
Loading

0 comments on commit 415f9d1

Please sign in to comment.