Skip to content

Bug: Hashtag blocks transformation to Headings #5366

Description

@2wheeh

Lexical version: 0.12.5 (Latest)

Steps To Reproduce

  1. go to the Playground
  2. write some text (or heading, ... )
  3. put selection on the very first position
  4. enter #, ##, ... + ' ' to transform to heading

Link to code example: it can be reproduced on Playground

The current behavior

before-heading-01.mov

The expected behavior

It transforms to heading by HEADING transformer

Activity

  1. 2wheeh commented on Dec 11, 2023

    @2wheeh
    ContributorAuthor

    The bug is here:

          const anchorKey = selection.anchor.key;
          const anchorOffset = selection.anchor.offset;
    
          const anchorNode = editorState._nodeMap.get(anchorKey);
    
          if (
            !$isTextNode(anchorNode) ||
            !dirtyLeaves.has(anchorKey) ||
            (anchorOffset !== 1 && anchorOffset > prevSelection.anchor.offset + 1)
          ) {
            return;
          }

    When we enter #foo, it transforms to hashtag node.
    So when we enter #..# in front of text existing, it goes as following:
    (| : caret)
    |foo
    #|foo
    ##|foo : here, it gets split into # and #foo. And #|foo is gonna be the prevSelection.anchor
    ## |foo : anchorOffset (3) > prevSelection.anchor.offset (1) + 1 -> callback fn returns !

    so it ends up not calling transform (L434)

  2. 2wheeh commented on Dec 12, 2023

    @2wheeh
    Author
  3. changed the title [-]Bug: transform to Heading is not fired when it has text content[/-] [+]Bug: Hashtag blocks transformation to Headings[/+] on Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions