提交 dab68ed8 编写于 作者: R rebornix

add options support in notebook find widget.

上级 92b25083
......@@ -62,7 +62,7 @@ export abstract class SimpleFindReplaceWidget extends Widget {
@IContextViewService private readonly _contextViewService: IContextViewService,
@IContextKeyService contextKeyService: IContextKeyService,
@IThemeService private readonly _themeService: IThemeService,
private readonly _state: FindReplaceState = new FindReplaceState(),
protected readonly _state: FindReplaceState = new FindReplaceState(),
showOptionButtons?: boolean
) {
super();
......
......@@ -24,6 +24,9 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { getActiveNotebookEditor } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions';
import { FindReplaceState } from 'vs/editor/contrib/find/findState';
import { INotebookSearchOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
const FIND_HIDE_TRANSITION = 'find-hide-transition';
const FIND_SHOW_TRANSITION = 'find-show-transition';
......@@ -45,9 +48,10 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
@IContextViewService contextViewService: IContextViewService,
@IContextKeyService contextKeyService: IContextKeyService,
@IThemeService themeService: IThemeService,
@IConfigurationService private readonly _configurationService: IConfigurationService
) {
super(contextViewService, contextKeyService, themeService);
super(contextViewService, contextKeyService, themeService, new FindReplaceState(), true);
DOM.append(this._notebookEditor.getDomNode(), this.getDomNode());
this._findWidgetFocused = KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED.bindTo(contextKeyService);
......@@ -56,6 +60,10 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
this._register(themeService.onDidColorThemeChange(() => {
this.updateTheme(themeService.getColorTheme());
}));
this._register(this._state.onFindReplaceStateChange(() => {
this.onInputChanged();
}));
}
private _onFindInputKeyDown(e: IKeyboardEvent): void {
......@@ -63,7 +71,7 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
if (this._findMatches.length) {
this.find(false);
} else {
this.set(null);
this.set(null, true);
}
e.preventDefault();
return;
......@@ -71,7 +79,7 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
if (this._findMatches.length) {
this.find(true);
} else {
this.set(null);
this.set(null, true);
}
e.preventDefault();
return;
......@@ -80,13 +88,18 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
protected onInputChanged(): boolean {
const val = this.inputValue;
const wordSeparators = this._configurationService.inspect<string>('editor.wordSeparators').value;
const options: INotebookSearchOptions = { regex: this._getRegexValue(), wholeWord: this._getWholeWordValue(), caseSensitive: this._getCaseSensitiveValue(), wordSeparators: wordSeparators };
if (val) {
this._findMatches = this._notebookEditor.viewModel!.find(val).filter(match => match.matches.length > 0);
this._findMatches = this._notebookEditor.viewModel!.find(val, options).filter(match => match.matches.length > 0);
this.set(this._findMatches, false);
if (this._findMatches.length) {
return true;
} else {
return false;
}
} else {
this.set([], false);
}
return false;
......@@ -98,7 +111,7 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
}
if (!this._findMatchesStarts) {
this.set(this._findMatches);
this.set(this._findMatches, true);
} else {
const totalVal = this._findMatchesStarts!.getTotalValue();
const nextVal = (this._currentMatch + (previous ? -1 : 1) + totalVal) % totalVal;
......@@ -117,7 +130,7 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
}
if (!this._findMatchesStarts) {
this.set(this._findMatches);
this.set(this._findMatches, true);
}
const nextIndex = this._findMatchesStarts!.getIndexOf(this._currentMatch);
......@@ -179,7 +192,7 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
}
}
private set(cellFindMatches: CellFindMatch[] | null): void {
private set(cellFindMatches: CellFindMatch[] | null, autoStart: boolean): void {
if (!cellFindMatches || !cellFindMatches.length) {
this._findMatches = [];
this.setAllFindMatchesDecorations([]);
......@@ -196,9 +209,12 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
// current match
this.constructFindMatchesStarts();
if (autoStart) {
this._currentMatch = 0;
this.setCurrentFindMatchDecoration(0, 0);
}
}
private setCurrentFindMatchDecoration(cellIndex: number, matchIndex: number) {
this._notebookEditor.changeModelDecorations(accessor => {
......@@ -270,7 +286,7 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
hide() {
super.hide();
this.set([]);
this.set([], false);
if (this._hideTimeout === null) {
if (this._showTimeout !== null) {
......
......@@ -15,7 +15,7 @@ import * as model from 'vs/editor/common/model';
import { SearchParams } from 'vs/editor/common/model/textModelSearch';
import { EDITOR_TOP_PADDING } from 'vs/workbench/contrib/notebook/browser/constants';
import { CellEditState, CellFocusMode, CursorAtBoundary, CellViewModelStateChangeEvent, IEditableCellViewModel, INotebookCellDecorationOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellKind, NotebookCellMetadata, NotebookDocumentMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, NotebookCellMetadata, NotebookDocumentMetadata, INotebookSearchOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
export abstract class BaseCellViewModel extends Disposable {
......@@ -382,15 +382,21 @@ export abstract class BaseCellViewModel extends Disposable {
abstract resolveTextModel(): Promise<model.ITextModel>;
protected cellStartFind(value: string): model.FindMatch[] | null {
protected cellStartFind(value: string, options: INotebookSearchOptions): model.FindMatch[] | null {
let cellMatches: model.FindMatch[] = [];
if (this.assertTextModelAttached()) {
cellMatches = this.textModel!.findMatches(value, false, false, false, null, false);
cellMatches = this.textModel!.findMatches(
value,
false,
options.regex || false,
options.caseSensitive || false,
options.wholeWord ? options.wordSeparators || null : null,
false);
} else {
const lineCount = this.textBuffer.getLineCount();
const fullRange = new Range(1, 1, lineCount, this.textBuffer.getLineLength(lineCount) + 1);
const searchParams = new SearchParams(value, false, false, null);
const searchParams = new SearchParams(value, options.regex || false, options.caseSensitive || false, options.wholeWord ? options.wordSeparators || null : null,);
const searchData = searchParams.parseSearchRequest();
if (!searchData) {
......
......@@ -11,7 +11,7 @@ import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer'
import { BOTTOM_CELL_TOOLBAR_HEIGHT, CELL_MARGIN, CELL_RUN_GUTTER, CELL_STATUSBAR_HEIGHT, EDITOR_BOTTOM_PADDING, EDITOR_TOOLBAR_HEIGHT, EDITOR_TOP_MARGIN, EDITOR_TOP_PADDING, CELL_BOTTOM_MARGIN, CODE_CELL_LEFT_MARGIN } from 'vs/workbench/contrib/notebook/browser/constants';
import { CellEditState, CellFindMatch, CodeCellLayoutChangeEvent, CodeCellLayoutInfo, ICellViewModel, NotebookLayoutInfo } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { CellKind, NotebookCellOutputsSplice } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, NotebookCellOutputsSplice, INotebookSearchOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { BaseCellViewModel } from './baseCellViewModel';
import { NotebookEventDispatcher } from 'vs/workbench/contrib/notebook/browser/viewModel/eventDispatcher';
......@@ -243,8 +243,8 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
private readonly _hasFindResult = this._register(new Emitter<boolean>());
public readonly hasFindResult: Event<boolean> = this._hasFindResult.event;
startFind(value: string): CellFindMatch | null {
const matches = super.cellStartFind(value);
startFind(value: string, options: INotebookSearchOptions): CellFindMatch | null {
const matches = super.cellStartFind(value, options);
if (matches === null) {
return null;
......
......@@ -14,7 +14,7 @@ import { MarkdownRenderer } from 'vs/workbench/contrib/notebook/browser/view/ren
import { BaseCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel';
import { EditorFoldingStateDelegate } from 'vs/workbench/contrib/notebook/browser/contrib/fold/foldingModel';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, INotebookSearchOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookEventDispatcher, NotebookCellStateChangedEvent } from 'vs/workbench/contrib/notebook/browser/viewModel/eventDispatcher';
export class MarkdownCellViewModel extends BaseCellViewModel implements ICellViewModel {
......@@ -179,8 +179,8 @@ export class MarkdownCellViewModel extends BaseCellViewModel implements ICellVie
private readonly _hasFindResult = this._register(new Emitter<boolean>());
public readonly hasFindResult: Event<boolean> = this._hasFindResult.event;
startFind(value: string): CellFindMatch | null {
const matches = super.cellStartFind(value);
startFind(value: string, options: INotebookSearchOptions): CellFindMatch | null {
const matches = super.cellStartFind(value, options);
if (matches === null) {
return null;
......
......@@ -24,7 +24,7 @@ import { NotebookEventDispatcher, NotebookMetadataChangedEvent } from 'vs/workbe
import { CellFoldingState, EditorFoldingStateDelegate } from 'vs/workbench/contrib/notebook/browser/contrib/fold/foldingModel';
import { MarkdownCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { CellKind, NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, NotebookCellMetadata, INotebookSearchOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { FoldingRegions } from 'vs/editor/contrib/folding/foldingRanges';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { MarkdownRenderer } from 'vs/workbench/contrib/notebook/browser/view/renderers/mdRenderer';
......@@ -1017,10 +1017,10 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
* Search in notebook text model
* @param value
*/
find(value: string): CellFindMatch[] {
find(value: string, options: INotebookSearchOptions): CellFindMatch[] {
const matches: CellFindMatch[] = [];
this._viewCells.forEach(cell => {
const cellMatches = cell.startFind(value);
const cellMatches = cell.startFind(value, options);
if (cellMatches) {
matches.push(cellMatches);
}
......
......@@ -600,3 +600,10 @@ export enum NotebookEditorPriority {
default = 'default',
option = 'option',
}
export interface INotebookSearchOptions {
regex?: boolean;
wholeWord?: boolean;
caseSensitive?: boolean
wordSeparators?: string;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册