Skip to content

How to implement find and replace functions? #5937

Answered by 2wheeh
newproplus asked this question in Q&A
Discussion options

You must be logged in to vote

I would use COMMAND if that function is fired on event like button click.

here is a simple implementation.

2024-04-22.6.36.13.mov
import type {LexicalCommand, LexicalEditor} from 'lexical';

import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
import {
  $nodesOfType,
  COMMAND_PRIORITY_EDITOR,
  createCommand,
  TextNode,
} from 'lexical';
import React, {useEffect} from 'react';

interface Payload {
  from: string;
  to: string;
}

const FIND_REPLACE_COMMAND: LexicalCommand<Payload> = createCommand(
  'FIND_REPLACE_COMMAND',
);

const listener = ({from, to}: Payload, editor: LexicalEditor) => {
  editor.update(() => {
    const textNodes = $nodesOfType(

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by newproplus
Comment options

You must be logged in to vote
1 reply
@tipycalFlow
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants