mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 15:12:58 +03:00
✨ Koenig - Toggle list types using MD list syntax
refs https://github.com/TryGhost/Ghost/issues/9623 - toggle the list type (unordered vs ordered) when typing `- `, `* `, `1 `, or `1. ` at the beginning of a list item
This commit is contained in:
parent
54c3e1de66
commit
ea2a6a09dc
@ -8,10 +8,6 @@ export function replaceWithListSection(editor, matches, listTagName) {
|
||||
let {range, range: {head, head: {section}}} = editor;
|
||||
let text = section.textUntil(head);
|
||||
|
||||
if (section.isListItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we don't want to convert to a heading if the user has not just
|
||||
// finished typing the markdown (eg, they've made a previous
|
||||
// heading expansion then Cmd-Z'ed it to get the text back then
|
||||
@ -20,6 +16,35 @@ export function replaceWithListSection(editor, matches, listTagName) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (section.isListItem) {
|
||||
if (section.parent.tagName === listTagName) {
|
||||
return;
|
||||
}
|
||||
|
||||
// toggle all list items to the new list type
|
||||
editor.run((postEditor) => {
|
||||
let listRange = section.parent.toRange();
|
||||
let {post} = editor;
|
||||
|
||||
range = range.extend(-(matches[0].length));
|
||||
postEditor.deleteRange(range);
|
||||
|
||||
let cursorListItem;
|
||||
post.walkMarkerableSections(listRange, (listItem) => {
|
||||
let isCursorListItem = listItem === section;
|
||||
let changedListItem = postEditor.changeSectionTagName(listItem, listTagName);
|
||||
|
||||
if (isCursorListItem) {
|
||||
cursorListItem = changedListItem;
|
||||
}
|
||||
});
|
||||
|
||||
postEditor.setRange(cursorListItem.headPosition().toRange());
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
editor.run((postEditor) => {
|
||||
range = range.extend(-(matches[0].length));
|
||||
let position = postEditor.deleteRange(range);
|
||||
|
Loading…
Reference in New Issue
Block a user