Skip to content

Commit

Permalink
correct formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
blacksmithgu committed Oct 7, 2023
1 parent f1d234c commit 7640f73
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
27 changes: 20 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { App, Component, debounce, MarkdownPostProcessorContext, MarkdownView, Plugin, PluginSettingTab, Setting } from "obsidian";
import {
App,
Component,
debounce,
MarkdownPostProcessorContext,
MarkdownView,
Plugin,
PluginSettingTab,
Setting,
} from "obsidian";
import { renderErrorPre } from "ui/render";
import { FullIndex } from "data-index/index";
import { parseField } from "expression/parse";
Expand All @@ -11,7 +20,11 @@ import { currentLocale } from "util/locale";
import { DateTime } from "luxon";
import { DataviewInlineApi } from "api/inline-api";
import { replaceInlineFields } from "ui/views/inline-field";
import { inlineFieldsField, replaceInlineFieldsInLivePreview, workspaceLayoutChangeEffect } from "./ui/views/inline-field-live-preview";
import {
inlineFieldsField,
replaceInlineFieldsInLivePreview,
workspaceLayoutChangeEffect,
} from "./ui/views/inline-field-live-preview";
import { DataviewInit } from "ui/markdown";
import { inlinePlugin } from "./ui/lp-render";
import { Extension } from "@codemirror/state";
Expand Down Expand Up @@ -124,15 +137,15 @@ export default class DataviewPlugin extends Plugin {
// Mainly intended to detect when the user switches between live preview and source mode.
this.registerEvent(
this.app.workspace.on("layout-change", () => {
this.app.workspace.iterateAllLeaves((leaf) => {
this.app.workspace.iterateAllLeaves(leaf => {
if (leaf.view instanceof MarkdownView && leaf.view.editor.cm) {
leaf.view.editor.cm.dispatch({
effects: workspaceLayoutChangeEffect.of(null)
})
effects: workspaceLayoutChangeEffect.of(null),
});
}
})
});
})
)
);
this.registerEditorExtension(inlineFieldsField);
this.registerEditorExtension(replaceInlineFieldsInLivePreview(this.app, this.settings));
}
Expand Down
6 changes: 3 additions & 3 deletions src/typings/obsidian-ex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ declare module "obsidian" {

interface Editor {
/**
* CodeMirror editor instance
*/
cm?: EditorView;
* CodeMirror editor instance
*/
cm?: EditorView;
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/ui/views/inline-field-live-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ export const replaceInlineFieldsInLivePreview = (app: App, settings: DataviewSet

this.overlappingIndices = newIndices;

const layoutChanged = update.transactions.some(
transaction => transaction.effects.some(
effect => effect.is(workspaceLayoutChangeEffect)
)
const layoutChanged = update.transactions.some(transaction =>
transaction.effects.some(effect => effect.is(workspaceLayoutChangeEffect))
);

if (update.state.field(editorLivePreviewField)) {
if (update.docChanged || update.viewportChanged || layoutChanged || overlapChanged) {
this.decorations = this.buildDecoration(update.view);
}
}
} else {
this.decorations = Decoration.none;
}
Expand Down Expand Up @@ -179,7 +177,7 @@ class InlineFieldWidget extends WidgetType {
});
renderValue(
parseInlineValue(this.field.value),
value,
value,
this.sourcePath,
this.parentComponent,
this.settings,
Expand All @@ -192,7 +190,7 @@ class InlineFieldWidget extends WidgetType {
});
renderValue(
parseInlineValue(this.field.value),
value,
value,
this.sourcePath,
this.parentComponent,
this.settings,
Expand Down Expand Up @@ -226,7 +224,7 @@ export async function renderMarkdown(
return null;
}

/**
/**
* A state effect that represents the workspace's layout change.
* Mainly intended to detect when the user switches between live preview and source mode.
*/
Expand Down

0 comments on commit 7640f73

Please sign in to comment.