mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
Fixes #4750 by preventing automatic deletion of list elements in certain cases
This commit is contained in:
parent
829a245858
commit
f59e312ee2
@ -886,6 +886,9 @@ packages/lib/locale.js.map
|
|||||||
packages/lib/markdownUtils.d.ts
|
packages/lib/markdownUtils.d.ts
|
||||||
packages/lib/markdownUtils.js
|
packages/lib/markdownUtils.js
|
||||||
packages/lib/markdownUtils.js.map
|
packages/lib/markdownUtils.js.map
|
||||||
|
packages/lib/markdownUtils.test.d.ts
|
||||||
|
packages/lib/markdownUtils.test.js
|
||||||
|
packages/lib/markdownUtils.test.js.map
|
||||||
packages/lib/markupLanguageUtils.d.ts
|
packages/lib/markupLanguageUtils.d.ts
|
||||||
packages/lib/markupLanguageUtils.js
|
packages/lib/markupLanguageUtils.js
|
||||||
packages/lib/markupLanguageUtils.js.map
|
packages/lib/markupLanguageUtils.js.map
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -873,6 +873,9 @@ packages/lib/locale.js.map
|
|||||||
packages/lib/markdownUtils.d.ts
|
packages/lib/markdownUtils.d.ts
|
||||||
packages/lib/markdownUtils.js
|
packages/lib/markdownUtils.js
|
||||||
packages/lib/markdownUtils.js.map
|
packages/lib/markdownUtils.js.map
|
||||||
|
packages/lib/markdownUtils.test.d.ts
|
||||||
|
packages/lib/markdownUtils.test.js
|
||||||
|
packages/lib/markdownUtils.test.js.map
|
||||||
packages/lib/markupLanguageUtils.d.ts
|
packages/lib/markupLanguageUtils.d.ts
|
||||||
packages/lib/markupLanguageUtils.js
|
packages/lib/markupLanguageUtils.js
|
||||||
packages/lib/markupLanguageUtils.js.map
|
packages/lib/markupLanguageUtils.js.map
|
||||||
|
@ -155,14 +155,18 @@ export default function useListIdent(CodeMirror: any) {
|
|||||||
// otherwise fallback on the default codemirror behavior
|
// otherwise fallback on the default codemirror behavior
|
||||||
if (ranges.length === 1) {
|
if (ranges.length === 1) {
|
||||||
const line = cm.getLine(anchor.line);
|
const line = cm.getLine(anchor.line);
|
||||||
|
// if cursor on 0th line set previousLine=''
|
||||||
|
const previousLine = anchor.line ? cm.getLine(anchor.line - 1) : '';
|
||||||
|
|
||||||
if (markdownUtils.isEmptyListItem(line)) {
|
if (markdownUtils.isEmptyListItem(line)) {
|
||||||
const tokens = cm.getLineTokens(anchor.line);
|
const tokens = cm.getLineTokens(anchor.line);
|
||||||
// A empty list item with an indent will have whitespace as the first token
|
// A empty list item with an indent will have whitespace as the first token
|
||||||
if (tokens.length > 1 && tokens[0].string.match(/^\s/)) {
|
if (tokens.length > 1 && tokens[0].string.match(/^\s/)) {
|
||||||
cm.execCommand('smartListUnindent');
|
cm.execCommand('smartListUnindent');
|
||||||
} else {
|
} else if (markdownUtils.isListItem(previousLine)) {
|
||||||
cm.replaceRange('', { line: anchor.line, ch: 0 }, anchor);
|
cm.replaceRange('', { line: anchor.line, ch: 0 }, anchor);
|
||||||
|
} else { // perform normal enter key operation
|
||||||
|
cm.replaceRange('\n', anchor);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
1
packages/lib/.gitignore
vendored
1
packages/lib/.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
plugin_types/
|
plugin_types/
|
||||||
|
markdownUtils.test.js
|
94
packages/lib/markdownUtils.test.ts
Normal file
94
packages/lib/markdownUtils.test.ts
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import markdownUtils from './markdownUtils';
|
||||||
|
|
||||||
|
describe('Should detect list items', () => {
|
||||||
|
test('should detect `- lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('- lorem ipsum')).toBe(true);
|
||||||
|
});
|
||||||
|
test('should detect `+ lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('+ lorem ipsum')).toBe(true);
|
||||||
|
});
|
||||||
|
test('should detect `* lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('* lorem ipsum')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ordered list
|
||||||
|
test('should detect `1. lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('1. lorem ipsum')).toBe(true);
|
||||||
|
});
|
||||||
|
test('should detect `1) lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('1) lorem ipsum')).toBe(true);
|
||||||
|
});
|
||||||
|
// checkbox list
|
||||||
|
test('should detect `+ [x] lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('+ [x] lorem ipsum')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ordered list
|
||||||
|
test('should NOT detect `-lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('-lorem ipsum')).toBe(false);
|
||||||
|
});
|
||||||
|
test('should NOT detect `+lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('+lorem ipsum')).toBe(false);
|
||||||
|
});
|
||||||
|
test('should NOT detect `*lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('*lorem ipsum')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ordered list
|
||||||
|
test('should NOT detect `1.lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('1.lorem ipsum')).toBe(false);
|
||||||
|
});
|
||||||
|
test('should NOT detect `1)lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('1)lorem ipsum')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should NOT detect `+[x]lorem ipsum` as list item ', () => {
|
||||||
|
expect(markdownUtils.isListItem('+[x]lorem ipsum')).toBe(false);
|
||||||
|
});
|
||||||
|
// Empty list detection
|
||||||
|
test('should detect `- ` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('- ')).toBe(true);
|
||||||
|
});
|
||||||
|
test('should detect `+ ` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('+ ')).toBe(true);
|
||||||
|
});
|
||||||
|
test('should detect `* ` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('* ')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ordered list
|
||||||
|
test('should detect `1. ` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('1. ')).toBe(true);
|
||||||
|
});
|
||||||
|
test('should detect `1) ` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('1) ')).toBe(true);
|
||||||
|
});
|
||||||
|
// checkbox list
|
||||||
|
test('should detect `+ [x] ` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('+ [x] ')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// unordered list
|
||||||
|
test('should NOT detect `-` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('-')).toBe(false);
|
||||||
|
});
|
||||||
|
test('should NOT detect `+` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('+')).toBe(false);
|
||||||
|
});
|
||||||
|
test('should NOT detect `*` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('*')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ordered list
|
||||||
|
test('should NOT detect `1.` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('1.')).toBe(false);
|
||||||
|
});
|
||||||
|
test('should NOT detect `1)` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('1)')).toBe(false);
|
||||||
|
});
|
||||||
|
// checbox list
|
||||||
|
test('should NOT detect `+ [x]` as empty list item ', () => {
|
||||||
|
expect(markdownUtils.isEmptyListItem('+ [x]')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -5,7 +5,7 @@ const MarkdownIt = require('markdown-it');
|
|||||||
|
|
||||||
// Taken from codemirror/addon/edit/continuelist.js
|
// Taken from codemirror/addon/edit/continuelist.js
|
||||||
const listRegex = /^(\s*)([*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]\s))(\s*)/;
|
const listRegex = /^(\s*)([*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]\s))(\s*)/;
|
||||||
const emptyListRegex = /^(\s*)([*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s*)$/;
|
const emptyListRegex = /^(\s*)([*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s+)$/;
|
||||||
|
|
||||||
export interface MarkdownTableHeader {
|
export interface MarkdownTableHeader {
|
||||||
name: string;
|
name: string;
|
||||||
|
Loading…
Reference in New Issue
Block a user