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

#8689: The editor placeholder should not disappear until started typing #8867

Merged
merged 19 commits into from
Feb 2, 2021

Conversation

oleq
Copy link
Member

@oleq oleq commented Jan 19, 2021

Suggested merge commit message (convention)

Fix (engine): The editor placeholder should not disappear until started typing. Closes #8689.
Fix (image): Image caption placeholder is now hidden when focused. See #8689.
Fix (heading): In Title plugin, the body placeholder is visible even when the body section is focused. See #8689.
Fix: Editor will show the placeholder even when focused. See #8689.



Additional information

This is a draft as I pointed out in the original PR. It needs proper tests and documentation.

@maxbarnas
Copy link
Contributor

maxbarnas commented Jan 26, 2021

@oleq, I had trouble understanding at first how the hideOnFocus works here https://github.com/ckeditor/ckeditor5/pull/8867/files#diff-4691af5a35179ee901044c054fabd91c8baffb422338eaaba2a9a57121869541R162 without checking a focus.

Tell me please, if I got this wrong, but we are assuming that the post-fixer was fired on change, therefore we can assume the focus is there, in the element, so the only thing left is to check the configuration option to decide whether we want to hide placeholder.

If that's correct, then maybe we could change the name of hideOnFocus in needsPlaceholder() to something less related to the config property, and more to needsPlaceholder() context? Maybe requireSelection or reverse it to keepPlaceholderWhenFocused? Or maybe I should just add a lengthy comment with an explanation? WDYT?

@maxbarnas
Copy link
Contributor

Also, do you see a preferred way of testing this change? https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-image/src/imagecaption/utils.js#L30

@oleq
Copy link
Member Author

oleq commented Jan 27, 2021

@oleq, had trouble understanding at first how the hideOnFocus works here https://github.com/ckeditor/ckeditor5/pull/8867/files#diff-4691af5a35179ee901044c054fabd91c8baffb422338eaaba2a9a57121869541R162 without checking a focus.

  1. First, we check if the element is attached. If not, well, it certainly does not need a placeholder.
  2. Then (since attached), we check if it has some content. If so, again, there's no point in giving it a placeholder.
  3. Then we deal with the document focus because we know the element is attached and without any content.
    1. If we don't care about the document focus (L162), the whole next point is bogus. We can add the placeholder to the element straight away (L170) since it is attached and empty.
    2. If we don't want a placeholder on document focus, we need to check if the document is focused (L169)
      1. And, if the document is focused, then we must make sure the selection is somewhere else (L177) before giving it element a placeholder (like in the Title plugin).
      2. And if the document is not focused, we don't care about the selection (because the user is not editing) so we add the placeholder to the element straight away (L170).

If that's correct, then maybe we could change the name of hideOnFocus in needsPlaceholder() to something less related to the config property, and more to needsPlaceholder() context?

I agree this is a bad name of the argument. I'd say considerDocumentFocus/notNeededWhenDocumentFocused + some lengthy explanation should do the trick.

@oleq
Copy link
Member Author

oleq commented Jan 27, 2021

Also, do you see a preferred way of testing this change? https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-image/src/imagecaption/utils.js#L30

Somewhere in ImageCaptionEditing plugins we'll need a test that focuses the image with an empty caption (placeholder shows up) then it moves the selection to the caption (the placeholder should disappear).

@maxbarnas maxbarnas marked this pull request as ready for review January 27, 2021 14:49
@niegowski niegowski self-requested a review January 28, 2021 11:27
Copy link
Contributor

@niegowski niegowski left a comment

Choose a reason for hiding this comment

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

I think that we also need some tests for the new option (inside the placeholder tests). Currently, I can see only new tests for needsPlaceholder.

Also, this PR is introducing a breaking change on enablePlaceholder and needsPlaceholder functions.

packages/ckeditor5-engine/tests/view/placeholder.js Outdated Show resolved Hide resolved
packages/ckeditor5-engine/tests/view/placeholder.js Outdated Show resolved Hide resolved
packages/ckeditor5-engine/tests/view/placeholder.js Outdated Show resolved Hide resolved
packages/ckeditor5-image/src/imagecaption/utils.js Outdated Show resolved Hide resolved
@maxbarnas
Copy link
Contributor

