diff --git a/ghost/admin/lib/koenig-editor/addon/options/text-expansions.js b/ghost/admin/lib/koenig-editor/addon/options/text-expansions.js index a6bbc9e8f1..e457a5803c 100644 --- a/ghost/admin/lib/koenig-editor/addon/options/text-expansions.js +++ b/ghost/admin/lib/koenig-editor/addon/options/text-expansions.js @@ -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);