Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit 079a07f

Browse files
committed
Fix a bug where an empty text view is considered non-empty.
Creating a multiline message and deleting all of it leaves a single <p> tag in the model which we need to ignore.
1 parent 2bc3735 commit 079a07f

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

crates/wysiwyg/src/composer_model/delete_text.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ where
5252
if s == e {
5353
// We have no selection - check for special list behaviour
5454
// TODO: should probably also get inside here if our selection
55-
// only contains a zero-wdith space.
55+
// only contains a zero-width space.
5656
let range = self.state.dom.find_range(s, e);
5757
self.backspace_single_cursor(range)
5858
} else {

platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerViewModel.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public class WysiwygComposerViewModel: WysiwygComposerViewModelProtocol, Observa
154154
model.delegate = self
155155
// Publish composer empty state.
156156
$attributedContent.sink { [unowned self] content in
157-
isContentEmpty = content.text.length == 0
157+
isContentEmpty = content.text.length == 0 || content.plainText == "\n" // An empty <p> is left when deleting multi-line content.
158158
}
159159
.store(in: &cancellables)
160160

platforms/ios/lib/WysiwygComposer/Tests/WysiwygComposerTests/Components/WysiwygComposerView/WysiwygComposerViewModelTests.swift

+15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ final class WysiwygComposerViewModelTests: XCTestCase {
5656
// Then the content should be empty for the placeholder to be shown.
5757
XCTAssertTrue(viewModel.isContentEmpty)
5858
}
59+
60+
func testIsContentEmptyAfterDeletingMultilineContent() {
61+
// When typing a new line.
62+
_ = viewModel.replaceText(range: .zero, replacementText: "\n")
63+
viewModel.textView.attributedText = NSAttributedString(string: "\n")
64+
viewModel.didUpdateText()
65+
66+
// And then deleting that new line.
67+
_ = viewModel.replaceText(range: .init(location: 0, length: 1), replacementText: "")
68+
viewModel.textView.attributedText = NSAttributedString(string: "")
69+
viewModel.didUpdateText()
70+
71+
// Then the content should be empty for the placeholder to be shown.
72+
XCTAssertTrue(viewModel.isContentEmpty)
73+
}
5974

6075
func testSimpleTextInputIsAccepted() throws {
6176
let shouldChange = viewModel.replaceText(range: .zero,

0 commit comments

Comments
 (0)