mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-28 10:32:27 +08:00
chore(code): reintroduce placeholder
This commit is contained in:
parent
7cd4bce5b0
commit
d29286f9e3
@ -44,6 +44,7 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
|
|||||||
|
|
||||||
getExtraOpts(): Partial<EditorConfig> {
|
getExtraOpts(): Partial<EditorConfig> {
|
||||||
return {
|
return {
|
||||||
|
placeholder: t("editable_code.placeholder"),
|
||||||
onContentChanged: () => this.spacedUpdate.scheduleUpdate()
|
onContentChanged: () => this.spacedUpdate.scheduleUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,7 +56,6 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
|
|||||||
// gutters: ["CodeMirror-lint-markers"],
|
// gutters: ["CodeMirror-lint-markers"],
|
||||||
// tabindex: 300,
|
// tabindex: 300,
|
||||||
// dragDrop: false, // with true the editor inlines dropped files which is not what we expect
|
// dragDrop: false, // with true the editor inlines dropped files which is not what we expect
|
||||||
// placeholder: t("editable_code.placeholder")
|
|
||||||
// };
|
// };
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { defaultKeymap, indentWithTab } from "@codemirror/commands";
|
import { defaultKeymap, indentWithTab } from "@codemirror/commands";
|
||||||
import { EditorView, keymap, lineNumbers, ViewUpdate, type EditorViewConfig, type KeyBinding } from "@codemirror/view";
|
import { EditorView, keymap, lineNumbers, placeholder, ViewUpdate, type EditorViewConfig, type KeyBinding } from "@codemirror/view";
|
||||||
import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting } from "@codemirror/language";
|
import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting } from "@codemirror/language";
|
||||||
import { Compartment } from "@codemirror/state";
|
import { Compartment } from "@codemirror/state";
|
||||||
import byMimeType from "./syntax_highlighting.js";
|
import byMimeType from "./syntax_highlighting.js";
|
||||||
@ -7,6 +7,7 @@ import byMimeType from "./syntax_highlighting.js";
|
|||||||
type ContentChangedListener = () => void;
|
type ContentChangedListener = () => void;
|
||||||
|
|
||||||
export interface EditorConfig extends EditorViewConfig {
|
export interface EditorConfig extends EditorViewConfig {
|
||||||
|
placeholder?: string;
|
||||||
onContentChanged?: ContentChangedListener;
|
onContentChanged?: ContentChangedListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +32,10 @@ export default class CodeMirror extends EditorView {
|
|||||||
extensions = [...extensions, ...config.extensions];
|
extensions = [...extensions, ...config.extensions];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.placeholder) {
|
||||||
|
extensions.push(placeholder(config.placeholder));
|
||||||
|
}
|
||||||
|
|
||||||
if (config.onContentChanged) {
|
if (config.onContentChanged) {
|
||||||
extensions.push(EditorView.updateListener.of((v) => this.#onDocumentUpdated(v)));
|
extensions.push(EditorView.updateListener.of((v) => this.#onDocumentUpdated(v)));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user