Skip to content

Fix: auto-set padding when background is selected#891

Merged
Brendonovich merged 5 commits intoCapSoftware:mainfrom
Enejivk:fix-editor-padding
Aug 21, 2025
Merged

Fix: auto-set padding when background is selected#891
Brendonovich merged 5 commits intoCapSoftware:mainfrom
Enejivk:fix-editor-padding

Conversation

@Enejivk
Copy link
Contributor

@Enejivk Enejivk commented Aug 15, 2025

Here’s a shorter, more direct version of your PR description:


Summary
Automatically sets padding to 10 when a background (wallpaper, image, color, or gradient) is selected and current padding is 0.

Changes

  • Added ensurePaddingForBackground() to apply default padding if none exists.

  • Called it when:

    • Switching background tabs
    • Selecting a wallpaper
    • (Also applies to uploaded images, colors, and gradients)

Why
Ensures selected backgrounds are always visible, improving UX when padding was previously zero.

Apex_1755260578882.mp4

Summary by CodeRabbit

  • New Features

    • Background padding now auto-initializes to 10 when selecting image, color, gradient, or wallpaper backgrounds, and when applying wallpapers, if padding was previously zero—ensuring consistent spacing and appearance when switching background options.
  • Chores

    • Improved type-checking for preset creation to require expected compiler diagnostics; no runtime or user-facing behavior changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

Walkthrough

Adds a helper to initialize background.padding to 10 when selecting background source tabs or applying a wallpaper. Also replaces a // @ts-ignore with // @ts-expect-error when assigning config.timeline = undefined in preset creation; runtime behavior unchanged.

Changes

Cohort / File(s) Change Summary
Editor background padding initialization
apps/desktop/src/routes/editor/ConfigSidebar.tsx
Added ensurePaddingForBackground and invoked it in the background source tab change handler and after applying a wallpaper (around debouncedSetProject) to set background.padding = 10 when it was previously 0.
TypeScript directive adjustment
apps/desktop/src/utils/createPresets.ts
Replaced // @ts-ignore with // @ts-expect-error on the line assigning config.timeline = undefined; no runtime change, enforces expectation of a compile-time error.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant ConfigSidebar
  participant ensurePad as ensurePaddingForBackground
  participant Debounced as debouncedSetProject
  participant Store as Project Store

  User->>ConfigSidebar: select background tab / choose wallpaper
  ConfigSidebar->>ensurePad: ensurePaddingForBackground(config)
  ensurePad-->>ConfigSidebar: (sets padding=10 if was 0)
  ConfigSidebar->>Debounced: debouncedSetProject(updatedConfig)
  Debounced->>Store: apply updated config
  Store-->>User: updated background applied
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I’m a rabbit in the code, hopping light and quick,
I pad backgrounds to ten with a gentle click.
Wallpapers settle, no more squeeze or din,
And TypeScript winks — “expect the error in.”
Hoppity-hop! The editor’s snug again. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
packages/ui-solid/src/auto-imports.d.ts (1)

9-92: Generated icon globals: formatting-only churn; identifiers unchanged

The set of global icon identifiers and their default-type accessors remain identical; only quotes/semicolons/spacing changed. No semantic impact.

If feasible, align the unplugin-auto-import generator’s quote/semicolon settings to reduce diffs in future runs.

apps/desktop/src/utils/tauri.ts (3)

8-10: Nit: redundant return await in async functions

In cases without a surrounding try/catch, return TAURI_INVOKE(...) is equivalent and avoids an extra await. Not critical, especially in generated code.

If you ever adjust the generator, consider this pattern:

-async setMicInput(label: string | null) : Promise<null> {
-    return await TAURI_INVOKE("set_mic_input", { label });
-},
+async setMicInput(label: string | null) : Promise<null> {
+    return TAURI_INVOKE("set_mic_input", { label });
+},

447-451: Importing Channel as a value is unnecessary here; prefer type-only import

