-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
[FR] Saving Snippets in a Hidden Folder #67
Comments
I think it would be better to store snippets in the vault so I can edit the snippets at any time. but currently if you save the snippets as md files it can lead to confusing formatting. I can add a feature to latex-suite that can open the snippets, I save it as a js file and it has syntax highlighting. Something like this. The code is not much, if @artisticat1 is willing to add it would be better. //register a textFileView
export class SampleView extends TextFileView {
codeMirror: CodeMirror.Editor
constructor(leaf: WorkspaceLeaf, public plugin: SamplePlugin) {
super(leaf)
// @ts-ignore
this.codeMirror = CodeMirror(this.contentEl, {
theme: "javascript",
mode: "javascript",
addModeClass: true,
autofocus: true
})
this.codeMirror.on("changes", () => this.codeMirror.refresh());
}
onResize() {
this.codeMirror.refresh();
}
getViewData(): string {
return this.codeMirror.getValue()
}
setViewData(data: string, clear: boolean): void {
if (clear) {
//@ts-ignore
this.codeMirror.swapDoc(CodeMirror.Doc(data, "javascript"));
} else {
this.codeMirror.setValue(data);
}
// @ts-ignore
if (this.app?.vault?.config?.vimMode) {
this.codeMirror.setOption("keyMap", "vim");
}
// This seems to fix some odd visual bugs:
this.codeMirror.refresh();
// This focuses the editor, which is analogous to the
// default Markdown behavior in Obsidian:
this.codeMirror.focus();
}
clear(): void {
this.codeMirror.setValue("");
this.codeMirror.clearHistory();
}
getViewType() {
return SAMPLE_VIEW_TYPE
}
getDisplayText() {
if (this.file) {
return this.file.basename;
} else {
return "js (No File)";
}
}
public canAcceptExtension(extension: string) {
return extension === "js";
}
} //register in load
this.registerView(
SAMPLE_VIEW_TYPE,
(leaf) => new SampleView(leaf, this)
)
this.registerExtensions(["js"], "sample-view") You can also refer to the code on the github. That's what I'm referring to here, I don't understand part of the logic very well, hope it helps. |
Thanks for the detailed reply @windily-cloud! My |
Obsidian does not appear to emit a
That looks nice! You're welcome to submit a PR if you want. I'd be happy to accept it if the custom view only applies to the snippet file. |
You are right. Plugins like obsidian-vimrc that can read files in a hidden folder need reloading to take effect after editing. |
I submit a PR #69 . Now I can edit and load snippets in real time in obsidian, code highlighting and vim mode are also supported. |
It would be great if the plugin can read a snippets file in a hidden directory like
.config/
The text was updated successfully, but these errors were encountered: