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:
Kevin Ansfield 2018-06-15 14:00:00 +01:00
parent 54c3e1de66
commit ea2a6a09dc

View File

@ -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);