Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Select all (cmd/ctrl + A) doesn't work when there's a DecoratorBlockNode with nested editors as the first child #4358

Open
JoelBesada opened this issue Apr 19, 2023 · 2 comments
Labels
all-platforms-bug core Reconciler, DOM, Selection, Node, Events, Composition

Comments

@JoelBesada
Copy link
Contributor

JoelBesada commented Apr 19, 2023

Screen.Recording.2023-04-19.at.14.43.17.mov

Lexical version: 0.10.0 (if this is what's running on playground.lexical.dev right now)

This could be related to #4357, although in this case the select all keyboard shortcut doesn't select any text at all.

Steps To Reproduce

  1. Insert an experimental table node
  2. Remove any content above it
  3. Try to select everything with cmd/ctrl + A (as seen attempted in the Keyboard window in the video recording above)

The current behavior

The select all keyboard shortcut does nothing (or technically speaking, it seems to be selecting everything and deselecting again right after)

The expected behavior

The select all keyboard shortcut should select everything in the editor.

@acywatson acywatson added the core Reconciler, DOM, Selection, Node, Events, Composition label Apr 19, 2023
@petyosi
Copy link
Contributor

petyosi commented May 29, 2023

Same thing happens when a Decorator node is the last child. The selection briefly blinks.

Screen.Recording.2023-05-29.at.18.42.37.mov

@husseinraoouf
Copy link
Contributor

Hello 👋

i was facing the same issue and and fixed with a workaround, i thought i should share it so others can use it until the root issue is fixed

what i did is registering a listener on KEY_DOWN_COMMAND to handle Ctrl+A manually and in the listener i just changed the selection with root.select(0, root.getChildrenSize()) which selects all elements in the root node

export const IS_APPLE: boolean =
    CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform)

export function controlOrMeta(metaKey: boolean, ctrlKey: boolean): boolean {
    if (IS_APPLE) {
        return metaKey
    }
    return ctrlKey
}

export function isSelectAll(
    keyCode: number,
    metaKey: boolean,
    ctrlKey: boolean
): boolean {
    return keyCode === 65 && controlOrMeta(metaKey, ctrlKey)
}

export function $selectAll(editor: LexicalEditor) {
    const root = $getRoot()
    const lastNode = root.getLastChild()
    if (!$isElementNode(lastNode)) {
        lastNode.insertAfter($createAdamParagraphNode())
    }
    root.select(0, root.getChildrenSize())

    const rootElement =
        editor.getRootElement() as HTMLDivElement
    rootElement.focus({
        preventScroll: true,
    })
}

editor.registerCommand<KeyboardEvent>(
  KEY_DOWN_COMMAND,
  (event) => {
      const { keyCode, ctrlKey, metaKey } = event
      if (isSelectAll(keyCode, metaKey, ctrlKey)) {
          event.preventDefault()
          editor.update(() => {
              $selectAll(editor)
          })
          return true
      }

      return false
  },
  COMMAND_PRIORITY_LOW
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
all-platforms-bug core Reconciler, DOM, Selection, Node, Events, Composition
Projects
None yet
Development

No branches or pull requests

5 participants