Skip to content

Commit

Permalink
Ensure heading levels step up properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed Apr 30, 2021
1 parent d4682ce commit a37293f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
35 changes: 19 additions & 16 deletions src/settingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -645,34 +645,30 @@ 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);

createHeading({
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({
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit a37293f

Please sign in to comment.