MarkdownEditor: Handle title change marking note as modified

This commit is contained in:
Vishesh Handa
2021-02-02 16:25:43 +01:00
parent 8c3abe7b65
commit 350fbb1ccf

View File

@ -104,7 +104,7 @@ class MarkdownEditorState extends State<MarkdownEditor>
children: <Widget>[ children: <Widget>[
NoteTitleEditor( NoteTitleEditor(
_titleTextController, _titleTextController,
_noteTextChanged, _noteTitleTextChanged,
), ),
NoteBodyEditor( NoteBodyEditor(
textController: _textController, textController: _textController,
@ -176,6 +176,20 @@ class MarkdownEditorState extends State<MarkdownEditor>
notifyListeners(); notifyListeners();
} }
void _noteTitleTextChanged() {
if (_noteModified && !widget.editMode) return;
var newState =
!(widget.editMode && _titleTextController.text.trim().isEmpty);
if (newState != _noteModified) {
setState(() {
_noteModified = newState;
});
}
notifyListeners();
}
void _applyHeuristics() { void _applyHeuristics() {
var selection = _textController.selection; var selection = _textController.selection;
if (selection.baseOffset != selection.extentOffset) { if (selection.baseOffset != selection.extentOffset) {