mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-24 08:12:24 +02:00
This commit is contained in:
parent
a0ead2c48e
commit
b1ecb75e1f
@ -382,6 +382,9 @@ packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/types.js.map
|
|||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.d.ts
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.d.ts
|
||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.js
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.js
|
||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.js.map
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.js.map
|
||||||
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.test.d.ts
|
||||||
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.test.js
|
||||||
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.test.js.map
|
||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.d.ts
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.d.ts
|
||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.js
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.js
|
||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.js.map
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.js.map
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -369,6 +369,9 @@ packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/types.js.map
|
|||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.d.ts
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.d.ts
|
||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.js
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.js
|
||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.js.map
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.js.map
|
||||||
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.test.d.ts
|
||||||
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.test.js
|
||||||
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.test.js.map
|
||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.d.ts
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.d.ts
|
||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.js
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.js
|
||||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.js.map
|
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.js.map
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
import { modifyListLines } from './useCursorUtils';
|
||||||
|
|
||||||
|
describe('useCursorUtils', () => {
|
||||||
|
|
||||||
|
let listWithDashes = `- item1
|
||||||
|
- item2
|
||||||
|
- item3`;
|
||||||
|
|
||||||
|
let listNoDashes = `item1
|
||||||
|
item2
|
||||||
|
item3`;
|
||||||
|
|
||||||
|
test('should remove "- " from beggining of each line of input string', () => {
|
||||||
|
expect(JSON.stringify(modifyListLines(listWithDashes.split('\n'), 0, '- '))).toBe(JSON.stringify(listNoDashes.split('\n')));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should add "- " at the beggining of each line of the input string', () => {
|
||||||
|
expect(JSON.stringify(modifyListLines(listNoDashes.split('\n'), 0, '- '))).toBe(JSON.stringify(listWithDashes.split('\n')));
|
||||||
|
});
|
||||||
|
});
|
@ -1,6 +1,24 @@
|
|||||||
import markdownUtils from '@joplin/lib/markdownUtils';
|
import markdownUtils from '@joplin/lib/markdownUtils';
|
||||||
import Setting from '@joplin/lib/models/Setting';
|
import Setting from '@joplin/lib/models/Setting';
|
||||||
|
export function modifyListLines(lines: string[],num: number,listSymbol: string) {
|
||||||
|
for (let j = 0; j < lines.length; j++) {
|
||||||
|
const line = lines[j];
|
||||||
|
if (!line && j === lines.length - 1) continue;
|
||||||
|
// Only add the list token if it's not already there
|
||||||
|
// if it is, remove it
|
||||||
|
if (!line.startsWith(listSymbol)) {
|
||||||
|
if (num) {
|
||||||
|
lines[j] = `${num.toString()}. ${line}`;
|
||||||
|
num++;
|
||||||
|
} else {
|
||||||
|
lines[j] = listSymbol + line;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lines[j] = line.substr(listSymbol.length, line.length - listSymbol.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
// Helper functions that use the cursor
|
// Helper functions that use the cursor
|
||||||
export default function useCursorUtils(CodeMirror: any) {
|
export default function useCursorUtils(CodeMirror: any) {
|
||||||
|
|
||||||
@ -81,28 +99,12 @@ export default function useCursorUtils(CodeMirror: any) {
|
|||||||
for (let i = 0; i < selectedStrings.length; i++) {
|
for (let i = 0; i < selectedStrings.length; i++) {
|
||||||
const selected = selectedStrings[i];
|
const selected = selectedStrings[i];
|
||||||
|
|
||||||
let num = markdownUtils.olLineNumber(string1);
|
const num = markdownUtils.olLineNumber(string1);
|
||||||
|
|
||||||
const lines = selected.split(/\r?\n/);
|
const lines = selected.split(/\r?\n/);
|
||||||
// Save the newline character to restore it later
|
// Save the newline character to restore it later
|
||||||
const newLines = selected.match(/\r?\n/);
|
const newLines = selected.match(/\r?\n/);
|
||||||
|
modifyListLines(lines,num,string1);
|
||||||
for (let j = 0; j < lines.length; j++) {
|
|
||||||
const line = lines[j];
|
|
||||||
// Only add the list token if it's not already there
|
|
||||||
// if it is, remove it
|
|
||||||
if (!line.startsWith(string1)) {
|
|
||||||
if (num) {
|
|
||||||
lines[j] = `${num.toString()}. ${line}`;
|
|
||||||
num++;
|
|
||||||
} else {
|
|
||||||
lines[j] = string1 + line;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
lines[j] = line.substr(string1.length, line.length - string1.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const newLine = newLines !== null ? newLines[0] : '\n';
|
const newLine = newLines !== null ? newLines[0] : '\n';
|
||||||
selectedStrings[i] = lines.join(newLine);
|
selectedStrings[i] = lines.join(newLine);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user