Skip to content

Conversation

@mkh-user
Copy link
Member

@mkh-user mkh-user commented Oct 9, 2025

Type of Change

  • New feature

Description

Adds support for Godot nodes to generate previews. These changes include modifications to the EditorAPI, TextForgeMode class, and Preview panel, which collectively bump the TFM API version to 2.1.

Testing

All changes are backwards compatible, and the new functionality has been tested with a newly created SVG mode that will be released soon.

Impact

Nothing

Additional Information

Nothing

Checklist

  • My code adheres to the coding and style guidelines of the project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings
  • Changes were added to CHANGELOG

Summary by CodeRabbit

  • New Features

    • Added support for custom preview formats: previews can now be text (including BBCode) or embedded UI components.
    • Introduced a tabbed preview panel to switch between message, text, and control-based previews.
    • Adjusted preview panel sizing for better responsiveness.
  • Documentation

    • Updated About screen to reflect Mode API v2.1.
    • Changelog updated: “Support custom preview formats.”
  • Refactor

    • Updated preview behavior and scene layout to use tabs and dynamic content mounting.
    • Tweaked popup positioning in the main UI.

@mkh-user mkh-user self-assigned this Oct 9, 2025
@mkh-user mkh-user added this to the Text Forge 0.2 milestone Oct 9, 2025
@mkh-user mkh-user moved this from Needs Review to In Progress in Release: Text Forge 1.0 Oct 9, 2025
@mkh-user mkh-user marked this pull request as ready for review October 9, 2025 13:29
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

Walkthrough

The preview system now supports both text (BBCode string) and node (Control) previews. Signal and virtual method types were widened (String → untyped/Variant). The preview panel was refactored to a tabbed UI to handle both modes. Main scene UI offsets and About version text were updated. Changelog entry added.

Changes

Cohort / File(s) Summary
Preview API expansion
core/autoload/signals.gd, core/classes/text_forge_mode.gd
Widened preview types: signal preview_updated parameter de-typed (was String), TextForgeMode._generate_preview return type changed from String to Variant; docs updated to mention BBCode string or Control.
Preview panel logic and UI refactor
data/panels/preview/panel.gd, data/panels/preview/panel.tscn
Panel now supports dual preview modes. _update_preview accepts generic input and renders text or attaches a Control into a new preview_node container. Added TabContainer-based layout, exported tab/preview_node, removed message label export, updated enablement/signatures and default tab behavior.
Main scene updates
core/main.tscn
Adjusted MarginContainer offsets; updated About label “Mode API version” from v2.0 to v2.1.
Changelog
CHANGELOG.md
Added Unreleased entry: “Support custom preview formats” with PR reference.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Editor as Editor/Mode
  participant Signals as Signals (autoload)
  participant Panel as PreviewPanel (tabbed)

  rect rgba(200,230,255,0.3)
    Note over User,Editor: Edit triggers preview generation
    User->>Editor: Edit text
    Editor->>Editor: _generate_preview(text) -> Variant<br/>(String BBCode or Control)
  end

  rect rgba(220,255,220,0.3)
    Editor->>Signals: emit preview_updated(new)
    Signals-->>Panel: preview_updated(new)
    alt new is String
      Panel->>Panel: Enable text mode<br/>Update RichTextLabel (bbcode)
      Panel->>Panel: Switch TabContainer to Preview tab
    else new is Control
      Panel->>Panel: Enable node mode<br/>Clear and add Control to preview_node
      Panel->>Panel: Switch TabContainer to Node tab
    end
  end

  rect rgba(255,230,200,0.3)
    Note over Panel: Handles enable/disable and default tab selection
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I twitch my ears at tabs anew,
Where text or nodes can strut in view.
A signal hops without a type,
The forge returns a Variant ripe.
v2.1’s carrot shines bright—
I nibble previews, left and right.
Thump-thump! The UI feels just right. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Add custom preview support with nodes” accurately and concisely summarizes the main feature of the changeset by highlighting the addition of node-based preview support, which aligns with the pull request objectives and code modifications.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch custom-preview-support

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83eb2f7 and 879010c.

📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • core/autoload/signals.gd (1 hunks)
  • core/classes/text_forge_mode.gd (1 hunks)
  • core/main.tscn (2 hunks)
  • data/panels/preview/panel.gd (1 hunks)
  • data/panels/preview/panel.tscn (2 hunks)
🔇 Additional comments (10)
CHANGELOG.md (1)

13-13: LGTM!

The changelog entry correctly documents the new feature and follows the established format.

core/main.tscn (2)

271-272: LGTM!

The offset adjustments for the popup panel are appropriate for the UI updates.


362-362: LGTM!

The API version bump to v2.1 correctly reflects the backward-compatible enhancement to the preview system (widening _generate_preview return type from String to Variant).

core/classes/text_forge_mode.gd (1)

98-100: LGTM! Backward-compatible API enhancement.

