You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-08-10 22:11:50 +02:00
This commit is contained in:
@@ -68,7 +68,7 @@ describe('markdownCommands.toggleList', () => {
|
|||||||
const checklistEndText = ['- [ ] a', '- [ ] test'].join('\n');
|
const checklistEndText = ['- [ ] a', '- [ ] test'].join('\n');
|
||||||
|
|
||||||
const input = `${checklistStartText}\n\n${checklistEndText}`;
|
const input = `${checklistStartText}\n\n${checklistEndText}`;
|
||||||
const expected = `${checklistStartText}\n\n${checklistEndText}`; // no change
|
const expected = `${checklistStartText}\n- [ ] \n${checklistEndText}`; // new item
|
||||||
|
|
||||||
const editor = await createTestEditor(
|
const editor = await createTestEditor(
|
||||||
input,
|
input,
|
||||||
@@ -466,4 +466,23 @@ A block quote:
|
|||||||
|
|
||||||
expect(editor.state.doc.toString()).toBe(expectedDocText);
|
expect(editor.state.doc.toString()).toBe(expectedDocText);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[ListType.CheckList, '', '- [ ] '],
|
||||||
|
[ListType.OrderedList, '', '1. '],
|
||||||
|
[ListType.UnorderedList, '', '- '],
|
||||||
|
[ListType.UnorderedList, '> ', '> - '],
|
||||||
|
[ListType.UnorderedList, '# Test\n\n', '# Test\n\n- '],
|
||||||
|
])('should add lists when activated on an empty line or empty block quote (list type: %d, initial doc: %j)', async (
|
||||||
|
listType, originalDocument, expected,
|
||||||
|
) => {
|
||||||
|
const editor = await createTestEditor(
|
||||||
|
originalDocument,
|
||||||
|
EditorSelection.cursor(originalDocument.length),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
toggleList(listType)(editor);
|
||||||
|
expect(editor.state.doc.toString()).toBe(expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -213,12 +213,28 @@ export const toggleList = (listType: ListType): Command => {
|
|||||||
return ListAction.SwitchFormatting;
|
return ListAction.SwitchFormatting;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const areAllLinesBlankInRange = (fromLine: Line, toLine: Line) => {
|
||||||
|
for (let lineNumber = fromLine.number; lineNumber <= toLine.number; lineNumber++) {
|
||||||
|
const line = state.doc.line(lineNumber);
|
||||||
|
|
||||||
|
// Consider lines within block quotes with no other content to be blank (this
|
||||||
|
// command should behave similarly regardless of whether in or out of a block
|
||||||
|
// quote).
|
||||||
|
if (stripBlockquote(line).trim() !== '') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
const changes: TransactionSpec = state.changeByRange((sel: SelectionRange) => {
|
const changes: TransactionSpec = state.changeByRange((sel: SelectionRange) => {
|
||||||
const lineRange = getNextLineRange(sel);
|
const lineRange = getNextLineRange(sel);
|
||||||
if (!lineRange) return { range: sel };
|
if (!lineRange) return { range: sel };
|
||||||
const { fromLine, toLine } = lineRange;
|
const { fromLine, toLine } = lineRange;
|
||||||
const baselineIndent = getBaselineIndent(fromLine, toLine);
|
const baselineIndent = getBaselineIndent(fromLine, toLine);
|
||||||
const action = getAction(fromLine, toLine);
|
const action = getAction(fromLine, toLine);
|
||||||
|
const allLinesBlank = areAllLinesBlankInRange(fromLine, toLine);
|
||||||
|
|
||||||
// Outermost list item number
|
// Outermost list item number
|
||||||
let outerCounter = 1;
|
let outerCounter = 1;
|
||||||
@@ -230,8 +246,18 @@ export const toggleList = (listType: ListType): Command => {
|
|||||||
for (let lineNum = fromLine.number; lineNum <= toLine.number; lineNum++) {
|
for (let lineNum = fromLine.number; lineNum <= toLine.number; lineNum++) {
|
||||||
const line = doc.line(lineNum);
|
const line = doc.line(lineNum);
|
||||||
const origLineContent = stripBlockquote(line);
|
const origLineContent = stripBlockquote(line);
|
||||||
if (origLineContent.trim() === '') {
|
const currentLineBlank = origLineContent.trim() === '';
|
||||||
continue; // skip blank lines
|
|
||||||
|
// To support changing the formatting of non-tight lists, skip blank lines within
|
||||||
|
// larger content. This allows changing the list format without adding a potentially
|
||||||
|
// large number of empty list items.
|
||||||
|
//
|
||||||
|
// However, if all lines are blank (e.g. if the cursor at the beginning of an empty)
|
||||||
|
// document, we're not changing the formatting of an existing list. In this case,
|
||||||
|
// skipping blank lines would cause the command to do nothing.
|
||||||
|
// See https://github.com/laurent22/joplin/pull/12745.
|
||||||
|
if (currentLineBlank && !allLinesBlank) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Content excluding the block quote start
|
// Content excluding the block quote start
|
||||||
|
Reference in New Issue
Block a user