Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop,Mobile: Add setting to disable markup autocompletion #11222

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ const CodeMirror = (props: NoteBodyEditorProps, ref: ForwardedRef<NoteBodyEditor
monospaceFont: Setting.value('style.editor.monospaceFontFamily'),
},
automatchBraces: Setting.value('editor.autoMatchingBraces'),
autocompleteMarkup: Setting.value('editor.autocompleteMarkup'),
useExternalSearch: false,
ignoreModifiers: true,
spellcheckEnabled: Setting.value('editor.spellcheckBeta'),
Expand Down
1 change: 1 addition & 0 deletions packages/app-mobile/components/NoteEditor/NoteEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ function NoteEditor(props: Props, ref: any) {

automatchBraces: false,
ignoreModifiers: false,
autocompleteMarkup: Setting.value('editor.autocompleteMarkup'),

indentWithTabs: true,
}), [props.themeId, props.readOnly]);
Expand Down
14 changes: 12 additions & 2 deletions packages/editor/CodeMirror/configFromSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ const configFromSettings = (settings: EditorSettings) => {
settings.katexEnabled ? MarkdownMathExtension : [],
],
codeLanguages: lookUpLanguage,

...(settings.autocompleteMarkup ? {
// Most Markup completion is enabled by default
} : {
addKeymap: false,
completeHTMLTags: false,
htmlTagLanguage: html({ matchClosingTags: false, autoCloseTags: false }),
}),
}),
markdownLanguage.data.of({
closeBrackets: openingBrackets,
}),
markdownLanguage.data.of({ closeBrackets: openingBrackets }),
];
} else if (language === EditorLanguageType.Html) {
return html();
return html({ autoCloseTags: settings.autocompleteMarkup });
} else {
const exhaustivenessCheck: never = language;
return exhaustivenessCheck;
Expand Down
20 changes: 18 additions & 2 deletions packages/editor/CodeMirror/createEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { classHighlighter } from '@lezer/highlight';
import {
EditorView, drawSelection, highlightSpecialChars, ViewUpdate, Command, rectangularSelection,
} from '@codemirror/view';
import { history, undoDepth, redoDepth, standardKeymap } from '@codemirror/commands';
import { history, undoDepth, redoDepth, standardKeymap, insertTab } from '@codemirror/commands';

import { keymap, KeyBinding } from '@codemirror/view';
import { searchKeymap } from '@codemirror/search';
Expand All @@ -33,6 +33,16 @@ import biDirectionalTextExtension from './utils/biDirectionalTextExtension';
import searchExtension from './utils/searchExtension';
import isCursorAtBeginning from './utils/isCursorAtBeginning';

// Newer versions of CodeMirror by default use Chrome's EditContext API.
// While this might be stable enough for desktop use, it causes significant
// problems on Android:
// - https://github.com/codemirror/dev/issues/1450
// - https://github.com/codemirror/dev/issues/1451
// For now, CodeMirror allows disabling EditContext to work around these issues:
// https://discuss.codemirror.net/t/experimental-support-for-editcontext/8144/3
type ExtendedEditorView = typeof EditorView & { EDIT_CONTEXT: boolean };
(EditorView as ExtendedEditorView).EDIT_CONTEXT = false;

const createEditor = (
parentElement: HTMLElement, props: EditorProps,
): CodeMirrorControl => {
Expand Down Expand Up @@ -176,7 +186,13 @@ const createEditor = (
notifyLinkEditRequest();
return true;
}),
keyCommand('Tab', insertOrIncreaseIndent, true),
keyCommand('Tab', (view: EditorView) => {
if (settings.autocompleteMarkup) {
return insertOrIncreaseIndent(view);
}
// Use the default indent behavior (which doesn't adjust markup)
return insertTab(view);
}, true),
keyCommand('Shift-Tab', (view) => {
// When at the beginning of the editor, allow shift-tab to act
// normally.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const createEditorSettings = (themeId: number) => {
readOnly: false,
automatchBraces: false,
ignoreModifiers: false,
autocompleteMarkup: true,

keymap: EditorKeymap.Default,
language: EditorLanguageType.Markdown,
Expand Down
22 changes: 11 additions & 11 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
"typescript": "5.4.5"
},
"dependencies": {
"@codemirror/autocomplete": "6.13.0",
"@codemirror/commands": "6.3.3",
"@codemirror/lang-html": "6.4.8",
"@codemirror/lang-markdown": "6.2.4",
"@codemirror/language": "6.10.1",
"@codemirror/autocomplete": "6.18.1",
"@codemirror/commands": "6.7.0",
"@codemirror/lang-html": "6.4.9",
"@codemirror/lang-markdown": "6.3.0",
"@codemirror/language": "6.10.3",
"@codemirror/language-data": "6.3.1",
"@codemirror/legacy-modes": "6.3.3",
"@codemirror/lint": "6.5.0",
"@codemirror/legacy-modes": "6.4.1",
"@codemirror/lint": "6.8.2",
"@codemirror/search": "6.5.6",
"@codemirror/state": "6.4.1",
"@codemirror/view": "6.26.3",
"@lezer/common": "1.2.1",
"@lezer/highlight": "1.2.0",
"@lezer/markdown": "1.2.0",
"@codemirror/view": "6.34.1",
"@lezer/common": "1.2.3",
"@lezer/highlight": "1.2.1",
"@lezer/markdown": "1.3.1",
"@replit/codemirror-vim": "6.2.0"
}
}
1 change: 1 addition & 0 deletions packages/editor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export interface EditorSettings {
useExternalSearch: boolean;

automatchBraces: boolean;
autocompleteMarkup: boolean;

// True if internal command keyboard shortcuts should be ignored (thus
// allowing Joplin shortcuts to run).
Expand Down
12 changes: 12 additions & 0 deletions packages/lib/models/settings/builtInMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,18 @@ const builtInMetadata = (Setting: typeof SettingType) => {
storage: SettingStorage.File,
isGlobal: true,
},
'editor.autocompleteMarkup': {
value: true,
advanced: true,
type: SettingItemType.Bool,
public: true,
section: 'note',
appTypes: [AppType.Desktop, AppType.Mobile],
label: () => _('Autocomplete Markdown and HTML'),
description: () => _('Enables Markdown list continuation, auto-closing HTML tags, and other markup autocompletions.'),
storage: SettingStorage.File,
isGlobal: true,
},
'notes.columns': {
value: defaultListColumns(),
public: false,
Expand Down
Loading
Loading