mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05: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
1 changed files with 29 additions and 4 deletions
|
@ -8,10 +8,6 @@ export function replaceWithListSection(editor, matches, listTagName) {
|
||||||
let {range, range: {head, head: {section}}} = editor;
|
let {range, range: {head, head: {section}}} = editor;
|
||||||
let text = section.textUntil(head);
|
let text = section.textUntil(head);
|
||||||
|
|
||||||
if (section.isListItem) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// we don't want to convert to a heading if the user has not just
|
// 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
|
// finished typing the markdown (eg, they've made a previous
|
||||||
// heading expansion then Cmd-Z'ed it to get the text back then
|
// heading expansion then Cmd-Z'ed it to get the text back then
|
||||||
|
@ -20,6 +16,35 @@ export function replaceWithListSection(editor, matches, listTagName) {
|
||||||
return;
|
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) => {
|
editor.run((postEditor) => {
|
||||||
range = range.extend(-(matches[0].length));
|
range = range.extend(-(matches[0].length));
|
||||||
let position = postEditor.deleteRange(range);
|
let position = postEditor.deleteRange(range);
|
||||||
|
|
Loading…
Add table
Reference in a new issue