mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
This commit is contained in:
parent
dfe5383d4b
commit
fdbfa78e53
@ -246,7 +246,6 @@ packages/app-desktop/gui/Navigator.js
|
||||
packages/app-desktop/gui/NoteContentPropertiesDialog.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/Toolbar.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/index.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/setupVim.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/types.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useContextMenu.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.test.js
|
||||
@ -573,6 +572,8 @@ packages/editor/CodeMirror/configFromSettings.js
|
||||
packages/editor/CodeMirror/createEditor.test.js
|
||||
packages/editor/CodeMirror/createEditor.js
|
||||
packages/editor/CodeMirror/editorCommands/editorCommands.js
|
||||
packages/editor/CodeMirror/editorCommands/insertLineAfter.test.js
|
||||
packages/editor/CodeMirror/editorCommands/insertLineAfter.js
|
||||
packages/editor/CodeMirror/editorCommands/supportsCommand.js
|
||||
packages/editor/CodeMirror/editorCommands/swapLine.js
|
||||
packages/editor/CodeMirror/getScrollFraction.js
|
||||
@ -597,6 +598,7 @@ packages/editor/CodeMirror/testUtil/forceFullParse.js
|
||||
packages/editor/CodeMirror/testUtil/loadLanguages.js
|
||||
packages/editor/CodeMirror/theme.js
|
||||
packages/editor/CodeMirror/util/isInSyntaxNode.js
|
||||
packages/editor/CodeMirror/util/setupVim.js
|
||||
packages/editor/SelectionFormatting.js
|
||||
packages/editor/events.js
|
||||
packages/editor/types.js
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -226,7 +226,6 @@ packages/app-desktop/gui/Navigator.js
|
||||
packages/app-desktop/gui/NoteContentPropertiesDialog.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/Toolbar.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/index.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/setupVim.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/types.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useContextMenu.js
|
||||
packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useCursorUtils.test.js
|
||||
@ -553,6 +552,8 @@ packages/editor/CodeMirror/configFromSettings.js
|
||||
packages/editor/CodeMirror/createEditor.test.js
|
||||
packages/editor/CodeMirror/createEditor.js
|
||||
packages/editor/CodeMirror/editorCommands/editorCommands.js
|
||||
packages/editor/CodeMirror/editorCommands/insertLineAfter.test.js
|
||||
packages/editor/CodeMirror/editorCommands/insertLineAfter.js
|
||||
packages/editor/CodeMirror/editorCommands/supportsCommand.js
|
||||
packages/editor/CodeMirror/editorCommands/swapLine.js
|
||||
packages/editor/CodeMirror/getScrollFraction.js
|
||||
@ -577,6 +578,7 @@ packages/editor/CodeMirror/testUtil/forceFullParse.js
|
||||
packages/editor/CodeMirror/testUtil/loadLanguages.js
|
||||
packages/editor/CodeMirror/theme.js
|
||||
packages/editor/CodeMirror/util/isInSyntaxNode.js
|
||||
packages/editor/CodeMirror/util/setupVim.js
|
||||
packages/editor/SelectionFormatting.js
|
||||
packages/editor/events.js
|
||||
packages/editor/types.js
|
||||
|
@ -4,7 +4,7 @@ import KeymapService, { KeymapItem } from '@joplin/lib/services/KeymapService';
|
||||
import { EditorCommand } from '../../../utils/types';
|
||||
import shim from '@joplin/lib/shim';
|
||||
import { reg } from '@joplin/lib/registry';
|
||||
import setupVim from './setupVim';
|
||||
import setupVim from '@joplin/editor/CodeMirror/util/setupVim';
|
||||
import { EventName } from '@joplin/lib/eventManager';
|
||||
|
||||
export default function useKeymap(CodeMirror: any) {
|
||||
|
@ -8,7 +8,7 @@ import { PluginStates } from '@joplin/lib/services/plugins/reducer';
|
||||
import { ContentScriptType } from '@joplin/lib/services/plugins/api/types';
|
||||
import shim from '@joplin/lib/shim';
|
||||
import PluginService from '@joplin/lib/services/plugins/PluginService';
|
||||
import setupVim from '../utils/setupVim';
|
||||
import setupVim from '@joplin/editor/CodeMirror/util/setupVim';
|
||||
|
||||
interface Props extends EditorProps {
|
||||
style: React.CSSProperties;
|
||||
|
@ -7,6 +7,7 @@ import editorCommands from '../editorCommands/editorCommands';
|
||||
import { StateEffect } from '@codemirror/state';
|
||||
import { StreamParser } from '@codemirror/language';
|
||||
import Decorator, { LineWidgetOptions } from './Decorator';
|
||||
import insertLineAfter from '../editorCommands/insertLineAfter';
|
||||
const { pregQuote } = require('@joplin/lib/string-utils-common');
|
||||
|
||||
|
||||
@ -354,12 +355,17 @@ export default class CodeMirror5Emulation extends BaseCodeMirror5Emulation {
|
||||
public static commands = (() => {
|
||||
const commands: Record<string, CodeMirror5Command> = {
|
||||
...BaseCodeMirror5Emulation.commands,
|
||||
|
||||
vimInsertListElement: (codeMirror: BaseCodeMirror5Emulation) => {
|
||||
insertLineAfter(codeMirror.cm6);
|
||||
Vim.handleKey(codeMirror, 'i', 'macro');
|
||||
},
|
||||
};
|
||||
|
||||
for (const commandName in editorCommands) {
|
||||
const command = editorCommands[commandName as keyof typeof editorCommands];
|
||||
|
||||
commands[commandName] = (codeMirror: CodeMirror5Emulation) => command(codeMirror.editor);
|
||||
commands[commandName] = (codeMirror: BaseCodeMirror5Emulation) => command(codeMirror.cm6);
|
||||
}
|
||||
|
||||
// as any: Required to properly extend the base class -- without this,
|
||||
|
@ -0,0 +1,20 @@
|
||||
import { EditorSelection } from '@codemirror/state';
|
||||
import createTestEditor from '../testUtil/createTestEditor';
|
||||
import insertLineAfter from './insertLineAfter';
|
||||
|
||||
describe('insertLineAfter', () => {
|
||||
test('should continue lists', async () => {
|
||||
const editor = await createTestEditor(
|
||||
'- This\n- is\n- a test',
|
||||
EditorSelection.cursor(1),
|
||||
['BulletList'],
|
||||
);
|
||||
insertLineAfter(editor);
|
||||
expect(editor.state.doc.toString()).toBe([
|
||||
'- This',
|
||||
'- ',
|
||||
'- is',
|
||||
'- a test',
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
23
packages/editor/CodeMirror/editorCommands/insertLineAfter.ts
Normal file
23
packages/editor/CodeMirror/editorCommands/insertLineAfter.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { insertNewlineAndIndent } from '@codemirror/commands';
|
||||
import { insertNewlineContinueMarkup } from '@codemirror/lang-markdown';
|
||||
import { EditorSelection, SelectionRange } from '@codemirror/state';
|
||||
import { EditorView } from '@codemirror/view';
|
||||
|
||||
const insertLineAfter = (view: EditorView) => {
|
||||
const state = view.state;
|
||||
view.dispatch(state.changeByRange((sel: SelectionRange) => {
|
||||
const line = state.doc.lineAt(sel.anchor);
|
||||
return {
|
||||
range: EditorSelection.cursor(line.to),
|
||||
};
|
||||
}));
|
||||
|
||||
// insertNewlineContinueMarkup does nothing if not in markdown -- we thus
|
||||
// need a fallback case
|
||||
const addedNewLine = insertNewlineContinueMarkup(view);
|
||||
if (!addedNewLine) {
|
||||
insertNewlineAndIndent(view);
|
||||
}
|
||||
};
|
||||
|
||||
export default insertLineAfter;
|
@ -1,4 +1,4 @@
|
||||
import CodeMirrorControl from '@joplin/editor/CodeMirror/CodeMirrorControl';
|
||||
import CodeMirrorControl from '../CodeMirrorControl';
|
||||
|
||||
const setupVim = (CodeMirror: CodeMirrorControl) => {
|
||||
CodeMirror.Vim.defineAction('swapLineDown', CodeMirror.commands.swapLineDown);
|
Loading…
Reference in New Issue
Block a user