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

Commit

Permalink
Fix: crash when entering a new line after setting a blockquote with a…
Browse files Browse the repository at this point in the history
… single line through HTML (#1006)

Co-authored-by: Jorge Martín <jorgem@element.io>
  • Loading branch information
Velin92 and jmartinesp authored Jul 3, 2024
1 parent 0c7461f commit 28aff04
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
3 changes: 2 additions & 1 deletion crates/wysiwyg/src/composer_model/new_lines.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::dom::nodes::dom_node::DomNodeKind;
use crate::dom::nodes::dom_node::DomNodeKind::{
Generic, Link, List, ListItem, Paragraph,
};
Expand Down Expand Up @@ -72,7 +73,7 @@ where

let first_leaf = range.leaves().next();
match block_location.kind {
Paragraph => {
Paragraph | DomNodeKind::Quote => {
let ancestor_block_location =
range.deepest_block_node(Some(&block_handle));
if let Some(ancestor_block_location) = ancestor_block_location {
Expand Down
1 change: 0 additions & 1 deletion crates/wysiwyg/src/dom/dom_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,6 @@ where
else {
return;
};

let all_nodes_are_inline =
container.children().iter().all(|n| !n.is_block_node());
if all_nodes_are_inline {
Expand Down
12 changes: 10 additions & 2 deletions crates/wysiwyg/src/dom/parser/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ mod sys {
child,
last_container_mut_in(node),
);

self.current_path.remove(cur_path_idx);
}
"html" => {
Expand Down Expand Up @@ -396,11 +397,10 @@ mod sys {
use speculoos::{assert_that, AssertionFailure, Spec};
use widestring::Utf16String;

use super::*;
use crate::tests::testutils_composer_model::restore_whitespace;
use crate::{ToHtml, ToTree};

use super::*;

trait Roundtrips<T> {
fn roundtrips(&self);
}
Expand Down Expand Up @@ -796,6 +796,14 @@ mod sys {

#[test]
fn parse_quote() {
assert_that!(
"<p>foo</p><blockquote><p>A quote</p></blockquote><p>bar</p>"
)
.roundtrips();
}

#[test]
fn parse_quote_2() {
assert_that!(
"<p>foo</p><blockquote>A quote</blockquote><p>bar</p>"
)
Expand Down
45 changes: 45 additions & 0 deletions crates/wysiwyg/src/tests/test_paragraphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,51 @@ fn simple_enter_in_quote_adds_new_paragraph() {
);
}

#[test]
fn setting_html_with_line_blockquote_that_contains_a_single_line() {
let mut model = cm("|");
model
.set_content_from_html(&utf16("<blockquote>A</blockquote>"))
.unwrap();
assert_eq!(tx(&model), "<blockquote>A|</blockquote>");
}

#[test]
fn setting_html_with_line_blockquote_that_contains_a_newline() {
let mut model = cm("|");
model
.set_content_from_html(&utf16("<blockquote>A<br>B</blockquote>"))
.unwrap();
assert_eq!(tx(&model), "<blockquote><p>A</p><p>B|</p></blockquote>");
}

#[test]
fn enter_after_setting_html_with_blockquote_with_a_single_line() {
let mut model = cm("|");
model
.set_content_from_html(&utf16("<blockquote>A</blockquote>"))
.unwrap();
model.enter();
assert_eq!(
tx(&model),
"<blockquote><p>A</p><p>&nbsp;|</p></blockquote>"
);
}

#[test]
fn enter_after_setting_html_with_blockquote_containing_formatting() {
let mut model = cm("|");
model
.set_content_from_html(&utf16("<blockquote>A<b>test</b></blockquote>"))
.unwrap();
assert_eq!(tx(&model), "<blockquote>A<b>test|</b></blockquote>");
model.enter();
assert_eq!(
tx(&model),
"<blockquote><p>A<b>test</b></p><p><b>|</b></p></blockquote>"
);
}

#[test]
fn double_enter_in_quote_exits_the_quote() {
let mut model =
Expand Down

0 comments on commit 28aff04

Please sign in to comment.