Channel is only used in type position (TAURI_CHANNEL<FramesRendered>). Since invoke already brings in the module as a value, this is minor, but you can avoid extra value imports.

Apply if/when adjusting the generator:

 import {
 	invoke as TAURI_INVOKE,
-	Channel as TAURI_CHANNEL,
+	type Channel as TAURI_CHANNEL,
 } from "@tauri-apps/api/core";

328-330: Heads-up: duplicate Bounds type name in codebase

This file exports Bounds = { x, y, width, height }, while apps/desktop/src/utils/box.ts has Bounds = { size: XY; position: XY } (different shape). Not new, but it’s easy to import the wrong one by name.

Consider:

  • Aliasing on import at call sites (e.g., import type { Bounds as TauriBounds } ...) to avoid confusion, or
  • Renaming one of the types at the source (if feasible via generator settings) to make intent explicit (e.g., WindowBounds vs LogicalBounds).
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 801757a and 7d01753.

📒 Files selected for processing (2)
  • apps/desktop/src/utils/tauri.ts (2 hunks)
  • packages/ui-solid/src/auto-imports.d.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/desktop/src/utils/tauri.ts (2)
apps/desktop/src/utils/box.ts (1)
  • Bounds (6-6)
apps/desktop/src/store/captions.ts (1)
  • CaptionSettings (12-25)
🔇 Additional comments (5)
packages/ui-solid/src/auto-imports.d.ts (1)

7-7: LGTM: harmless formatting tweak on top-level export

Removing the trailing semicolon from export {} in a generated d.ts is non-functional. Safe to keep.

apps/desktop/src/utils/tauri.ts (4)

8-260: Commands block: formatting-only; behavior unchanged

The API surface and invoke payloads are intact. These are generated; no runtime changes detected.


265-307: Events typing: callable object intersection matches the Proxy implementation

The change to a callable intersection shape aligns with the traps provided in __makeEvents__. This improves type fidelity for both events.foo.listen(...) and events.foo(win).listen(...).


475-477: Callable mapping type refinement looks correct

The signature { (handle: __WebviewWindow__): __EventObj__<T[K]>; } accurately captures the callable nature of the event accessors. Good improvement.


328-329: ensurePaddingForBackground is already implemented and invoked

The ensurePaddingForBackground utility is defined and called in ConfigSidebar.tsx, so the padding logic is present as intended:

  • Definition: apps/desktop/src/routes/editor/ConfigSidebar.tsx lines 646–649
  • Invoked in background‐type switch (color/gradient/wallpaper): line 659
  • Invoked after setting a wallpaper path: line 1041

No missing padding logic detected.

