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:
parent
23ae4fb790
commit
a4b13be0d1
@ -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');
|
||||
}
|
||||
|
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user