Skip to content

Commit 9c6958d

Browse files
authored
Merge pull request #87 from badasswp/refactor/remove-replicated-instances-of-text
Refactor: Use `replaceInput` in place of repeated instances of `text`
2 parents d2b94e8 + d983134 commit 9c6958d

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Feat: Add Plugin options page.
66
* Feat: Add Shortcut command (CMD + F).
77
* Feat: Add custom hooks: `afterSearchReplace`, `excludedPostTypes`, `regexPattern`.
8+
* Refactor: Use `replaceInput` in place of repeated instances of `text`.
89
* Test: Add e2e tests for plugin codebase.
910
* Tested up to WP 6.9.
1011

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Want to add your personal touch? All of our documentation can be found [here](ht
6868
* Feat: Add Plugin options page.
6969
* Feat: Add Shortcut command (CMD + F).
7070
* Feat: Add custom hooks: `afterSearchReplace`, `excludedPostTypes`, `regexPattern`.
71+
* Refactor: Use `replaceInput` in place of repeated instances of `text`.
7172
* Test: Add e2e tests for plugin codebase.
7273
* Tested up to WP 6.9.
7374

src/core/app.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ const SearchReplaceForBlockEditor = (): JSX.Element => {
207207
select( 'core/block-editor' )
208208
.getBlocks()
209209
.forEach( ( element: any ) => {
210-
recursivelyReplace( element, pattern, replaceInput, status );
210+
recursivelyReplace( element, pattern, status );
211211
} );
212212

213213
if ( status && isSavePostEnabled ) {
@@ -271,21 +271,19 @@ const SearchReplaceForBlockEditor = (): JSX.Element => {
271271
*
272272
* @param {any} element Gutenberg editor block.
273273
* @param {RegExp} pattern Search pattern.
274-
* @param {string} text Replace pattern.
275274
* @param {boolean} status True (Replace), False (Search).
276275
*
277276
* @return {void}
278277
*/
279278
const recursivelyReplace = (
280279
element: any,
281280
pattern: RegExp,
282-
text: string,
283281
status: boolean
284282
): void => {
285283
const { name, innerBlocks } = element;
286284

287285
if ( getAllowedBlocks().indexOf( name ) !== -1 ) {
288-
const args = { element, pattern, text, status };
286+
const args = { element, pattern, status };
289287

290288
/**
291289
* Replace Block Attribute.
@@ -310,7 +308,7 @@ const SearchReplaceForBlockEditor = (): JSX.Element => {
310308

311309
if ( innerBlocks.length ) {
312310
innerBlocks.forEach( ( innerElement: any ) => {
313-
recursivelyReplace( innerElement, pattern, text, status );
311+
recursivelyReplace( innerElement, pattern, status );
314312
} );
315313
}
316314
};
@@ -331,7 +329,6 @@ const SearchReplaceForBlockEditor = (): JSX.Element => {
331329
const property = {};
332330
const {
333331
pattern,
334-
text,
335332
element: { attributes, clientId, name },
336333
status,
337334
} = args;
@@ -353,7 +350,7 @@ const SearchReplaceForBlockEditor = (): JSX.Element => {
353350
*/
354351
const handleAttributeReplacement = (): string => {
355352
setReplacements( ( items: number ) => items + 1 );
356-
return text;
353+
return replaceInput;
357354
};
358355

359356
/**

0 commit comments

Comments
 (0)