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

Improve spacebar behavior when entering summary text #59

Closed
jeremyfelt opened this issue Mar 3, 2023 · 1 comment
Closed

Improve spacebar behavior when entering summary text #59

jeremyfelt opened this issue Mar 3, 2023 · 1 comment
Assignees
Labels
bug Something isn't working development Front or back-end development is needed

Comments

@jeremyfelt
Copy link
Member

The spacebar is used on a <summary> element to toggle its parent <details> open/closed. Because of this, we do this horribly hacky thing to prevent the default behavior in the editor, but still insert a space:

/**
* Insert a space at the current position of the cursor and then adjust
* the cursor position, accounting for any selection it has made.
*
* @param {Node} node
*/
const insertSpace = ( node ) => {
const { ownerDocument } = node;
const { defaultView } = ownerDocument;
const sel = defaultView.getSelection();
const range = sel.getRangeAt( 0 );
const textNode = document.createTextNode( ' ' );
range.deleteContents();
range.insertNode( textNode );
range.setStartAfter( textNode );
};

This works, though it can be annoying because there's a slight lag before the space is inserted. If you're typing at any kind of pace at all, you may need to go back and correct the spaces.

The answer may be to use different markup in the editor, though it's nice to present the component as it will be presented on the front-end.

Maybe we could consider presenting different markup when the block is focused in the editor?

@jeremyfelt jeremyfelt added bug Something isn't working development Front or back-end development is needed labels Mar 7, 2023
@jeremyfelt jeremyfelt assigned jeremyfelt and unassigned philcable Dec 11, 2023
@jeremyfelt
Copy link
Member Author

Fixed by #91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working development Front or back-end development is needed
Projects
None yet
Development

No branches or pull requests

2 participants