Automated changelog | Aug 01 - Aug 08 | 28 hours (4 active days)
Architecture & Performance
This period saw a major architectural refactor focused on boosting real-time editor performance and laying the groundwork for advanced features.
- Optimized Element Detection Service: The
ElementDetectionServicehas been re-architected with a “Dual Method” approach to drastically reduce processing overhead during live typing.- Implementation: The original
detectElementTypemethod has been renamed todetectElementTypeImport, intended for initial file parsing where context is pre-built. A new, highly optimizeddetectElementTypeRealTimemethod was introduced for live editor interactions. - Technical Details: The
detectElementTypeRealTimemethod implements a “fast-path” that handles over 80% of typing scenarios (like dialogue continuation) with zero memory allocation. It achieves this by prioritizing checks on forced syntax and previous element types (previousElementTypes) before falling back to a lazy context builder (buildContextclosure). This avoids expensive document traversal on every keystroke. - Impact: This change delivers a significant performance improvement (estimated 85-95%) and reduces memory churn, resulting in a much more responsive editor experience. The new architecture is detailed in
SCRIPT_ELEMENT_DETECTION_OPTIMIZATION_PLAN.md.
- Implementation: The original
- Standardized Context Building: The
FountainContextUtilsservice was updated to provide a consistent and limited context window for element detection.- Implementation: The
buildContextForNodeandbuildContextForLinemethods now enforce a strict limit of 20 previous lines for context. - Impact: This ensures predictable and performant behavior for the element detection service, preventing slowdowns in very large documents.
- Implementation: The
- Optimized Syntax Detection: The core
FountainSyntaxDetectorreceived significant performance enhancements.- Implementation: The
isBasicCharacterNamemethod was heavily optimized using a “fail-fast” strategy, replacing many regular expressions with direct character code checks. TheisDialogueWithContextmethod now leverages a history ofpreviousElementTypesfor more accurate and performant detection. Regex patterns have been pre-compiled as static constants to reduce overhead. - Impact: These optimizations contribute to faster parsing and more accurate real-time element identification across the application.
- Implementation: The
- Real-time Controller Integration: The
FountainRealtimeControllerwas updated to leverage these new performance optimizations.- Implementation: The controller now calls the new
detectElementTypeRealTimeservice method, providing the lazybuildContextclosure. A new_collectPreviousElementTypeshelper was added to gather metadata from previous nodes, feeding crucial information into the new fast-path detection logic.
- Implementation: The controller now calls the new
New Feature: Real-time Script Analytics
A comprehensive, real-time script analytics service has been implemented, providing live statistical feedback to the user without impacting editor performance.
- Analytics Service & Data Models:
- Implementation: A new
ScriptAnalyticsServicewas introduced. It hooks into theFountainRealtimeControllerto receive document change notifications and updates analytics via a debouncedStream. The core innovation is its high-performance design: instead of re-parsing text, it iterates through SuperEditor’sParagraphNodes and reads the pre-calculatedfountainTypefromnode.metadata. - Data Models: New data models were created to support this feature:
ScriptAnalytics(for overall script stats like element counts and page estimation) andCharacterStats(for per-character metrics like dialogue lines and estimated screen time). These models includecopyWithand JSON serialization methods.
- Implementation: A new
- Industry-Standard Page Calculation:
- Implementation: A new
ScreenplayPageCalculatorservice was added. It uses industry-standard rules (e.g., 55 lines per page) and element-specific line weights (elementLineWeights) to provide an accurate page count, complete with fractional formatting (e.g., “22 3/4 pages”).
- Implementation: A new
- UI Components:
- Implementation: New widgets
ScriptAnalyticsPanelandScriptAnalyticsSidebarwere created to display the live data from the service. The panel offers a responsive layout, showing a compact view (isCompact: true) on smaller screens and a full breakdown on larger ones.
- Implementation: New widgets
Script Parsers & Text Processing
Significant improvements were made to the text processing pipeline to increase robustness and fix formatting issues.
- FDX Parser - Empty Line Restoration: A critical formatting regression in the FDX parser has been fixed.
- Implementation: A post-processing step,
_insertStandardEmptyLines, has been added to thefdx_parser. This method uses rule-based helpers (_needsEmptyLineBefore,_needsEmptyLineAfter) to intelligently insert emptyScenePartobjects between screenplay elements, conforming to industry formatting standards. The logic includes critical checks to prevent the insertion of double empty lines. - Impact: Imported FDX files now render with the correct, readable spacing between elements.
- Implementation: A post-processing step,
- Unicode Normalization: A robust Unicode character normalization step was added to the text processing pipeline.
- Implementation: The
FountainTextProcessornow includes anormalizeUnicodeCharactersmethod. This method converts common typographic characters (e.g., smart quotes ‘ ’ “ ”, em/en dashes — –) into their standard ASCII equivalents before parsing. It includes a fast-path check (_isUnicodeCharacterThatNeedsNormalization) to bypass the process if no special characters are found. - Impact: This makes all text-based parsers (Fountain, PDF) significantly more robust, ensuring consistent parsing of text copied from various sources.
- Implementation: The
- Enhanced Text Cleanup: The
TextCleanupUtilsfor pre-processing raw text has been improved.- Implementation: The page indicator detection regex (
_isPageIndicator,_isConsecutivePageIndicator) was updated to correctly identify and remove page numbers that have trailing periods (e.g., “6.”).
- Implementation: The page indicator detection regex (
- Performance Instrumentation: The
FountainTextProcessorandPdfParserhave been instrumented withStopwatch-based logging to measure and analyze performance during parsing, including metrics like lines/sec.
UI & Theming
- Simple Color Theming Toggle: A minimal, state-managed color theming feature has been added to the editor.
- Implementation: A new
ColorThemingNotifier(a RiverpodStateNotifier<bool>) was introduced insimple_editor_theming.dartto manage a simple on/off state. TheFountainFormattedEditorWidgetis now aConsumerWidgetthat watches this state via theeditorColorThemingProvider. - Stylesheet & Keyboard Action: The
FountainStylesheetsclass was updated to apply background colors to elements when theming is enabled. A new keyboard action,createFountainColorThemingAction(Cmd/Ctrl+Shift+T), was added to toggle the state. - Impact: Users can now toggle a color-coded view of the script for better element distinction.
- Implementation: A new
Stability & Error Handling
- Keyboard Error Boundary: A critical stability improvement was added to the script editor.
- Implementation: The
ScriptEditorWidgetnow wraps theSuperEditorinstance in a customFlutterErrorBoundary. This boundary specifically catches theKeyDownEventassertion error that was causing editor freezes. When the error is caught, it triggers a recovery routine (_recoverFromKeyboardError) that resets the editor’s focus state, preventing a crash. - Impact: This makes the editor significantly more resilient to a known Flutter framework assertion, improving overall stability.
- Implementation: The