Skip to content

Conversation

mkh-user
Copy link
Member

@mkh-user mkh-user commented Jul 28, 2025

Type of Change

  • New feature
  • Bug fix
  • Documentation update
  • Refactoring
  • UI/UX improvement

Description

This update introduces a comprehensive and foundational refactor of the EditorAPI and related modules, with a particular focus on mode logic and structure. The previous system for handling modes was limited in flexibility, lacked modularity, and suffered from performance inefficiencies. This refactor replaces the old architecture with a cleaner, more extensible system that enables new features and better performance.

Action Scripts

  • Customizable state checks for action scripts
    • Updated Auto Format to support modes lacking this feature
  • New Auto Indent action script (similar to Auto Format)
  • New Completion Query action script with shortcut support

Global

  • Added damage_modes variable to track broken or incompatible modes
  • Added temprory_children variable to manage node catching
  • FileDatabase: introduced TEMPLATE_MODE_INFO, TEMPLATE_MODE_SCRIPT, and TEMPLATE_MODE_ICON
  • SignalBus:
    • Removed: mode_selected, caret_selected
    • Added: preview_unavailable, preview_updated, mode_changed

Modes

  • Introduced TextForgeMode base class for all modes
  • New syntax highlighter system integrated into modes
  • Support for comment and string delimiters per mode
  • Optional mode-specific panel (Mode Panel) for customization
  • Auto Format and Auto Indent features now mode-driven
  • New mode initialization lifecycle with error handling
  • Decoupled Auto Format and Auto Indent logic
  • New save/load system for modes without direct file access
  • Code completion system based on mode capabilities
  • Preview rendering system for mode-based content
  • Mode-based outline generation
  • Mode-based linting

Panels

  • Added TextForgePanel base class for editor panels
  • New remove_panel method in PanelManager
  • Introduced Preview panel for mode-based content rendering
  • Introduced Outline panel for mode-based content overview and navigation
  • Introduced Problems panel for mode-based linting

Editor

  • Added type timer to skip file processing when user types
  • Automatic code completion requests triggered by typing
  • Automatic preview update requests triggered by typing
  • Automatic problems update request s triggered by typing

EditorAPI

  • Complete refactor of internal structure
  • Tracks damaged/incompatible modes and sends them to global access point
  • Validates existence of script, config, and icon files before loading
  • Robust error handling for mode configuration and initialization
  • Blocks modes with invalid parameters or incompatible script classes
  • New is_mode_compatible method for validation
  • Safe mode unloading with fallback support
  • Loads mode features dynamically after switching
  • New utility methods for new mode-based features
  • Enhanced change_mode_to method with full lifecycle support
  • Manage live preview updates, problems and file outline

Core

  • Refactored settings working for better modularity

Related Items

Testing

Basic functionality tests have been performed for:

  • Mode switching
  • Auto Format and Auto Indent execution
  • Preview rendering
  • Code completion triggering
  • Outline generation
  • File linting
  • New panels

Full regression testing and edge case validation are currently in progress.

Impact

This refactor significantly improves performance by:

  • Reducing redundant data loading
  • Caching mode-specific resources
  • Avoiding unnecessary file I/O during mode operations

It also lays the groundwork for future extensibility, including custom mode features, better syntax highlighting, and enhanced editor responsiveness.

Additional Information

Modes now follow a standardized structure by extending the TextForgeMode class, which provides built-in utilities for common features. Key architectural changes include:

  • 🔧 Mode Initialization:
    Modes can return error codes during initialization to cancel loading if incompatible.

  • 🎨 Syntax Highlighting:
    Each mode provides its own syntax_highlighter instance, which is shared with the editor.

  • 🧩 Mode Panels:
    Modes can define a custom panel for user interaction, displayed on the left side of the editor.

  • 📝 Auto Format & Auto Indent:
    These features are now managed per mode. Action scripts read mode capabilities and enable/disable themselves accordingly. EditorAPI will manage requests and modes for safe actions.

  • 💾 Saving & Loading:
    Modes do not access files directly. Instead:

    • EditorAPI loads file content as PackedByteArray, sends it to the mode, and receives a String for display.
    • For saving, EditorAPI sends the editor text (String) to the mode, which returns a PackedByteArray for file writing.
  • 👁️ Preview System:
    Modes can convert file content to BBCode for preview rendering. The new Preview panel displays this content.

  • 🚨 Linting & Problems Panel:
    Modes can analyze content and report warnings/errors. These are displayed in a dedicated problems panel with navigation support.

  • 📑 Outline Panel:
    Mods can outline the file. This information allows users to browse parts of the file and switch between them with Outline panel.

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

