Skip to content

Commit

Permalink
Fix edge case when switching to an empty note
Browse files Browse the repository at this point in the history
  • Loading branch information
noatpad committed Oct 14, 2023
1 parent 51554e8 commit 38cee7d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/banner/Banner.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@

<style lang="scss">
// NOTE: This styling rule here may cause side effects to the editing view. Let's hope it doesn't
/* BUG: On mobile, there is a horizontal scrolling issue where a small empty space can be
scrolled on the right. Unsure if this is due to this or the banner's size */
:global(.cm-scroller) { flex-direction: column; }
// Parent banner wrapper styling
Expand Down
9 changes: 8 additions & 1 deletion src/reading/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { BannerProps, Embedded } from 'src/banner';
import { extractBannerData } from 'src/bannerData';
import { plug } from 'src/main';
import { getSetting } from 'src/settings';
import { registerSettingChangeEvent } from 'src/utils';
import { iterateMarkdownLeaves, registerSettingChangeEvent } from 'src/utils';

/* BUG: This doesn't rerender banners in internal embeds properly.
Reload app or manually edit the view/contents to fix */
Expand Down Expand Up @@ -82,4 +82,11 @@ export const registerReadingBannerEvents = () => {
'defaultHeaderValue'
], rerender);
plug.registerEvent(plug.app.vault.on('rename', rerender));

// Edge case when switching from a note with a banner to a banner with no data to postprocess
plug.registerEvent(plug.app.workspace.on('layout-change', () => {
iterateMarkdownLeaves((leaf) => {
if (!leaf.view.file.stat.size) destroyBanner(leaf.view.previewMode.docId);
}, 'reading');
}));
};
2 changes: 2 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ declare module 'obsidian' {
}

interface MarkdownPreviewView {
docId: string;
renderer: PreviewRenderer;
}

Expand All @@ -71,6 +72,7 @@ declare module 'obsidian' {
interface View {
currentMode: EditMode | PreviewMode;
editor: Editor;
file: TFile;
previewMode: MarkdownPreviewView;
}

Expand Down

0 comments on commit 38cee7d

Please sign in to comment.