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

Commit

Permalink
Fix link splitting in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
artcodespace authored Jun 28, 2023
1 parent 10e5ed8 commit 4b9c2e1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/wysiwyg/src/composer_model/new_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ where
first_leaf.start_offset,
block_location.node_handle.depth(),
);
pre_process_sub_tree(&mut sub_tree);
let children = sub_tree.document_mut().remove_children();
self.state.dom.insert_at(
&block_location.node_handle.next_sibling(),
Expand Down
58 changes: 58 additions & 0 deletions crates/wysiwyg/src/tests/test_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,3 +885,61 @@ fn set_link_with_text_and_custom_attributes() {
"<a customattribute=\"customvalue\" href=\"https://matrix.org\">link|</a>"
)
}

#[test]
fn set_link_in_list_then_exit_list() {
// start with empty model
let mut model = cm("|");

// start a list, add a link
model.unordered_list();
model.set_link_with_text(
"https://matrix.org".into(),
"test".into(),
vec![],
);

assert_eq!(
tx(&model),
"<ul><li><a href=\"https://matrix.org\">test|</a></li></ul>"
);

// exit the list by pressing enter twice
model.enter();
model.enter();

// check that the list has ended, a new paragraph has been started, and the link has not been split
// into two parts
assert_eq!(
tx(&model),
"<ul><li><a href=\"https://matrix.org\">test</a></li></ul><p>&nbsp;|</p>"
);
}

#[test]
fn set_links_in_list_then_add_list_item() {
// start with empty model
let mut model = cm("|");

// start a list, add a link
model.unordered_list();
model.set_link_with_text(
"https://matrix.org".into(),
"test".into(),
vec![],
);

assert_eq!(
tx(&model),
"<ul><li><a href=\"https://matrix.org\">test|</a></li></ul>"
);

// press enter once to add a new list item
model.enter();

// check that the link has not been split into two, with one part empty
assert_eq!(
tx(&model),
"<ul><li><a href=\"https://matrix.org\">test</a></li><li>|</li></ul>"
);
}

0 comments on commit 4b9c2e1

Please sign in to comment.