Also, this PR is introducing a breaking change on enablePlaceholder and needsPlaceholder functions.

I wonder whether I should:

  • Update the tests and note down that we are introducing a breaking change to the default behavior of enablePlaceholder()
  • Reverse the default behavior back to a state where it hides placeholder on focus, but then we need to update the configuration of all the builds, to make them keep the placeholder on focus.

@oleq
Copy link
Member Author

oleq commented Feb 1, 2021

  • Let's unify the config and avoid negations when passing config between helpers.
    • keepOnFocus.
  • Let's update editors (classic, inline, etc.) with the new configuration.
  • This way there will be no BCs in the API.

@maxbarnas maxbarnas requested a review from niegowski February 1, 2021 13:40
@niegowski niegowski merged commit 8a276bd into master Feb 2, 2021
@niegowski niegowski deleted the i/8689-smarter-editor-placeholder branch February 2, 2021 15:26
mhsdesign added a commit to neos/neos-ui that referenced this pull request Oct 9, 2024
In Neos 7.3.17 and before the placeholder in ckeditor would not disappear when focused. And only when typing. By switching to the native placeholder feature of ckeditor in #3558 we introduced a regression as that implementation would hide the placeholder while just clicking into.
This is especially noticeable for centered texts as the cursor needs one millisecond to adjust and its glitchy.

 This will eventually be fixed in Ckeditor 24 something. As a hotfix for our version 16 i introduce the patch of ckeditor/ckeditor5#8474 (without the css absolute change as that would make centered text uneditable). The mentioned fix was not merged directly into ckeditor but made way more complicated: ckeditor/ckeditor5#8867
 We dont need the more complicated fix as we dont use the mentioned features of the placeholder in a image description and such.
markusguenther added a commit to neos/neos-ui that referenced this pull request Oct 14, 2024
…3864)

* BUGFIX: Restore old Placeholder behavior to keep shown when focused

In Neos 7.3.17 and before the placeholder in ckeditor would not disappear when focused. And only when typing. By switching to the native placeholder feature of ckeditor in #3558 we introduced a regression as that implementation would hide the placeholder while just clicking into.
This is especially noticeable for centered texts as the cursor needs one millisecond to adjust and its glitchy.

 This will eventually be fixed in Ckeditor 24 something. As a hotfix for our version 16 i introduce the patch of ckeditor/ckeditor5#8474 (without the css absolute change as that would make centered text uneditable). The mentioned fix was not merged directly into ckeditor but made way more complicated: ckeditor/ckeditor5#8867
 We dont need the more complicated fix as we dont use the mentioned features of the placeholder in a image description and such.

* TASK: Move cursor before the placeholer

* TASK: Hide break in placeholder context

To move the cursor to the first position, the placeholder text is moved backwards. Therefore, a change with a break is disadvantageous.

---------

Co-authored-by: Markus Günther <info@unikka.de>
laurahaenel pushed a commit to laurahaenel/neos-ui that referenced this pull request Oct 21, 2024
…eos#3864)

* BUGFIX: Restore old Placeholder behavior to keep shown when focused

In Neos 7.3.17 and before the placeholder in ckeditor would not disappear when focused. And only when typing. By switching to the native placeholder feature of ckeditor in neos#3558 we introduced a regression as that implementation would hide the placeholder while just clicking into.
This is especially noticeable for centered texts as the cursor needs one millisecond to adjust and its glitchy.

 This will eventually be fixed in Ckeditor 24 something. As a hotfix for our version 16 i introduce the patch of ckeditor/ckeditor5#8474 (without the css absolute change as that would make centered text uneditable). The mentioned fix was not merged directly into ckeditor but made way more complicated: ckeditor/ckeditor5#8867
 We dont need the more complicated fix as we dont use the mentioned features of the placeholder in a image description and such.

* TASK: Move cursor before the placeholer

* TASK: Hide break in placeholder context

To move the cursor to the first position, the placeholder text is moved backwards. Therefore, a change with a break is disadvantageous.

---------

Co-authored-by: Markus Günther <info@unikka.de>
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.

The editor placeholder should disappear when typing, not when focusing the editor
4 participants