Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.2.2 - 2026-07-14

### Fixed

- Rich text note not saving when switching to read-only mode

## 2.2.1 - 2026-07-10

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/380.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FIXED
- Rich text note not saving when switching to read-only mode
2 changes: 2 additions & 0 deletions fastlane/metadata/android/fr-FR/changelogs/380.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CORRIGÉ
- Note de texte riche ne s'enregistre pas lors du passage en mode lecture seule
87 changes: 73 additions & 14 deletions lib/pages/editor/editor_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:fleather/fleather.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -35,6 +37,12 @@ class EditorPage extends ConsumerStatefulWidget {
}

class _EditorState extends ConsumerState<EditorPage> {
Timer? saveDebounce;
Note? pendingNote;

FleatherController? _fleatherController;
RichTextNote? _fleatherControllerNote;

@override
void initState() {
super.initState();
Expand All @@ -47,6 +55,15 @@ class _EditorState extends ConsumerState<EditorPage> {

@override
void dispose() {
// If a save was waiting to happen, save immediately
if (saveDebounce?.isActive ?? false) {
saveDebounce!.cancel();

if (pendingNote != null) {
save(pendingNote!, globalRef);
}
}

// ignore: avoid_ref_inside_state_dispose
globalRef.read(notesProvider(status: NoteStatus.available).notifier).removeEmpty();
// ignore: avoid_ref_inside_state_dispose
Expand All @@ -59,6 +76,42 @@ class _EditorState extends ConsumerState<EditorPage> {
editorFocusNode.requestFocus();
}

void scheduleSave(Note note) {
pendingNote = note;

saveDebounce?.cancel();
saveDebounce = Timer(const Duration(milliseconds: 1000), () => save(note));
}

void save(Note note, [WidgetRef? widgetRef]) {
(widgetRef ?? ref).read(notesProvider(status: NoteStatus.available, label: currentLabelFilter).notifier).edit(note);

pendingNote = null;
}

FleatherController getFleatherController(RichTextNote note) {
// Do not reset the controller if the note hasn't changed (happens when the editing mode switches)
if (_fleatherController != null && _fleatherControllerNote == note) {
return _fleatherController!;
}

_fleatherController?.dispose();
_fleatherController = FleatherController(
document: note.document,
autoFormats: AutoFormats(
autoFormats: [
const AutoFormatLinks(),
const MarkdownInlineShortcuts(),
const MarkdownLineShortcuts(),
const AutoTextDirection(),
],
),
);
_fleatherControllerNote = note;

return _fleatherController!;
}

@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
Expand All @@ -85,31 +138,37 @@ class _EditorState extends ConsumerState<EditorPage> {
Widget? toolbar;
switch (currentNote) {
case PlainTextNote note:
contentEditor = PlainTextEditor(note: note, readOnly: readOnly, autofocus: autofocus);
case RichTextNote note:
final fleatherController = FleatherController(
document: note.document,
autoFormats: AutoFormats(
autoFormats: [
const AutoFormatLinks(),
const MarkdownInlineShortcuts(),
const MarkdownLineShortcuts(),
const AutoTextDirection(),
],
),
contentEditor = PlainTextEditor(
note: note,
readOnly: readOnly,
autofocus: autofocus,
onChanged: scheduleSave,
);
case RichTextNote note:
final fleatherController = getFleatherController(note);
fleatherControllerNotifier.value = fleatherController;
contentEditor = RichTextEditor(
note: note,
fleatherController: fleatherController,
readOnly: readOnly,
autofocus: autofocus,
onChanged: scheduleSave,
);
toolbar = Toolbar(fleatherController: fleatherController);
case MarkdownNote note:
contentEditor = MarkdownEditor(note: note, readOnly: readOnly, autofocus: autofocus);
contentEditor = MarkdownEditor(
note: note,
readOnly: readOnly,
autofocus: autofocus,
onChanged: scheduleSave,
);
case ChecklistNote note:
contentEditor = ChecklistEditor(note: note, isNewNote: widget.isNewNote, readOnly: readOnly);
contentEditor = ChecklistEditor(
note: note,
isNewNote: widget.isNewNote,
readOnly: readOnly,
onChanged: scheduleSave,
);
}

final editor = Scaffold(
Expand Down
53 changes: 14 additions & 39 deletions lib/pages/editor/widgets/editors/checklist_editor.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_checklist/checklist.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../../common/constants/constants.dart';
import '../../../../models/note/note.dart';
import '../../../../models/note/note_status.dart';
import '../../../../providers/notes/notes_provider.dart';
import '../../../../providers/notifiers/notifiers.dart';

/// Checklist editor.
class ChecklistEditor extends ConsumerStatefulWidget {
/// Editor allowing to edit the checklist content of a [ChecklistNote].
const ChecklistEditor({super.key, required this.note, required this.isNewNote, required this.readOnly});
const ChecklistEditor({
super.key,
required this.note,
required this.isNewNote,
required this.readOnly,
required this.onChanged,
});

/// The note to display.
final ChecklistNote note;
Expand All @@ -24,47 +24,22 @@ class ChecklistEditor extends ConsumerStatefulWidget {
/// Whether the text fields are read only.
final bool readOnly;

/// Called when the note has changed.
final ValueChanged<Note> onChanged;

@override
ConsumerState<ChecklistEditor> createState() => _ChecklistEditorState();
}

class _ChecklistEditorState extends ConsumerState<ChecklistEditor> {
Timer? saveDebounce;
List<ChecklistLine>? pendingChecklistLines;

void onChanged(List<ChecklistLine> checklistLines) {
pendingChecklistLines = checklistLines;

// Reset the saving debounce timer on each change
saveDebounce?.cancel();
saveDebounce = Timer(const Duration(milliseconds: 1000), save);
}

void save([WidgetRef? widgetRef]) {
if (pendingChecklistLines == null) {
return;
}

final checkboxes = pendingChecklistLines!.map((checklistLine) => checklistLine.toggled).toList();
final texts = pendingChecklistLines!.map((checklistLine) => checklistLine.text).toList();
final newNote = widget.note
final checkboxes = checklistLines.map((checklistLine) => checklistLine.toggled).toList();
final texts = checklistLines.map((checklistLine) => checklistLine.text).toList();
final note = widget.note
..checkboxes = checkboxes
..texts = texts;

(widgetRef ?? ref)
.read(notesProvider(status: NoteStatus.available, label: currentLabelFilter).notifier)
.edit(newNote);
}

@override
void dispose() {
// If a save was waiting to happen, save immediately
if (saveDebounce?.isActive ?? false) {
saveDebounce!.cancel();
save(globalRef);
}

super.dispose();
widget.onChanged(note);
}

@override
Expand Down
36 changes: 11 additions & 25 deletions lib/pages/editor/widgets/editors/markdown_editor.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
Expand All @@ -11,14 +9,17 @@ import '../../../../common/constants/constants.dart';
import '../../../../common/constants/paddings.dart';
import '../../../../common/extensions/build_context_extension.dart';
import '../../../../models/note/note.dart';
import '../../../../models/note/note_status.dart';
import '../../../../providers/notes/notes_provider.dart';
import '../../../../providers/notifiers/notifiers.dart';

/// Markdown editor.
class MarkdownEditor extends ConsumerStatefulWidget {
/// Markdown allowing to edit the markdown text content of a [MarkdownNote].
const MarkdownEditor({super.key, required this.note, required this.readOnly, required this.autofocus});
const MarkdownEditor({
super.key,
required this.note,
required this.readOnly,
required this.autofocus,
required this.onChanged,
});

/// The note to display.
final MarkdownNote note;
Expand All @@ -29,13 +30,15 @@ class MarkdownEditor extends ConsumerStatefulWidget {
/// Whether the text field should request focus.
final bool autofocus;

/// Called when the note has changed.
final ValueChanged<Note> onChanged;

@override
ConsumerState<MarkdownEditor> createState() => _MarkdownEditorState();
}

class _MarkdownEditorState extends ConsumerState<MarkdownEditor> {
late final TextEditingController contentTextController;
Timer? saveDebounce;

@override
void initState() {
Expand All @@ -45,15 +48,9 @@ class _MarkdownEditorState extends ConsumerState<MarkdownEditor> {
}

void onChanged() {
// Reset the saving debounce timer on each change
saveDebounce?.cancel();
saveDebounce = Timer(const Duration(milliseconds: 1000), save);
}

void save([WidgetRef? widgetRef]) {
final note = widget.note..content = contentTextController.text;

(widgetRef ?? ref).read(notesProvider(status: NoteStatus.available, label: currentLabelFilter).notifier).edit(note);
widget.onChanged(note);
}

void onOpenLink(String text, String? href, String title) {
Expand All @@ -66,17 +63,6 @@ class _MarkdownEditorState extends ConsumerState<MarkdownEditor> {
launchUrl(uri);
}

@override
void dispose() {
// If a save was waiting to happen, save immediately
if (saveDebounce?.isActive ?? false) {
saveDebounce!.cancel();
save(globalRef);
}

super.dispose();
}

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
Expand Down
36 changes: 11 additions & 25 deletions lib/pages/editor/widgets/editors/plain_text_editor.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand All @@ -8,14 +6,17 @@ import '../../../../common/constants/constants.dart';
import '../../../../common/constants/paddings.dart';
import '../../../../common/extensions/build_context_extension.dart';
import '../../../../models/note/note.dart';
import '../../../../models/note/note_status.dart';
import '../../../../providers/notes/notes_provider.dart';
import '../../../../providers/notifiers/notifiers.dart';

/// Plain text editor.
class PlainTextEditor extends ConsumerStatefulWidget {
/// Text editor allowing to edit the plain text content of a [PlainTextNote].
const PlainTextEditor({super.key, required this.note, required this.readOnly, required this.autofocus});
const PlainTextEditor({
super.key,
required this.note,
required this.readOnly,
required this.autofocus,
required this.onChanged,
});

/// The note to display.
final PlainTextNote note;
Expand All @@ -26,13 +27,15 @@ class PlainTextEditor extends ConsumerStatefulWidget {
/// Whether the text field should request focus.
final bool autofocus;

/// Called when the note has changed.
final ValueChanged<Note> onChanged;

@override
ConsumerState<PlainTextEditor> createState() => _PlainTextEditorState();
}

class _PlainTextEditorState extends ConsumerState<PlainTextEditor> {
late final TextEditingController contentTextController;
Timer? saveDebounce;

@override
void initState() {
Expand All @@ -42,26 +45,9 @@ class _PlainTextEditorState extends ConsumerState<PlainTextEditor> {
}

void onChanged() {
// Reset the saving debounce timer on each change
saveDebounce?.cancel();
saveDebounce = Timer(const Duration(milliseconds: 1000), save);
}

void save([WidgetRef? widgetRef]) {
final note = widget.note..content = contentTextController.text;

(widgetRef ?? ref).read(notesProvider(status: NoteStatus.available, label: currentLabelFilter).notifier).edit(note);
}

@override
void dispose() {
// If a save was waiting to happen, save immediately
if (saveDebounce?.isActive ?? false) {
saveDebounce!.cancel();
save(globalRef);
}

super.dispose();
widget.onChanged(note);
}

@override
Expand Down
Loading
Loading