-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Keep the cursor position in the Classic Block #12393
Conversation
- On blur store the cursor position and the "raw" content of the Classic Block. - Use the "raw" content when refreshing the editor content on `componentDidUpdate()`. - Restore the cursor position on focus and before inserting content.
const editor = window.tinymce.get( `editor-${ clientId }` ); | ||
let { contentRaw } = attributes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contentRaw is not persisted, we should probably use "local state" for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sure, that'd work even better :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use some e2e test for the classic block :)
Needed when the first thing the user does after adding a Classic Block is to open a modal that inserts something, like the media modal.
setAttributes( { | ||
contentRaw: editor.getContent( { format: 'raw' } ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing the raw content without any processing seems like a bad idea? Why should this be different from the classic editor?
editor.on( 'init', () => { | ||
// Store the initial "raw" content. | ||
setAttributes( { | ||
contentRaw: editor.getContent( { format: 'raw' } ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't expect merely initialising the block to change the content. The user didn't do anything.
const editor = window.tinymce.get( `editor-${ clientId }` ); | ||
let { contentRaw } = attributes; | ||
|
||
// Strip white space before comparing to avoid resetting the editor content when not necessary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of whitespace is different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only differences I'm seeing are in some <p>\u00a0</p>
and some ;
missing/being added to ends of inline style attributes.
Looking more at this, still can't figure out what the refresh code in
Seems at some point it was possible that Even if this is still needed, don't think that looking at @iseulde @aduth any chance you could remember what was the purpose of the above code? I know, it's been there for over a year... |
To me, this is an interesting thing that happens in master:
This means that clicking the image specifically is causing the focus loss? |
I think it is still needed for undo/redo. It needs to be possible to set the content from outside the classic block.
Sounds good to me. |
Yes, clicking anywhere outside the editor triggers the That is easily fixed by doing the |
I'm probably missing something but can't trigger that... Disabling the revert of the content doesn't seem to break undo/redo. |
Another interesting thing: even if I remove |
Right. It still needs |
Why does this only happen for selecting an image though? What's special about this image? |
Here it happens for any click that focuses something outside the editor body. For example opening the menu, etc. |
Found it :) The check in componentDidUpdate() is needed only when the global undo/redo buttons are clicked. Not needed/not running for Ctrl/Cmd + z though... |
Closing this in favor of #12415. |
Fixes #10509.
componentDidUpdate()
. It contains the cursor position "bookmark".