From efa26525f0aff4bb1eb735f5dcd6dc1d07f795b1 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Wed, 24 Nov 2021 08:03:35 +0200 Subject: [PATCH] fix(Path View): :bug: Can't get max-width in source mode (fix #163) --- main.js | 7 ++++++- src/main.ts | 16 +++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index f912d38b..c148ff5b 100644 --- a/main.js +++ b/main.js @@ -50214,7 +50214,12 @@ class BCPlugin extends obsidian.Plugin { debugGroupEnd(settings, "debugMode"); return; } - const max_width = getComputedStyle(document.querySelector(".markdown-preview-view.is-readable-line-width .markdown-preview-sizer")).getPropertyValue("max-width"); + const elForMaxWidth = mode === "preview" + ? ".markdown-preview-view.is-readable-line-width .markdown-preview-sizer" + : ""; + const max_width = elForMaxWidth !== "" + ? getComputedStyle(document.querySelector(elForMaxWidth)).getPropertyValue("max-width") + : null; const trailDiv = createDiv({ cls: `BC-trail ${respectReadableLineLength ? "is-readable-line-width markdown-preview-sizer markdown-preview-section" diff --git a/src/main.ts b/src/main.ts index 23d6b04d..6392afcd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1218,11 +1218,17 @@ export default class BCPlugin extends Plugin { return; } - const max_width = getComputedStyle( - document.querySelector( - ".markdown-preview-view.is-readable-line-width .markdown-preview-sizer" - ) - ).getPropertyValue("max-width"); + const elForMaxWidth = + mode === "preview" + ? ".markdown-preview-view.is-readable-line-width .markdown-preview-sizer" + : ""; + + const max_width = + elForMaxWidth !== "" + ? getComputedStyle( + document.querySelector(elForMaxWidth) + ).getPropertyValue("max-width") + : null; const trailDiv = createDiv({ cls: `BC-trail ${