Skip to content

How can I toggle LTR <-> RTL on toolbar button click on per block basis? #5468

Closed Answered by alidplus
pauldmps asked this question in Q&A
Discussion options

You must be logged in to vote

use this direction plugin:

type TextDirectionType = 'rtl' | 'ltr'
export const CHANGE_DIRECTION_COMMAND: LexicalCommand<TextDirectionType> =
  createCommand<TextDirectionType>();

export function DirectionPlugin(): null {
  const [editor] = useLexicalComposerContext();
  useEffect(() => {
    return mergeRegister(
      editor.registerCommand(
        CHANGE_DIRECTION_COMMAND,
        (dir) => {
          const selection = $getSelection()
          if (selection && $isRangeSelection(selection)) {
            const nodes = selection.getNodes()
            editor.update(() => {
              for (const node of nodes) {
                /** cpp: closest parent paragraph node */
                

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by pauldmps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants