1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00

Desktop: Fix getLineSpan logic and list token regex logic (#3365)

- previously getLineSpan was included line text as a token (dumb
oversight)
- the regex was updated to include a space after a OL element (was
missing for some reason)
This commit is contained in:
Caleb John 2020-06-16 06:00:17 -06:00 committed by GitHub
parent 23ae4fb790
commit a4b13be0d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -47,16 +47,16 @@ export default function useListIdent(CodeMirror: any) {
return currentToken;
}
// Gets the first non-whitespace token locationof a list
function getListSpan(listTokens: any) {
// Gets the character coordinates of the start and end of a list token
function getListSpan(listTokens: any, line: string) {
let start = listTokens[0].start;
const end = listTokens[listTokens.length - 1].end;
const token = extractListToken(line);
if (listTokens.length > 1 && listTokens[0].string.match(/\s/)) {
start = listTokens[1].start;
}
return { start: start, end: end };
return { start: start, end: start + token.length };
}
CodeMirror.commands.smartListIndent = function(cm: any) {
@ -74,7 +74,7 @@ export default function useListIdent(CodeMirror: any) {
} else {
if (olLineNumber(line)) {
const tokens = cm.getLineTokens(anchor.line);
const { start, end } = getListSpan(tokens);
const { start, end } = getListSpan(tokens, line);
// Resets numbered list to 1.
cm.replaceRange('1. ', { line: anchor.line, ch: start }, { line: anchor.line, ch: end });
}
@ -99,9 +99,9 @@ export default function useListIdent(CodeMirror: any) {
} else {
const newToken = newListToken(cm, anchor.line);
const tokens = cm.getLineTokens(anchor.line);
const { start, end } = getListSpan(tokens);
const { start, end } = getListSpan(tokens, line);
cm.replaceRange(newToken, { line: anchor.line, ch: start }, { line: anchor.line, ch: end });
cm.replaceRange(newToken, { line: anchor.line, ch: start }, { line: anchor.line, ch: end });
cm.indentLine(anchor.line, 'subtract');
}

View File

@ -5,7 +5,7 @@ const { setupLinkify } = require('lib/joplin-renderer');
const removeMarkdown = require('remove-markdown');
// Taken from codemirror/addon/edit/continuelist.js
const listRegex = /^(\s*)([*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]))(\s*)/;
const listRegex = /^(\s*)([*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]\s))(\s*)/;
const emptyListRegex = /^(\s*)([*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s*)$/;
const markdownUtils = {