From a37293f937d5b55d1921a5419b0df8552f548210 Mon Sep 17 00:00:00 2001 From: mgmeyers Date: Fri, 30 Apr 2021 11:37:53 -0700 Subject: [PATCH] Ensure heading levels step up properly --- manifest.json | 2 +- src/settingHandlers.ts | 35 +++++++++++++++++++---------------- versions.json | 1 + 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/manifest.json b/manifest.json index eefbfad..098ab2d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-style-settings", "name": "Style Settings", - "version": "0.2.3", + "version": "0.2.4", "minAppVersion": "0.11.5", "description": "Offers controls for adjusting theme, plugin, and snippet CSS variables.", "author": "mgmeyers", diff --git a/src/settingHandlers.ts b/src/settingHandlers.ts index b54ac2c..d04f806 100644 --- a/src/settingHandlers.ts +++ b/src/settingHandlers.ts @@ -88,7 +88,7 @@ export function createHeading(opts: { if (opts.config.resetFn) { setting.addExtraButton((b) => { b.setIcon("reset") - .setTooltip('Reset all settings to default') + .setTooltip("Reset all settings to default") .onClick(opts.config.resetFn); }); } @@ -645,18 +645,13 @@ export function createSettings(opts: { let targetContainer = getTargetContainer(containerStack); if (config.level > containerLevel) { + // Nest one level createHeading({ config, containerEl: targetContainer, }); - - targetContainer.createDiv( - { cls: "style-settings-container" }, - (container) => { - containerStack.push(container); - } - ); } else if (config.level === containerLevel) { + // Same level containerStack.pop(); targetContainer = getTargetContainer(containerStack); @@ -664,15 +659,16 @@ export function createSettings(opts: { config, containerEl: targetContainer, }); - - targetContainer.createDiv( - { cls: "style-settings-container" }, - (container) => { - containerStack.push(container); - } - ); } else { - containerStack.pop(); + // Step up to the appropriate level + while ( + containerStack.length > 1 && + parseInt(containerStack[containerStack.length - 1].dataset.level) > + config.level + ) { + containerStack.pop(); + } + targetContainer = getTargetContainer(containerStack); createHeading({ @@ -681,6 +677,13 @@ export function createSettings(opts: { }); } + targetContainer.createDiv( + { cls: "style-settings-container" }, + (container) => { + container.dataset.level = config.level.toString(); + containerStack.push(container); + } + ); containerLevel = config.level; break; diff --git a/versions.json b/versions.json index 10d1898..e08c52d 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { + "0.2.4": "0.11.5", "0.2.3": "0.11.5", "0.2.2": "0.11.5", "0.2.1": "0.11.5",