Skip to content

Commit 36c6475

Browse files
authored
Disabled hyphenation in Editor owing to an issue with LayoutManager.glyphForCharacterRange (#290)
1 parent ce17760 commit 36c6475

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Diff for: Proton/Sources/Swift/Core/RichTextView.swift

+9
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,15 @@ extension RichTextView: NSLayoutManagerDelegate {
795795
func layoutManager(_ layoutManager: NSLayoutManager, didCompleteLayoutFor textContainer: NSTextContainer?, atEnd layoutFinishedFlag: Bool) {
796796
richTextViewDelegate?.richTextView(self, didFinishLayout: layoutFinishedFlag)
797797
}
798+
799+
func layoutManager(_ layoutManager: NSLayoutManager, shouldBreakLineByHyphenatingBeforeCharacterAt charIndex: Int) -> Bool {
800+
// Disable hyphenation for backgroundStyle as otherwise, in some cases, with hyphenations,
801+
// layoutManager.glyphRange(forCharacterRange:) returns range with hyphenation and textstorage has
802+
// corresponding ranges without hyphenation
803+
// This will likely be revised in a future version to enable back hyphenation
804+
return false
805+
}
806+
798807
}
799808

800809
extension RichTextView: TextStorageDelegate {

Diff for: Proton/Tests/Editor/EditorSnapshotTests.swift

+33
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,39 @@ class EditorSnapshotTests: SnapshotTestCase {
11611161
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
11621162
}
11631163

1164+
func testWrappedBackgroundInNestedEditor() {
1165+
let viewController = EditorTestViewController()
1166+
let editor = viewController.editor
1167+
let config = GridConfiguration(
1168+
columnsConfiguration: [
1169+
GridColumnConfiguration(width: .fixed(60)),
1170+
GridColumnConfiguration(width: .fractional(0.30)),
1171+
GridColumnConfiguration(width: .fractional(0.30)),
1172+
],
1173+
rowsConfiguration: [
1174+
GridRowConfiguration(initialHeight: 40),
1175+
GridRowConfiguration(initialHeight: 40),
1176+
])
1177+
let attachment = GridViewAttachment(config: config)
1178+
1179+
editor.insertAttachment(in: editor.textEndRange, attachment: attachment)
1180+
1181+
XCTAssertEqual(attachment.view.containerAttachment, attachment)
1182+
1183+
viewController.render(size: CGSize(width: 300, height: 225))
1184+
1185+
let backgroundStyle = BackgroundStyle(color: .red,
1186+
roundedCornerStyle: .absolute(value: 6),
1187+
border: BorderStyle(lineWidth: 1, color: .yellow),
1188+
shadow: ShadowStyle(color: .blue, offset: CGSize(width: 2, height: 2), blur: 2),
1189+
widthMode: .matchTextExact)
1190+
1191+
let cell01 = attachment.view.cellAt(rowIndex: 0, columnIndex: 1)
1192+
cell01?.editor.attributedText = NSAttributedString(string: "testLongString ThatWrapsToMultiple Lines", attributes: [.backgroundStyle: backgroundStyle, .textBlock: 1])
1193+
1194+
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
1195+
}
1196+
11641197
func testEditorWithArabicText() {
11651198
let viewController = EditorTestViewController()
11661199
let editor = viewController.editor
Loading

0 commit comments

Comments
 (0)