proton icon indicating copy to clipboard operation
proton copied to clipboard

Issues with non-zero line spacing

Open Chunngai opened this issue 1 year ago • 0 comments

When testing the feature of background color with rounded corners (as introduced here), I found two issues with a non-zero line spacing, as shown in the attached screenshot.

Screenshot 2024-02-21 at 2 24 21 PM

Issues

  1. Incorrect background location for text on the last line: the background color of the word "to", which is on the last line of the text view, is not correct.
  2. Additional cursor height for text selection: when selecting the word "that" on the first line, the cursor height is greater than the line height (also, the height of the colored background). (When using the vanilla approach to setting background color with [.backgroundColor: myBackgroundColor], the cursor height is equal to line height)

Reproduction

  1. In the setup() method of ExampleApp/ExampleApp/AdvancedFeatures/CommandsExampleViewController, I added typingAttributes as follows:
editor.typingAttributes = [.paragraphStyle:{
    let paraStyle = NSMutableParagraphStyle()
    paraStyle.lineSpacing = 10
    paraStyle.paragraphSpacing = 30
    return paraStyle
}()]
  1. In the execute method of ExampleApp/ExampleApp/Commands/TextBlockCommand.swift, I updated the background style as follows:
let style = BackgroundStyle(
    color: .green,
    roundedCornerStyle: .absolute(value: 5),
    heightMode: .matchText
)
  1. Run the app, type some text in the text view. (Note that I have modified the button stack and only kept the "TextBlock" button)
  2. Select some text on the last line and click "TextBlock" to reproduce the first problem.
  3. Select arbitrary text to reproduce the second problem.

Any ideas to fix it?

The first problem may be cased by the code for .matchText in the drawBackground(forGlyphRange:at:) method of the customized LayoutManager.

Chunngai avatar Feb 21 '24 07:02 Chunngai