singerdmx / flutter-quill

Rich text editor for Flutter
https://pub.dev/packages/flutter_quill
MIT License
2.43k stars 768 forks source link

Feature: Line height attribute #1956

Closed CatHood0 closed 1 day ago

CatHood0 commented 1 week ago

Is there an existing issue for this?

Proposal

I propose creating an attribute to be able to modify the space between lines, of course, I am not just proposing whether to do my part. I already have the implementation done with the button next to the attribute, however, I would like to know if there are plans to implement this feature, since I have seen several ones (like me) that for their applications, an attribute like line-height , it would be very good for us, since it makes the editor more complete (and the spice between words and letters is another story.

The issue is that, if it is planned, I would like to know where I could start looking to add it natively to the project.

This is how work by now:

https://github.com/singerdmx/flutter-quill/assets/114286961/927836e4-5c6c-4835-8124-90d4aac911fe

singerdmx commented 1 week ago

I wonder how this is handled in react-quill

singerdmx commented 1 week ago

Below is the reply from ChatGPT:

React Quill does not have a built-in attribute specifically for setting line height directly through its API. Instead, you can adjust line height and other styles by applying custom CSS to the editor content.

Here’s how you can adjust line heights in React Quill:

  1. Define your CSS for the desired line height, for example:
.ql-editor {
  line-height: 1.5;  /* Adjust the value as needed */
}
  1. Ensure this CSS is loaded into the component where React Quill is used. This could be in your global stylesheet or scoped styles depending on your setup.
singerdmx commented 1 week ago

If we cannot find this being enabled elsewhere, we may have to create a new attribute with a good name

CatHood0 commented 1 week ago

Here’s how you can adjust line heights in React Quill

I saw this before. I searched, but found a same answer as your. Then i decide just create a custom attribute that isn't at react-quill. I don't know what do you think about it. Should we add it since react-quill doesn't use it?.

On my implementation i called as:

class LineHeightAttribute extends Attribute<String?> {
  const LineHeightAttribute({String? value = "1.0"})
      : super(
          'line-height',
          AttributeScope.block,
          value,
        );
}
singerdmx commented 1 week ago

What would the corresponding delta json look like?

CatHood0 commented 1 week ago

Looks like:

344361618-e2c8ff64-8b90-46ff-b5dc-214c97323151_1_50

singerdmx commented 1 week ago

I am fine with line-height But would the number mean differently for different platform such as web v.s. mobile?

singerdmx commented 1 week ago

Here is what ChatGPT says:

it is a multiplier applied to the current font size to determine the height of the line boxes in which the text is placed. Here’s what that number represents:

singerdmx commented 1 week ago

So we will only support Unitless value for now?

CatHood0 commented 1 week ago

I think on this feature using always Unitless (because i'm make this one using as a base LibreOffice, Word, and others Word Processors), but, idk about web platform. I'll need to take a look to watch the behavior. Any suggestion?

singerdmx commented 1 week ago

Just unitless value should be fine. I just want you to be aware the existence of the other two.

singerdmx commented 1 week ago

Actually try not to make this overcomplicated and only supporting unitless value should be good

CatHood0 commented 1 week ago

I know, i think this works better using unitless because is easy to maintain, instead calculating percentage or the length value. I'll do the pr soon