Skip to content

Commit b392b2d

Browse files
committed
feat: ensure count is shown for text selection on modal open
1 parent 10e55a0 commit b392b2d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/core/app.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,17 @@ const SearchReplaceForBlockEditor = (): JSX.Element => {
4949
*/
5050
const openModal = (): void => {
5151
setIsModalVisible( true );
52-
setReplacements( 0 );
52+
53+
// Get selected text, if any.
54+
const selectedText: string = getBlockEditorIframe()
55+
.getSelection()
56+
.toString();
57+
58+
// By default, reset count and search input.
59+
if ( ! selectedText ) {
60+
setReplacements( 0 );
61+
setSearchInput( '' );
62+
}
5363
};
5464

5565
/**
@@ -61,7 +71,6 @@ const SearchReplaceForBlockEditor = (): JSX.Element => {
6171
*/
6272
const closeModal = (): void => {
6373
setIsModalVisible( false );
64-
setReplacements( 0 );
6574
};
6675

6776
/**

0 commit comments

Comments
 (0)