diff --git a/crates/wysiwyg/src/dom/parser/markdown/markdown_html_parser.rs b/crates/wysiwyg/src/dom/parser/markdown/markdown_html_parser.rs index f0c8ce23c..2cd46efe7 100644 --- a/crates/wysiwyg/src/dom/parser/markdown/markdown_html_parser.rs +++ b/crates/wysiwyg/src/dom/parser/markdown/markdown_html_parser.rs @@ -28,8 +28,7 @@ impl MarkdownHTMLParser { let mut options = Options::empty(); options.insert(Options::ENABLE_STRIKETHROUGH); - let markdown = markdown.to_string(); - + let markdown = dbg!(markdown.to_string()); let parser = Parser::new_ext(&markdown, options); let mut html = String::new(); @@ -39,14 +38,16 @@ impl MarkdownHTMLParser { // By default, there is a `
…
\n` around the HTML content. That's the // correct way to handle a text block in Markdown. But it breaks our // assumption regarding the HTML markup. So let's remove it. + // write me a function that gives me the number of substrings contained in a string: + let html = { - if !html.starts_with("") { - &html[..] - } else { + if html.starts_with("
") && html.matches("
").count() == 1 { let p = "
".len(); let ppnl = "
\n".len(); &html[p..html.len() - ppnl] + } else { + &html[..] } }; diff --git a/crates/wysiwyg/src/tests/test_set_content.rs b/crates/wysiwyg/src/tests/test_set_content.rs index e38b308e6..889612add 100644 --- a/crates/wysiwyg/src/tests/test_set_content.rs +++ b/crates/wysiwyg/src/tests/test_set_content.rs @@ -194,3 +194,12 @@ fn set_content_from_markdown_codeblock_with_newlines() { .unwrap(); assert_eq!(tx(&model), "I am a code block|
");
}
+
+#[test]
+fn set_content_from_markdown_multiple_new_lines() {
+ let mut model = cm("|");
+ model
+ .set_content_from_markdown(&utf16("test\n\ntest"))
+ .unwrap();
+ assert_eq!(tx(&model), "test
test|
"); +} diff --git a/platforms/ios/example/Wysiwyg/Views/ContentView.swift b/platforms/ios/example/Wysiwyg/Views/ContentView.swift index e09218d52..49c4e5536 100644 --- a/platforms/ios/example/Wysiwyg/Views/ContentView.swift +++ b/platforms/ios/example/Wysiwyg/Views/ContentView.swift @@ -93,10 +93,9 @@ struct ContentView: View { switch keyCommand { case .enter: sentMessage = viewModel.content + viewModel.clearContent() return true - case .shiftEnter: - return false } }, pasteHandler: { _ in }) diff --git a/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerView.swift b/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerView.swift index 1af9090f6..b1e9d48ac 100644 --- a/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerView.swift +++ b/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerView.swift @@ -253,7 +253,7 @@ struct UITextViewWrapper: UIViewRepresentable { private func processDefault(for keyCommand: WysiwygKeyCommand) { switch keyCommand { - case .enter, .shiftEnter: + case .enter: enter() } } diff --git a/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygTextView.swift b/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygTextView.swift index 3c660d890..2f0130123 100644 --- a/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygTextView.swift +++ b/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygTextView.swift @@ -31,7 +31,7 @@ protocol WysiwygTextViewDelegate: AnyObject { /// - textView: Composer text view. /// - keyCommand: Key command received. func textViewDidReceiveKeyCommand(_ textView: UITextView, keyCommand: WysiwygKeyCommand) - + /// Notify the delegate that a paste event has beeb received by the text view. /// /// - Parameters: diff --git a/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygKeyCommand.swift b/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygKeyCommand.swift index 6912cd7d8..302e228f6 100644 --- a/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygKeyCommand.swift +++ b/platforms/ios/lib/WysiwygComposer/Sources/WysiwygComposer/Components/WysiwygKeyCommand.swift @@ -23,12 +23,10 @@ public enum WysiwygKeyCommand: CaseIterable { /// User pressed `enter`. Default behaviour: a line feed is created. /// Note: in the context of a messaging app, this is usually used to send a message. case enter - /// User pressed `shift` + `enter`. Default behaviour: a line feed is created. - case shiftEnter var input: String { switch self { - case .enter, .shiftEnter: + case .enter: return "\r" } } @@ -37,8 +35,6 @@ public enum WysiwygKeyCommand: CaseIterable { switch self { case .enter: return [] - case .shiftEnter: - return .shift } }