@mkh-user mkh-user removed this from the Text Forge 0.2 milestone Aug 11, 2025
@mkh-user mkh-user changed the title Mode Update EditorAPI Refactor Aug 11, 2025
@mkh-user mkh-user added action scripts Official action scripts or action scripts features feature: Navigation labels Aug 11, 2025
@mkh-user mkh-user moved this to In progress in Release: Text Forge 1.0 Aug 13, 2025
@mkh-user mkh-user marked this pull request as ready for review August 15, 2025 09:05
@mkh-user mkh-user requested a review from Wiechciu August 15, 2025 09:06
Copy link
Collaborator

@Wiechciu Wiechciu left a comment

Choose a reason for hiding this comment

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

Reviewed, seems alright. Although keep in mind I don't understand half of that code yet =]

@mkh-user
Copy link
Member Author

Last overall unit tests result:

GdUnit Test Client connected with id: ---Removed---
Run Test Suite: res://tests/core/autoload/factory_test.gd
factory_test > test_confirmation_dialog:0 ('Anything', 'Anything', 'Anything', 'Anything', null::null, null::null, true) PASSED 192ms
factory_test > test_confirmation_dialog:1 ('Anything', 'Anything', 'Anything', 'Anything', null::null, null::null, false) PASSED 96ms
factory_test > test_menu_button:0 (false, 'Test')                                   PASSED 87ms
factory_test > test_menu_button:1 (true, '')                                        PASSED 94ms
factory_test > test_signle_line_input:0 ('', '', null::null, true)                  PASSED 131ms
factory_test > test_signle_line_input:1 ('', '', null::null, false)                 PASSED 88ms
Statistics: 6 tests cases | 0 errors | 0 failures | 0 flaky | 0 skipped | 0 orphans | PASSED 891ms

Run Test Suite: res://tests/core/autoload/translation_manager_test.gd
translation_manager_test > test_get_text_from_string_source                         PASSED 41ms
translation_manager_test > test_get_text_from_string_source_fallback                PASSED 32ms
translation_manager_test > test_get_text_from_string_source_invalid_key             PASSED 32ms
translation_manager_test > test_get_text_from_string_source_invalid_lang            PASSED 33ms
translation_manager_test > test_get_text_invalid_file                               PASSED 33ms
translation_manager_test > test_set_language_restore_default                        PASSED 33ms
translation_manager_test > test_set_language_change                                 PASSED 33ms
Statistics: 7 tests cases | 0 errors | 0 failures | 0 flaky | 0 skipped | 0 orphans | PASSED 364ms

Run Test Suite: res://tests/translation_data_test.gd
translation_data_test > test_translation_file                                       PASSED 51ms
Statistics: 1 tests cases | 0 errors | 0 failures | 0 flaky | 0 skipped | 0 orphans | PASSED 68ms

Overall Summary: 14 tests cases | 0 errors | 0 failures | 0 flaky | 0 skipped | 0 orphans |
Executed test suites: (3/3)
Executed test cases : (14/14)
Total execution time: 1s 323ms
 Open XML Report at: ---Removed---
Open HTML Report at: ---Removed---
GdUnit Test Client disconnected with id: ---Removed---

@mkh-user mkh-user merged commit 381c76b into Main Aug 19, 2025
1 check passed
@mkh-user mkh-user deleted the mode-update branch August 19, 2025 13:40
@github-project-automation github-project-automation bot moved this from In progress to Done in Release: Text Forge 1.0 Aug 19, 2025
@mkh-user
Copy link
Member Author

Finally merged!!!

@mkh-user mkh-user added this to the Text Forge 0.1 milestone Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action scripts Official action scripts or action scripts features feature: AutoCompletion feature: Navigation
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Feature: Linters Create "Auto Indent" action Feature: Outline Feature: Auto Completion
2 participants