From 7655e0dc32fa3093b36c094a1fbad87625199227 Mon Sep 17 00:00:00 2001 From: flemming-it Date: Sat, 30 May 2026 16:07:44 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20use=20fullText=20setter=20=E2=80=94=20co?= =?UTF-8?q?ntent=20from=20previous=20file=20no=20longer=20leaks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stefan reported that opening a flow (hello) sometimes showed content from a different flow (extract-with-approval). Cause: flutter_code_editor's CodeController distinguishes between `text` (the visible buffer, post-fold) and `fullText` (the underlying source). Setting `_code.text = newFile` only updates the visible buffer; the underlying `_code` data structure retains the previous file's source, so subsequent folding/scrolling can surface its content. Switch all three load sites + the save site to the canonical setter: Before _code.text = text (visible buffer only) After _code.fullText = text (replaces underlying source) Save also moves to writing `_code.fullText` so any text the operator collapsed behind a fold survives the round-trip. Verified against flutter_code_editor 0.3.5 source — the fullText setter calls `_updateCodeIfChanged` then re-emits `TextEditingValue(text: _code.visibleText)`, which is the documented "fully reset the editor" path. Bump version 0.1.1 → 0.1.2. Studio's pubspec already pins `ref: main` so the next `flutter pub upgrade` picks it up. Signed-off-by: flemming-it --- lib/src/flow_editor_page.dart | 11 +++++++---- pubspec.yaml | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/src/flow_editor_page.dart b/lib/src/flow_editor_page.dart index b46b4b2..ca9e865 100644 --- a/lib/src/flow_editor_page.dart +++ b/lib/src/flow_editor_page.dart @@ -127,7 +127,7 @@ class _FlowEditorPageState extends State { // captures whatever line-ending normalisation / fold- // marker insertion CodeController applied, so the dirty // check is comparing apples to apples. - _code.text = text; + _code.fullText = text; setState(() { _activeName = name; _baseline = _code.fullText; @@ -142,7 +142,7 @@ class _FlowEditorPageState extends State { if (keep == false || !mounted) return; } final text = await File(f.path).readAsString(); - _code.text = text; + _code.fullText = text; setState(() { _activeName = f.name; _baseline = _code.fullText; @@ -177,7 +177,10 @@ class _FlowEditorPageState extends State { setState(() => _saving = true); try { final f = File('${_defaultFlowsDir()}/$name.yaml'); - await f.writeAsString(_code.text, flush: true); + // Write fullText — `text` is post-fold visible-only, so + // saving it would lose any content the editor has hidden + // behind a collapsed fold. + await f.writeAsString(_code.fullText, flush: true); if (!mounted) return; setState(() { _baseline = _code.fullText; @@ -227,7 +230,7 @@ outputs: } await f.writeAsString(template, flush: true); if (!mounted) return; - _code.text = template; + _code.fullText = template; setState(() { _activeName = name; _baseline = _code.fullText; diff --git a/pubspec.yaml b/pubspec.yaml index 1e9dc3b..7fd16db 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: fai_studio_flow_editor description: Swappable inline YAML editor for F∆I Studio flows. -version: 0.1.1 +version: 0.1.2 publish_to: 'none' repository: https://git.flemming.ai/fai/studio-flow-editor