Problem/Motivation

There is no way to change the CKeditor height, especially if one wants to make it smaller.
The result is a UI WTF where all input areas are of equal height, be they supposed to contain only one line or multiple.

As stated in the linked issues, the height of a line varies in wysiwyg, so "having exactly n lines" is not possible by principle.
So this issue's scope is to approximately reflect the row setting.

Proposed resolution

Take the patch from #2717599-7: Text editors do not respect <textarea rows>: make that clear in the formatted text field widgets which makes height = a + b * rows (where rows is configurable per field), and make a and b sitebuilder-configurable globally.

Optionally let the solution ripe in contrib before moving it into core.

Remaining tasks

Code. review, commit.

User interface changes

An additional config section for said parameters.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#30 ckeditor5.js_.txt901 bytesmark_fullmer
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

axel.rutz created an issue. See original summary.

geek-merlin’s picture

Title: "Number of rows" field configuration not working with ckeditor » Make CKEditor (approximately) reflect the rows setting of a field

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Wim Leers’s picture

Category: Bug report » Task
Status: Active » Postponed (maintainer needs more info)
Issue tags: +Usability
Related issues: +#2788905: "Number of rows" configuration on Page Body field not working

#507696: Allow individual width/height per field didn't fix this in the more than eight years that issue was open.

The patch you link to as being a solution (#2717599-7: Text editors do not respect <textarea rows>: make that clear in the formatted text field widgets) is a hack that doesn't work reliably in all situations, which is why we didn't commit that to Drupal core.

Really, #2717599: Text editors do not respect <textarea rows>: make that clear in the formatted text field widgets already explored all possibilities AFAICT. I told you at #2788905-7: "Number of rows" configuration on Page Body field not working:

Feel free to open a completely new issue and then summarize what's happened so far, and what you'd like to see happen on top of that.

You didn't say what you wanted to see happen on top of what has already been done, and how you propose we do that, differently from what #2717599: Text editors do not respect <textarea rows>: make that clear in the formatted text field widgets already tried to do a long time ago.

There's no point in asking to fix something that is not fixable, unless you provide some idea for how to fix it.

geek-merlin’s picture

Huh, that's harsh.

geek-merlin’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs work
geek-merlin’s picture

Issue summary: View changes
Wim Leers’s picture

#6: Sorry, I didn't mean to be harsh. Reading my comment at #5, I of course agree that was unnecessarily harsh.

But I hope you also understand my point: we discussed this at length many times in the past. It's pointless to repeat the exact same discussion. So without new ideas, new perspectives, we'll just end up repeating the previous discussion, which is a waste of everybody's time. That is what I tried to convey, but I did that far too harshly 😥 Sorry! 😔

geek-merlin’s picture

@wim: Any comments on the updated IS? I did read the whole discussion, and the only objection, that wos not thoroughly discussed IMHO, was yours from #2717599-8: Text editors do not respect <textarea rows>: make that clear in the formatted text field widgets. So from my information, without other references, i can not follow your claim there:

we discussed this at length many times in the past. It's pointless to repeat the exact same discussion

To re-state your objection from #2717599-8: Text editors do not respect <textarea rows>: make that clear in the formatted text field widgets:

#7: nice hack :) You can do that in a theme. But it's not acceptable in Drupal core, because you make a lot of assumptions: line height to be 1.5em, a certain vertical margin, etc. That is a bit too simplistic, because depending on the theme (grep the codebase for ckeditor_stylesheets to know what I'm referring to), there may be completely different margins and line heights, or even just font sizes.

So even if there was a consensus reached in a place that i do not know, i can not see the cited objections hold for
a) the goal of *approximately* reflectiong the row setting like stated in title and IS, and
b) an implementation that makes the row-to-height mapping configurable like proposed in the IS

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

geek-merlin’s picture

Status: Needs work » Active

Implemented this in contrib land for now. (JS object decorators FTW!)
https://www.drupal.org/project/ckeditorheight

Still thinking it should come with core.

geek-merlin’s picture

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anybody’s picture

As we can see in the growing usage of axel.rutz contrib module, there's demand for this fix... I also agree this should be part of core, otherwise this form setting (rows) makes no sense at all for default ckeditor. And yes, there are many cases where you want a small or a hughe field dependent on expected content. Autogrow (in core already) helps if the field is too small then...

PS: The ckeditorheight plugin works like a charm :)

Anybody’s picture

Shell we create a patch based on axel.rutz module to proceed here? The current situation where the setting simply has no effect is much worse than the solution from #12. So I don't unterstand what's the show-stopper here even after reading the linked issues / discussions.

