-
-
Notifications
You must be signed in to change notification settings - Fork 4
View (CodeMirror)
The UNITADE CodeMirror View is a specified view of the UNITADE ecosystem, which is currently stale and presents itself as legacy code from past versions of Obsidian. At that time, it was the instrument to render files as code files with syntax highlighting and a custom leaf view upon files. Currently (starting from "v2.4*" versions of the plugin), its only possible feature is to try to integrate the code view on very old versions of Obsidian or fix issues within phantom views and extensions, meaning "forcing" to view or "not view" files and workspaces.
Important
While this feature is considered "legacy," it is still a significant part of UNITADE's infrastructure and has proven helpful in edge cases. These are a few reasons this functionality still exists.
The CodeMirror view provides a simple interpretation from a code perspective upon its realization; mainly, this is because CodeMirror already implements most of the logic behind the curtains.
Example of Implementation (may differ in source):
import {
TextFileView,
WorkspaceLeaf,
} from "obsidian";
import CodeMirror from '../../../lib/codemirror';
export default class UNITADE_VIEW extends TextFileView {
private _codemirror: CodeMirror.Editor;
private _extension: string = '';
constructor(leaf: WorkspaceLeaf, extension: string) {
super(leaf);
this._extension = extension;
this._codemirror = CodeMirror(this.contentEl, {
theme: 'obsidian',
});
this._codemirror.on('changes', this.onChange);
}
onResize(): void {
this._codemirror.refresh();
}
onChange = async () => {
this.requestSave();
}
getViewData(): string {
return this._codemirror.getValue();
}
setViewData(data: string, clear: boolean): void {
if (clear)
this._codemirror.swapDoc(CodeMirror.Doc(data, text/x-${this._extension}));
else
this._codemirror.setValue(data);
}
clear(): void {
this._codemirror.setValue('');
this._codemirror.clearHistory();
}
getDisplayText(): string {
if (this.file)
return this.file.basename;
else
return 'no file';
}
canAcceptExtension(extension: string): boolean {
return extension === this._extension;
}
getViewType(): string {
return 'mirrorview';
}
}For implementations in different sources, view the corresponding source directories and files.