Widening the return type from String to Variant enables node-based previews while maintaining compatibility with existing modes that return text. The default implementation returning an empty string is handled correctly by the preview panel.

core/autoload/signals.gd (1)

45-46: LGTM! Signal signature appropriately widened.

Removing the type annotation enables the signal to carry either BBCode strings or Control nodes. The updated documentation clearly specifies the two valid types, helping consumers handle both cases correctly.

data/panels/preview/panel.tscn (2)

5-16: LGTM! Node paths correctly updated.

The node paths properly reference the new TabContainer-based structure, enabling the panel logic to switch between message, text preview, and node preview modes.


26-60: LGTM! UI restructuring supports dual-mode previews.

The TabContainer-based layout cleanly separates the three display modes:

  • Tab 0: Message for disabled state
  • Tab 1: RichTextLabel for BBCode text previews
  • Tab 2: ScrollContainer for node-based previews

The _tab_index metadata aligns with the tab switching logic in panel.gd.

data/panels/preview/panel.gd (3)

7-12: LGTM! Export variables properly defined.

The new exports correctly reference the TabContainer and node preview container, enabling the dual-mode preview system.


18-27: LGTM! Robust dual-mode preview handling.

The implementation correctly:

  • Type-checks for both String and Control previews
  • Validates non-empty strings before displaying text previews
  • Properly cleans up existing node children before adding new previews (line 24)
  • Falls back to disabled state for invalid inputs

30-36: LGTM! Tab switching logic is correct.

The method appropriately switches between tabs based on the preview mode:

  • Tab 0: Disabled/message state
  • Tab 1: Text preview mode
  • Tab 2: Node preview mode

The indices align with the _tab_index metadata in the scene file.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@mkh-user mkh-user merged commit 0969940 into Main Oct 9, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Completed in Release: Text Forge 1.0 Oct 9, 2025
@mkh-user mkh-user deleted the custom-preview-support branch October 9, 2025 13:33
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

Walkthrough

Adds support for non-text previews by changing signal and method types, and refactors the preview panel to a tab-based UI that can display either BBCode text or an embedded Control. Updates scene layout and About text to Mode API v2.1, and adds a changelog entry.

Changes

Cohort / File(s) Summary of changes
Changelog
CHANGELOG.md
Added “Support custom preview formats” under Unreleased → Added.
Signals/API surface
core/autoload/signals.gd
signal preview_updated(new: String)signal preview_updated(new); comment clarifies preview can be BBCode String or Control.
Mode API update
core/classes/text_forge_mode.gd
_generate_preview(text: String) -> String_generate_preview(text: String) -> Variant (now may return String or Control).
Preview panel logic (tabs + flexible preview)
data/panels/preview/panel.gd
Replaced message-based toggle with TabContainer navigation. New exported nodes: tab, preview_node. Removed message. _update_preview now accepts String or Control; mounts Control into preview_node. _set_preview_enabled(enabled, as_text) selects tab 0/1/2. Clears old children before mounting.
Preview panel scene structure
data/panels/preview/panel.tscn
Rebuilt to TabContainer with three tabs: Message, Preview (RichTextLabel), and a ScrollContainer with MarginContainer for custom Control. Updated node paths to tab, preview, preview_node. Reduced custom_minimum_size to (200, 0). Added metadata _tab_index and tab properties.
Main scene tweaks
core/main.tscn
Adjusted MarginContainer offsets (right: -2.0→198.0, bottom: -2.0→80.0). Updated About text to “Mode API v2.1”.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant User
  participant Mode as TextForgeMode
  participant Signals as Autoload Signals
  participant Panel as Preview Panel
  participant UI as TabContainer/Preview Area

  User->>Mode: Trigger preview generation
  Mode-->>Mode: _generate_preview(text) -> Variant (String or Control)
  Mode-->>Signals: emit preview_updated(new)

  Signals-->>Panel: preview_updated(new)
  Panel->>Panel: _update_preview(_preview)
  alt _preview is non-empty String
    Panel->>UI: _set_preview_enabled(true, as_text=true)
    Panel->>UI: Set RichTextLabel.bbcode_text
    UI->>UI: Switch to tab: Preview (text)
  else _preview is Control
    Panel->>UI: Clear preview_node children
    Panel->>UI: AddChild(Control) into preview_node
    Panel->>UI: _set_preview_enabled(true, as_text=false)
    UI->>UI: Switch to tab: Custom (control)
  else no preview
    Panel->>UI: _set_preview_enabled(false, as_text=false)
    UI->>UI: Switch to tab: Message
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~55 minutes

Possibly related PRs

Poem

I twitch my ears at tabs so neat,
Text or widgets, what a treat!
A hop to v2.1 we go,
Previews bloom in a tidy show.
I nudge the nodes, clear and new—
Carrots for code, and views that grew. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the primary change of adding support for custom previews including Godot node-based previews, reflecting the main purpose of the pull request without extraneous details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch custom-preview-support

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

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

2 participants