Skip to content

Commit

Permalink
Improve handling of quotes inside lists (microsoft#1438)
Browse files Browse the repository at this point in the history
* Remove coloring when removing a quote inside a LI

* Prevent list items from being removed before quote
  • Loading branch information
ianeli1 authored Nov 29, 2022
1 parent 3afe4ae commit 82e8883
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ const OutdentWhenBackOn1stEmptyLine: BuildInEditFeature<PluginKeyboardEvent> = {
keys: [Keys.BACKSPACE],
shouldHandleEvent: (event, editor) => {
let li = editor.getElementAtCursor('LI', null /*startFrom*/, event);
return li && isNodeEmpty(li) && !li.previousSibling;
return (
li &&
isNodeEmpty(li) &&
!li.previousSibling &&
!li.getElementsByTagName('blockquote').length
);
},
handleEvent: toggleListAndPreventDefault,
};
Expand Down Expand Up @@ -371,7 +376,9 @@ const isFirstItemOfAList = (item: string) => {
const MaintainListChain: BuildInEditFeature<PluginKeyboardEvent> = {
keys: [Keys.ENTER, Keys.TAB, Keys.DELETE, Keys.BACKSPACE, Keys.RANGE],
shouldHandleEvent: (event, editor) =>
editor.queryElements('li', QueryScope.OnSelection).length > 0,
editor
.queryElements('li', QueryScope.OnSelection)
.filter(li => !li.getElementsByTagName('blockquote').length).length > 0,
handleEvent: (event, editor) => {
const chains = getListChains(editor);
editor.runAsync(editor => commitListChains(editor, chains));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ function splitQuote(event: PluginKeyboardEvent, editor: IEditor) {
}
parent = splitBalancedNodeRange(childOfQuote);
shouldClearFormat = isStyledBlockquote(parent);
unwrap(parent);
const newParent = unwrap(parent);
editor.select(childOfQuote, PositionType.Begin);

if (shouldClearFormat) {
if (safeInstanceOf(newParent, 'HTMLLIElement')) {
newParent.style.removeProperty('color');
}
clearFormat(editor);
}
});
Expand Down

0 comments on commit 82e8883

Please sign in to comment.