From b5a3a0382c92abea21b36e51e06861ff92dedea6 Mon Sep 17 00:00:00 2001 From: Madhur Tandon Date: Sat, 12 Mar 2022 15:14:26 +0530 Subject: [PATCH] add options for search input --- src/searchReplace.tsx | 99 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 4 deletions(-) diff --git a/src/searchReplace.tsx b/src/searchReplace.tsx index dbb5581..83ed351 100644 --- a/src/searchReplace.tsx +++ b/src/searchReplace.tsx @@ -2,14 +2,22 @@ import React from 'react'; import { Debouncer } from '@lumino/polling'; import { requestAPI } from './handler'; import { VDomModel, VDomRenderer } from '@jupyterlab/apputils'; -import { Search } from '@jupyter-notebook/react-components'; +import { Search, Button } from '@jupyter-notebook/react-components'; export class SearchReplaceModel extends VDomModel { constructor() { super(); this._searchString = ''; + this._caseSensitive = false; + this._wholeWord = false; + this._useRegex = false; this._debouncedStartSearch = new Debouncer(() => { - this.getSearchString(this._searchString); + this.getSearchString( + this._searchString, + this._caseSensitive, + this._wholeWord, + this._useRegex + ); }); } @@ -29,14 +37,52 @@ export class SearchReplaceModel extends VDomModel { } } + get caseSensitive(): boolean { + return this._caseSensitive; + } + + set caseSensitive(v: boolean) { + this._caseSensitive = v; + this.stateChanged.emit(); + } + + get wholeWord(): boolean { + return this._wholeWord; + } + + set wholeWord(v: boolean) { + this._wholeWord = v; + this.stateChanged.emit(); + } + + get useRegex(): boolean { + return this._useRegex; + } + + set useRegex(v: boolean) { + this._useRegex = v; + this.stateChanged.emit(); + } + get queryResults(): string { return this._queryResults; } - async getSearchString(search: string): Promise { + async getSearchString( + search: string, + caseSensitive: boolean, + wholeWord: boolean, + useRegex: boolean + ): Promise { try { const data = await requestAPI( - '?' + new URLSearchParams([['query', search]]).toString(), + '?' + + new URLSearchParams([ + ['query', search], + ['case_sensitive', caseSensitive.toString()], + ['whole_word', wholeWord.toString()], + ['use_regex', useRegex.toString()] + ]).toString(), { method: 'GET' } @@ -52,6 +98,9 @@ export class SearchReplaceModel extends VDomModel { } private _searchString: string; + private _caseSensitive: boolean; + private _wholeWord: boolean; + private _useRegex: boolean; private _queryResults: any; private _debouncedStartSearch: Debouncer; } @@ -74,6 +123,48 @@ export class SearchReplaceView extends VDomRenderer { (this.model.searchString = event.target.value) } /> + + +
{JSON.stringify(this.model.queryResults, undefined, 4)}
);