Skip to content

Commit

Permalink
Force source mode when applying templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed May 27, 2021
1 parent aebff29 commit 93005bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8980,9 +8980,10 @@ function applyTemplate(view, templatePath) {
? view.app.vault.getAbstractFileByPath(templatePath)
: null;
if (templateFile && templateFile instanceof obsidian.TFile) {
const activeView = view.app.workspace.activeLeaf.view;
// Force the view to source mode, if needed
if (view instanceof obsidian.MarkdownView && view.getMode() !== "source") {
yield view.setState(Object.assign(Object.assign({}, view.getState()), { mode: "source" }), {});
if (activeView instanceof obsidian.MarkdownView && activeView.getMode() !== "source") {
yield activeView.setState(Object.assign(Object.assign({}, activeView.getState()), { mode: "source" }), {});
}
const { templatesEnabled, templaterPlugin, templatesPlugin } = view.plugin.getTemplatePlugins();
const templateContent = yield view.app.vault.read(templateFile);
Expand Down
7 changes: 4 additions & 3 deletions src/components/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ export async function applyTemplate(view: KanbanView, templatePath?: string) {
: null;

if (templateFile && templateFile instanceof TFile) {
const activeView = view.app.workspace.activeLeaf.view
// Force the view to source mode, if needed
if (view instanceof MarkdownView && view.getMode() !== "source") {
await view.setState(
if (activeView instanceof MarkdownView && activeView.getMode() !== "source") {
await activeView.setState(
{
...view.getState(),
...activeView.getState(),
mode: "source",
},
{}
Expand Down

0 comments on commit 93005bb

Please sign in to comment.