Skip to content

Commit b43f995

Browse files
committed
Fix list stacking
1 parent 69a4889 commit b43f995

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/index.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -667,21 +667,29 @@ function listStyle(textarea: HTMLTextAreaElement, style: StyleArgs): SelectionRa
667667

668668
let selectedText = textarea.value.slice(textarea.selectionStart, textarea.selectionEnd)
669669

670-
const undoOrderedListResult = undoOrderedListStyle(selectedText)
671-
const undoUnorderedListResult = undoUnorderedListStyle(undoOrderedListResult.text)
670+
// If the user intent was to do an undo, we will stop after this.
671+
// Otherwise, we will still undo to other list type to prevent list stacking
672+
let undoResult: UndoResult
673+
if (style.orderedList) {
674+
undoResult = undoOrderedListStyle(selectedText)
675+
selectedText = undoUnorderedListStyle(undoResult.text).text
676+
} else {
677+
undoResult = undoUnorderedListStyle(selectedText)
678+
selectedText = undoOrderedListStyle(undoResult.text).text
679+
}
672680

673-
if (undoOrderedListResult.processed || undoUnorderedListResult.processed) {
674-
// if (noInitialSelection) {
675-
// selectionStart = Math.max(selectionStart - prefix.length, 0)
676-
// selectionEnd = selectionStart
677-
// } else {
678-
// selectionStart = Math.max(selectionStart - prefix.length, 0)
679-
// selectionEnd = selectionEnd + prefix.length // * lines.length
680-
// }
681-
return {text: undoUnorderedListResult.text, selectionStart, selectionEnd}
681+
if (undoResult.processed) {
682+
// // if (noInitialSelection) {
683+
// // selectionStart = Math.max(selectionStart - prefix.length, 0)
684+
// // selectionEnd = selectionStart
685+
// // } else {
686+
// // selectionStart = Math.max(selectionStart - prefix.length, 0)
687+
// // selectionEnd = selectionEnd + prefix.length // * lines.length
688+
// // }
689+
return {text: undoResult.text, selectionStart, selectionEnd}
682690
}
683691

684-
selectedText = undoUnorderedListResult.text
692+
// selectedText = undoResult.text
685693

686694
const lines = selectedText.split('\n').map((value, index) => {
687695
return `${prefix(index)}${value}`

0 commit comments

Comments
 (0)