Skip to content

Commit

Permalink
style: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yf-yang committed Nov 27, 2024
1 parent e3c22b2 commit 6c10766
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ it('should be', () => {
expect(
decorateFindReplace({
...getEditorPlugin(editor, FindReplacePlugin),
entry: [{ type: 'p', children: [{ text: '' }] }, [0]],
entry: [{ children: [{ text: '' }], type: 'p' }, [0]],
})
).toEqual(output);
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ it('should decorate matching text', () => {
expect(
plugin.decorate?.({
...getEditorPlugin(editor, plugin),
entry: [{ type: 'p', children: [{ text: 'test' }] }, [0]],
entry: [{ children: [{ text: 'test' }], type: 'p' }, [0]],
})
).toEqual([
{
Expand Down Expand Up @@ -45,7 +45,7 @@ it('should decorate matching text case-insensitively', () => {
expect(
plugin.decorate?.({
...getEditorPlugin(editor, plugin),
entry: [{ type: 'p', children: [{ text: 'test' }] }, [0]],
entry: [{ children: [{ text: 'test' }], type: 'p' }, [0]],
})
).toEqual([
{
Expand Down Expand Up @@ -76,7 +76,7 @@ it('should decorate matching consecutive text nodes', () => {
plugin.decorate?.({
...getEditorPlugin(editor, plugin),
entry: [
{ type: 'p', children: [{ text: 'tes' }, { text: 't', bold: true }] },
{ children: [{ text: 'tes' }, { bold: true, text: 't' }], type: 'p' },
[0],
],
})
Expand Down Expand Up @@ -122,12 +122,12 @@ it('should decorate matching multiple occurrences', () => {
...getEditorPlugin(editor, plugin),
entry: [
{
type: 'p',
children: [
{ text: 'tes' },
{ text: 'ts and tests and t', bold: true },
{ bold: true, text: 'ts and tests and t' },
{ text: 'ests' },
],
type: 'p',
},
[0],
],
Expand Down
11 changes: 6 additions & 5 deletions packages/find-replace/src/lib/decorateFindReplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ export const decorateFindReplace: Decorate<FindReplaceConfig> = ({

let start = 0;
const matches: number[] = [];

while ((start = str.indexOf(searchLower, start)) !== -1) {
matches.push(start);
start += searchLower.length;
}

if (!matches.length) {
if (matches.length === 0) {
return [];
}

Expand All @@ -47,6 +48,7 @@ export const decorateFindReplace: Decorate<FindReplaceConfig> = ({
// If the match ends before the start of the current text, move to the next match
if (matchEnd <= textStart) {
matchIndex++;

continue;
}

Expand All @@ -66,18 +68,17 @@ export const decorateFindReplace: Decorate<FindReplaceConfig> = ({

ranges.push({
anchor: {
path: textNodePath,
offset: anchorOffset,
path: textNodePath,
},
focus: {
path: textNodePath,
offset: focusOffset,
path: textNodePath,
},
search: search.substring(searchOverlapStart, searchOverlapEnd),
search: search.slice(searchOverlapStart, searchOverlapEnd),
[type]: true,
});
}

// If the match ends within the current text, move to the next match
if (matchEnd <= textEnd) {
matchIndex++;
Expand Down

0 comments on commit 6c10766

Please sign in to comment.