fix: use fullText setter — content from previous file no longer leaks

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 <sf@flemming.it>
This commit is contained in:
flemming-it 2026-05-30 16:07:44 +02:00
parent 8b918f8f2a
commit 7655e0dc32
2 changed files with 8 additions and 5 deletions

View file

@ -127,7 +127,7 @@ class _FlowEditorPageState extends State<FlowEditorPage> {
// 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<FlowEditorPage> {
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<FlowEditorPage> {
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;

View file

@ -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