@Wim Leers, would you mind to have a look at the contrib module and see what it does to compate that against the current core behaviour as documented in the issue description? Of course nobody wants to waste anyones time, but I think we can lead this to a fine solution.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mlncn’s picture

I would very much like to see a patch based on the module. I am using the module on all sites now. It is simply providing expected behavior. I thought that when changing the rows failed to change the height, that it was a bug. I didn't even mentally register the "explanatory" text until finding issues about the problem, and still think the explanatory text is inadequate— but the very fact that it was added at all, indicates a need for this approximation fix instead.

Anybody’s picture

I absolutely agree with #18!

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

PhilY’s picture

Using the CKEditorHeight module too on several sites without problem.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Wim Leers’s picture

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Project: Drupal core » CKEditor 4 - WYSIWYG HTML editor
Version: 9.5.x-dev » 1.0.x-dev
Component: ckeditor.module » Code

CKEditor has been removed from core, CKEditor 4 is removed from Drupal Core in 10.0.0

tgoeg’s picture

Has anyone tried out whether this just shifts the problem to CKEditor5 and we need a new ticket, then, or if it is solved in v5/solvable by different means?

mark_fullmer’s picture

FileSize
901 bytes

Has anyone tried out whether this just shifts the problem to CKEditor5 and we need a new ticket

The contrib module CKeditor Height issue queue reports that their current implementation does not work with CKEditor 5: https://www.drupal.org/project/ckeditorheight/issues/3274041

or if it is solved in v5/solvable by different means?

The issue in the CKEditor 5 queue regarding this is https://github.com/ckeditor/ckeditor5/issues/636 , and it doesn't appear that they're providing a solution as of right now. A workaround is referenced in https://github.com/ckeditor/ckeditor5/issues/636#issuecomment-405952805 , specifically https://stackoverflow.com/a/46559355

If we wanted to apply this to Drupal markup syntax, a well-scoped CSS-only solution (tested, works), would be to add min-height declarations for a series of row attributes, a la:

...
textarea[data-ckeditor5-id][rows="3"]+.ck-editor .ck-editor__editable_inline {
  min-height: calc(1.5em * 3);
}
textarea[data-ckeditor5-id][rows="4"]+.ck-editor .ck-editor__editable_inline {
  min-height: calc(1.5em * 4);
}
textarea[data-ckeditor5-id][rows="5"]+.ck-editor .ck-editor__editable_inline {
  min-height: calc(1.5em * 5);
}
...

Being squeamish about such CSS verbosity, I also explored a JS approach that would add the min-height as an inline style (attached file). However, the auto_grow plugin uses JS to adjust the CKEditor window, which would remove the inline style. I can picture some JS that reapplies the style on change, but this would have its own disadvantages.

John Pitcairn’s picture

Unfortunately no browser will currently let us use the rows attribute value in css via a simple attr(rows). But the css verbosity can be reduced somewhat with something like:

[rows=3] {
  --rows: 3
}
[rows=4] {
  --rows: 4
}
[rows=5] {
  --rows: 5
}
[data-ckeditor5-id] + .ck-editor .ck-editor__editable_inline {
  min-height: calc(1.5em * var(--rows, 5));
}

Or a js solution (or Drupal preprocess) could insert the --rows variable in an inline style for css to use.

tgoeg’s picture

Preprocessing sounds the least intrusive and most compatible with other modules, to me at least.
I am just a sysadmin, but from what I gather from modules and preprocessing until now, I think this could be put into a simple loop and would somewhat abstract the ugliness of defining every single --rows variable (at least in code, the resulting CSS definitely has the list).

Generally speaking this should make it into core (or core's CKEditor5 module) as a fixed part eventually, not as an additional piece of code a theme or a module adds. This would keep those two parts (preprocessing and applying the CSS) pretty close together, which sounds favorable to me. Splitting the two parts too far apart would otherwise by a little hard to grasp (and understand/maintain later on).

geek-merlin’s picture

> Generally speaking this should make it into core (or core's CKEditor5 module) as a fixed part eventually, not as an additional piece of code a theme or a module adds.

The CKEditor5 debate lives here, see my comment: #3241295-25: CKEditor 5 isn't respecting field widgets row settings

And as ckeditorheight.module creator: If someone moves the code into ckeditor4.module, i'm all for it.

geek-merlin’s picture

Status: Active » Closed (won't fix)

Given that the contrib module exists and works for mans, and the approach went core, i deem this wontfix now.

Thanks everyone!