createPreset: async (preset: CreatePreset) => {
const config = { ...preset.config };
// @ts-ignore we reeeally don't want the timeline in the preset
// @ts-expect-error we reeeally don't want the timeline in the preset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done by Biome automatically. Although it's outside of the changes on this PR gonna keep it.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
apps/desktop/src/routes/editor/ConfigSidebar.tsx (3)

653-663: Simplify handleBackgroundTabChange (all cases do the same).

Since all four cases invoke ensurePaddingForBackground(), you can collapse the switch and future-proof it against new background types.

Apply:

-// this will run when user select a background tab
-const handleBackgroundTabChange = (tab: BackgroundSource["type"]) => {
-  switch (tab) {
-    case "image":
-    case "color":
-    case "gradient":
-    case "wallpaper":
-      ensurePaddingForBackground();
-      break;
-  }
-};
+// this will run when user selects a background tab
+const handleBackgroundTabChange = (_tab: BackgroundSource["type"]) => {
+  ensurePaddingForBackground();
+};

1041-1042: Avoid a second history entry when selecting wallpapers; make it atomic.

Calling ensurePaddingForBackground() outside debouncedSetProject can create two separate history entries (padding change and wallpaper change). Move the ensure call inside debouncedSetProject’s batched update so the user gets a single undo step.

Apply this removal here:

-  ensurePaddingForBackground();

And update debouncedSetProject (outside this hunk) like this:

// Replace the existing debouncedSetProject with this version
const debouncedSetProject = (wallpaperPath: string) => {
  const resumeHistory = projectHistory.pause();
  queueMicrotask(() => {
    batch(() => {
      setProject("background", "source", {
        type: "wallpaper",
        path: wallpaperPath,
      } as const);
      ensurePaddingForBackground();
      resumeHistory();
    });
  });
};

1148-1192: Image upload flow doesn’t currently trigger padding default; add ensure there.

If the project is already on the “image” tab (no tab change), selecting/uploading an image won’t run handleBackgroundTabChange, so padding may remain 0 (contrary to the PR intent of applying to uploaded images). Call ensurePaddingForBackground() after setting the image source.

Add the call after setProject:

setProject("background", "source", {
  type: "image",
  path: fullPath,
});
ensurePaddingForBackground();

Note: If you also move ensurePaddingForBackground() into debouncedSetProject (as suggested for wallpapers), that won’t affect this code path; you still need the ensure call here.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7d01753 and 106f30e.

📒 Files selected for processing (2)
  • apps/desktop/src/routes/editor/ConfigSidebar.tsx (3 hunks)
  • apps/desktop/src/utils/createPresets.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/desktop/src/routes/editor/ConfigSidebar.tsx (1)
apps/desktop/src/utils/tauri.ts (1)
  • BackgroundSource (397-406)
🔇 Additional comments (3)
apps/desktop/src/utils/createPresets.ts (1)

29-30: Switch to ts-expect-error here is fine and intentional.

Using // @ts-expect-error enforces the presence of the type error and documents intent to strip timeline from presets at runtime. No runtime impact.

apps/desktop/src/routes/editor/ConfigSidebar.tsx (2)

645-651: Padding guard is correct and idempotent.

The minimal guard prevents unnecessary writes and ensures the default is only applied when padding is exactly 0/undefined. Looks good.


803-807: Good: hook the padding initializer at the source-tab switch.

Calling handleBackgroundTabChange before switching source guarantees the default padding is applied on tab change.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
apps/desktop/src/routes/editor/ConfigSidebar.tsx (5)

645-650: Auto-padding helper is good; centralize the default and guard non-positive values.

This looks correct and idempotent. Two small improvements:

  • Replace the magic number 10 with a file-level constant to keep a single source of truth.
  • Guard against any non-positive values (<= 0) to be future-proof.

Apply this diff:

-	// set padding if background is selected
-	const ensurePaddingForBackground = () => {
-		if (project.background.padding === 0)
-			setProject("background", "padding", 10);
-	};
+	// Auto-apply a default padding when a background is selected and padding is zero
+	const DEFAULT_BACKGROUND_PADDING = 10;
+	const ensurePaddingForBackground = () => {
+		if (project.background.padding <= 0) {
+			setProject("background", "padding", DEFAULT_BACKGROUND_PADDING);
+		}
+	};

Follow-up note: If you want this applied universally whenever a wallpaper/image is chosen (even without switching tabs), wire this helper into those onChange handlers too (see comments below).


792-844: Batch ensurePadding + source-type switch to produce a single history entry (and avoid extra renders).

Calling ensurePaddingForBackground outside the switch works, but it will create a separate update from the source-type change. Wrap both in Solid’s batch so they coalesce into one update/history entry.

Apply this diff:

 					onChange={(v) => {
 						const tab = v as BackgroundSource["type"];
-						ensurePaddingForBackground();
-						switch (tab) {
+						batch(() => {
+							ensurePaddingForBackground();
+							switch (tab) {
 							case "image": {
 								setProject("background", "source", {
 									type: "image",
 									path:
 										project.background.source.type === "image"
 											? project.background.source.path
 											: null,
 								});
 								break;
 							}
 							case "color": {
 								setProject("background", "source", {
 									type: "color",
 									value:
 										project.background.source.type === "color"
 											? project.background.source.value
 											: DEFAULT_GRADIENT_FROM,
 								});
 								break;
 							}
 							case "gradient": {
 								setProject("background", "source", {
 									type: "gradient",
 									from:
 										project.background.source.type === "gradient"
 											? project.background.source.from
 											: DEFAULT_GRADIENT_FROM,
 									to:
 										project.background.source.type === "gradient"
 											? project.background.source.to
 											: DEFAULT_GRADIENT_TO,
 									angle:
 										project.background.source.type === "gradient"
 											? project.background.source.angle
 											: 90,
 								});
 								break;
 							}
 							case "wallpaper": {
 								setProject("background", "source", {
 									type: "wallpaper",
 									path:
 										project.background.source.type === "wallpaper"
 											? project.background.source.path
 											: null,
 								});
 								break;
 							}
-						}
+							}
+						});
 					}}

Optional: You may want to skip auto-padding when switching to the Image tab and there is no image selected yet (path is null). If that’s desired, gate ensurePaddingForBackground() behind something like: tab !== "image" || (project.background.source.type === "image" && project.background.source.path). I can draft that if you prefer.


1161-1179: Upload image path should also trigger auto-padding (same rationale as wallpapers).

If the user is already on the Image tab (with padding 0) and uploads a file, we currently don’t auto-apply padding. Call ensurePaddingForBackground() (or batch it) right after setting the image path so uploaded images are covered too.

Proposed change (outside the changed hunk), inside the try block after setProject for the image:

setProject("background", "source", {
  type: "image",
  path: fullPath,
});
ensurePaddingForBackground(); // or batch together with the setProject call

Alternatively, adopt the same batching pattern as with wallpapers:

batch(() => {
  setProject("background", "source", { type: "image", path: fullPath });
  if (project.background.padding <= 0) {
    setProject("background", "padding", DEFAULT_BACKGROUND_PADDING);
  }
});

653-691: onMount wallpaper migration path doesn’t apply auto-padding.

When a persisted wallpaper ID is resolved to a file URL on mount (radioGroupOnChange path), padding isn’t enforced. If you move the auto-padding into debouncedSetProject (as suggested), this path will automatically benefit. Otherwise, add ensurePaddingForBackground() in that flow too.


1018-1032: Wallpaper selection: batch auto-padding with the source update in debouncedSetProject

To avoid a separate history entry—or worse, losing the padding change if history is paused—let’s move ensurePaddingForBackground() inside the same microtask batch where we set the wallpaper. That way both padding and the new source land in one atomic update.

• In apps/desktop/src/routes/editor/ConfigSidebar.tsx around line 1026, remove the standalone call to ensurePaddingForBackground() in the photo‐URL onChange handler:

-    debouncedSetProject(wallpaper.rawPath);
-    ensurePaddingForBackground();
+    debouncedSetProject(wallpaper.rawPath);

• In the debouncedSetProject definition (around line 744), prepend the padding check before setting the source:

const debouncedSetProject = (wallpaperPath: string) => {
  const resumeHistory = projectHistory.pause();
  queueMicrotask(() => {
    batch(() => {
+     if (project.background.padding <= 0) {
+       setProject("background", "padding", DEFAULT_BACKGROUND_PADDING);
+     }
      setProject("background", "source", {
        type: "wallpaper",
        path: wallpaperPath,
      } as const);
      resumeHistory();
    });
  });
};

This ensures the padding and wallpaper-path updates are recorded together.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 106f30e and f9241ce.

📒 Files selected for processing (1)
  • apps/desktop/src/routes/editor/ConfigSidebar.tsx (3 hunks)

@Brendonovich
Copy link
Contributor

Thanks for this!

@Brendonovich Brendonovich merged commit 790711f into CapSoftware:main Aug 21, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants