Skip to content

Commit

Permalink
Disabled hyphenation in Editor owing to an issue with LayoutManager.g…
Browse files Browse the repository at this point in the history
…lyphForCharacterRange (#290)
  • Loading branch information
rajdeep authored Mar 1, 2024
1 parent ce17760 commit 36c6475
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Proton/Sources/Swift/Core/RichTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,15 @@ extension RichTextView: NSLayoutManagerDelegate {
func layoutManager(_ layoutManager: NSLayoutManager, didCompleteLayoutFor textContainer: NSTextContainer?, atEnd layoutFinishedFlag: Bool) {
richTextViewDelegate?.richTextView(self, didFinishLayout: layoutFinishedFlag)
}

func layoutManager(_ layoutManager: NSLayoutManager, shouldBreakLineByHyphenatingBeforeCharacterAt charIndex: Int) -> Bool {
// Disable hyphenation for backgroundStyle as otherwise, in some cases, with hyphenations,
// layoutManager.glyphRange(forCharacterRange:) returns range with hyphenation and textstorage has
// corresponding ranges without hyphenation
// This will likely be revised in a future version to enable back hyphenation
return false
}

}

extension RichTextView: TextStorageDelegate {
Expand Down
33 changes: 33 additions & 0 deletions Proton/Tests/Editor/EditorSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,39 @@ class EditorSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
}

func testWrappedBackgroundInNestedEditor() {
let viewController = EditorTestViewController()
let editor = viewController.editor
let config = GridConfiguration(
columnsConfiguration: [
GridColumnConfiguration(width: .fixed(60)),
GridColumnConfiguration(width: .fractional(0.30)),
GridColumnConfiguration(width: .fractional(0.30)),
],
rowsConfiguration: [
GridRowConfiguration(initialHeight: 40),
GridRowConfiguration(initialHeight: 40),
])
let attachment = GridViewAttachment(config: config)

editor.insertAttachment(in: editor.textEndRange, attachment: attachment)

XCTAssertEqual(attachment.view.containerAttachment, attachment)

viewController.render(size: CGSize(width: 300, height: 225))

let backgroundStyle = BackgroundStyle(color: .red,
roundedCornerStyle: .absolute(value: 6),
border: BorderStyle(lineWidth: 1, color: .yellow),
shadow: ShadowStyle(color: .blue, offset: CGSize(width: 2, height: 2), blur: 2),
widthMode: .matchTextExact)

let cell01 = attachment.view.cellAt(rowIndex: 0, columnIndex: 1)
cell01?.editor.attributedText = NSAttributedString(string: "testLongString ThatWrapsToMultiple Lines", attributes: [.backgroundStyle: backgroundStyle, .textBlock: 1])

assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
}

func testEditorWithArabicText() {
let viewController = EditorTestViewController()
let editor = viewController.editor
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 36c6475

Please sign in to comment.