에디터 ν™•μž₯ κΈ°λŠ₯을 λ§Œλ“€μ—ˆλ‹€λ©΄, 에디터 μ™ΈλΆ€(예: λͺ…λ Ήμ΄λ‚˜ 리본 μ•‘μ…˜μ„ 톡해)와 ν†΅μ‹ ν•˜κ³  싢을 수 μžˆμŠ΅λ‹ˆλ‹€.

MarkdownViewμ—μ„œ CodeMirror 6 에디터에 μ ‘κ·Όν•  수 μžˆμŠ΅λ‹ˆλ‹€. ν•˜μ§€λ§Œ Obsidian APIκ°€ μ‹€μ œλ‘œ 에디터λ₯Ό λ…ΈμΆœν•˜μ§€ μ•ŠκΈ° λ•Œλ¬Έμ— TypeScriptμ—κ²Œ 그것이 μ‘΄μž¬ν•œλ‹€κ³  믿도둝 @ts-expect-errorλ₯Ό μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.

import { EditorView } from '@codemirror/view';
 
// @ts-expect-error, νƒ€μž…μ΄ μ •μ˜λ˜μ§€ μ•ŠμŒ
const editorView = view.editor.cm as EditorView;

λ·° ν”ŒλŸ¬κ·ΈμΈ

EditorView.plugin() λ©”μ„œλ“œλ₯Ό 톡해 λ·° ν”ŒλŸ¬κ·ΈμΈ μΈμŠ€ν„΄μŠ€μ— μ ‘κ·Όν•  수 μžˆμŠ΅λ‹ˆλ‹€.

this.addCommand({
	id: 'example-editor-command',
	name: '에디터 λͺ…λ Ή 예제',
	editorCallback: (editor, view) => {
		// @ts-expect-error, νƒ€μž…μ΄ μ •μ˜λ˜μ§€ μ•ŠμŒ
		const editorView = view.editor.cm as EditorView;
 
		const plugin = editorView.plugin(examplePlugin);
 
		if (plugin) {
			plugin.addPointerToSelection(editorView);
		}
	},
});

μƒνƒœ ν•„λ“œ

에디터 λ·°μ—μ„œ 직접 λ³€κ²½ 사항을 μ „λ‹¬ν•˜κ³  μƒνƒœ 효과λ₯Ό 전달할 수 μžˆμŠ΅λ‹ˆλ‹€.

this.addCommand({
	id: 'example-editor-command',
	name: '에디터 λͺ…λ Ή 예제',
	editorCallback: (editor, view) => {
		// @ts-expect-error, νƒ€μž…μ΄ μ •μ˜λ˜μ§€ μ•ŠμŒ
		const editorView = view.editor.cm as EditorView;
 
		editorView.dispatch({
			effects: [
				// ...
			],
		});
	},
});