Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable "Search Cell Outputs" in Find/Replace, disable "Replace" button when an output is highlighted #16157

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions packages/documentsearch/src/searchmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ export class SearchDocumentModel
}
}

/**
* Whether the replace button is enabled or not.
*/
get replaceEnabled(): boolean {
return this._replaceEnabled;
}

/**
* Search expression
*/
Expand Down Expand Up @@ -270,7 +277,10 @@ export class SearchDocumentModel
* Highlight the next match.
*/
async highlightNext(): Promise<void> {
await this.searchProvider.highlightNext();
const match = await this.searchProvider.highlightNext();
if (match) {
this._replaceEnabled = match.node == undefined;
}
// Emit state change as the index needs to be updated
this.stateChanged.emit();
}
Expand All @@ -279,7 +289,10 @@ export class SearchDocumentModel
* Highlight the previous match
*/
async highlightPrevious(): Promise<void> {
await this.searchProvider.highlightPrevious();
const match = await this.searchProvider.highlightPrevious();
if (match) {
this._replaceEnabled = match.node == undefined;
}
// Emit state change as the index needs to be updated
this.stateChanged.emit();
}
Expand Down Expand Up @@ -386,6 +399,7 @@ export class SearchDocumentModel
private _initialQuery = '';
private _filters: IFilters = {};
private _replaceText: string = '';
private _replaceEnabled = true;
private _searchActive = false;
private _searchDebouncer: Debouncer;
private _searchExpression = '';
Expand Down
10 changes: 9 additions & 1 deletion packages/documentsearch/src/searchview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ interface IReplaceEntryProps {
preserveCase: boolean;
replaceOptionsSupport: IReplaceOptionsSupport | undefined;
replaceText: string;
replaceEnabled: boolean;
translator?: ITranslator;
}

Expand Down Expand Up @@ -259,6 +260,7 @@ function ReplaceEntry(props: IReplaceEntryProps): JSX.Element {
className={REPLACE_BUTTON_WRAPPER_CLASS}
onClick={() => props.onReplaceCurrent()}
tabIndex={0}
disabled={!props.replaceEnabled}
>
<span
className={`${REPLACE_BUTTON_CLASS} ${BUTTON_CONTENT_CLASS}`}
Expand Down Expand Up @@ -455,7 +457,7 @@ interface ISearchOverlayProps {
*/
replaceEntryVisible: boolean;
/**
* Whther the filters grid is visible.
* Whether the filters grid is visible.
*/
filtersVisible: boolean;
/**
Expand All @@ -466,6 +468,10 @@ interface ISearchOverlayProps {
* Replacement expression
*/
replaceText: string;
/**
* Whether the replace button is enabled.
*/
replaceEnabled: boolean;
/**
* The text in the search entry
*/
Expand Down Expand Up @@ -777,6 +783,7 @@ class SearchOverlay extends React.Component<ISearchOverlayProps> {
onReplaceAll={() => this.props.onReplaceAll()}
replaceOptionsSupport={this.props.replaceOptionsSupport}
replaceText={this.props.replaceText}
replaceEnabled={this.props.replaceEnabled}
preserveCase={this.props.preserveCase}
translator={this.translator}
/>
Expand Down Expand Up @@ -912,6 +919,7 @@ export class SearchDocumentView extends VDomRenderer<SearchDocumentModel> {
filtersVisible={this._showFilters}
replaceOptionsSupport={this.model.replaceOptionsSupport}
replaceText={this.model.replaceText}
replaceEnabled={this.model.replaceEnabled}
initialSearchText={this.model.initialQuery}
searchInputRef={
this._searchInput as React.RefObject<HTMLTextAreaElement>
Expand Down
5 changes: 5 additions & 0 deletions packages/documentsearch/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ export interface ISearchMatch {
* Start location of the match (in a text, this is the column)
*/
position: number;

/**
* Node containing the match
*/
node?: Text;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/notebook/src/searchprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class NotebookSearchProvider extends SearchProvider<NotebookPanel> {
'Search in the cell outputs (not available when replace options are shown).'
),
default: false,
supportReplace: false
supportReplace: true
},
selection: {
title:
Expand Down