1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Desktop: Fixes #3917: Fixed numbered list bug in markdown editor (#4116)

This commit is contained in:
MichBoi 2020-11-26 09:34:13 -05:00 committed by GitHub
parent 69a4a895d4
commit 6272a2eb4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,5 @@
import markdownUtils from '@joplin/lib/markdownUtils';
// Helper functions that use the cursor
export default function useCursorUtils(CodeMirror: any) {
@ -78,6 +80,8 @@ export default function useCursorUtils(CodeMirror: any) {
for (let i = 0; i < selectedStrings.length; i++) {
const selected = selectedStrings[i];
let num = markdownUtils.olLineNumber(string1);
const lines = selected.split(/\r?\n/);
// Save the newline character to restore it later
const newLines = selected.match(/\r?\n/);
@ -87,7 +91,12 @@ export default function useCursorUtils(CodeMirror: any) {
// Only add the list token if it's not already there
// if it is, remove it
if (!line.startsWith(string1)) {
lines[j] = string1 + line;
if (num) {
lines[j] = `${num.toString()}. ${line}`;
num++;
} else {
lines[j] = string1 + line;
}
} else {
lines[j] = line.substr(string1.length, line.length - string1.length);
}