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

fix(407): clear text on action menu click #408

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Nikolai-featurebase
Copy link

@Nikolai-featurebase Nikolai-featurebase commented Dec 16, 2024

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #407

Type of change

Please tick the relevant option.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have performed a self-review of my own code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have checked my code and corrected any misspellings

@Darginec05 Darginec05 changed the base branch from master to v4.9.3 December 16, 2024 16:30
@Darginec05 Darginec05 changed the base branch from v4.9.3 to master December 16, 2024 17:08
{
...newBlock.value[0],
children: [{ text: '' }],
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can break logic for complex blocks with multiple nested Slate children.
My suggesstion:

    const lastNode = Editor.last(newSlate, [0]);
    Transforms.delete(newSlate, { at: lastNode[1] });

Copy link
Contributor

@gloaysa gloaysa Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @Darginec05 I was having a look at this one and I noticed that we do a lot more of stuff on the ActionMenuList when the user selects the block on key down.

Shouldn't we unify this behaviour?

if (HOTKEYS.isEnter(event)) {
        event.preventDefault();

        const selected = document.querySelector('[data-action-menu-item][aria-selected=true]') as HTMLElement;
        const type = selected?.dataset.actionMenuItemType;
        if (!type) return;

        const blockEntry: NodeEntry<SlateElement<string>> | undefined = Editor.above(slate, {
          match: (n) => Element.isElement(n) && Editor.isBlock(slate, n),
          mode: 'lowest',
        });

        if (blockEntry) {
          const [, currentNodePath] = blockEntry;
          const path = blockEntry ? currentNodePath : [];

          const start = Editor.start(slate, path);
          const range = { anchor: slate.selection.anchor, focus: start };

          Transforms.select(slate, range);
          Transforms.delete(slate);
        }

        editor.toggleBlock(type, { deleteText: true, focus: true });
        return onClose();
      }

If you noticed, inside the if (blockEntry) statement is where we call Transforms.delete(slate), and that's why the bug is not present when selecting the block using the keyboard. Remove that delete and the bug appears.

I propose to move the whole handleActionMenuKeyDown function to the utils.ts file (to clean up the component and consistency with all the other util functions), and reuse the logic for the click function in getItemProps and the Enter key-down event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] action menu command not cleared on click
3 participants