Add Editor Heuristics to Journal Editor

I frequently make lists in the Journal Editor and it's annoying that
these features aren't available.
This commit is contained in:
Vishesh Handa
2021-02-03 19:24:19 +01:00
parent b301d70991
commit 8eb8905d6d
2 changed files with 24 additions and 11 deletions

View File

@ -5,7 +5,10 @@ import 'package:flutter/material.dart';
import 'package:gitjournal/core/note.dart';
import 'package:gitjournal/editors/common.dart';
import 'package:gitjournal/editors/disposable_change_notifier.dart';
import 'package:gitjournal/editors/heuristics.dart';
import 'package:gitjournal/editors/note_body_editor.dart';
import 'package:gitjournal/error_reporting.dart';
import 'package:gitjournal/utils/logger.dart';
import 'package:gitjournal/widgets/editor_scroll_view.dart';
import 'package:gitjournal/widgets/journal_editor_header.dart';
@ -57,6 +60,8 @@ class JournalEditorState extends State<JournalEditor>
TextEditingController _textController = TextEditingController();
bool _noteModified;
EditorHeuristics _heuristics;
JournalEditorState(this.note) {
_textController = TextEditingController(text: note.body);
}
@ -65,6 +70,7 @@ class JournalEditorState extends State<JournalEditor>
void initState() {
super.initState();
_noteModified = widget.noteModified;
_heuristics = EditorHeuristics(text: note.body);
}
@override
@ -121,6 +127,13 @@ class JournalEditorState extends State<JournalEditor>
}
void _noteTextChanged() {
try {
_applyHeuristics();
} catch (e, stackTrace) {
Log.e("EditorHeuristics: $e");
logExceptionWarning(e, stackTrace);
}
if (_noteModified && !widget.editMode) {
notifyListeners();
return;
@ -136,6 +149,14 @@ class JournalEditorState extends State<JournalEditor>
notifyListeners();
}
void _applyHeuristics() {
var editState = TextEditorState.fromValue(_textController.value);
var es = _heuristics.textChanged(editState);
if (es != null) {
_textController.value = es.toValue();
}
}
@override
Future<void> addImage(File file) async {
await getNote().addImage(file);

View File

@ -188,18 +188,10 @@ class MarkdownEditorState extends State<MarkdownEditor>
}
void _applyHeuristics() {
var selection = _textController.selection;
var editState = TextEditorState.fromValue(_textController.value);
// vHanda: Why does this happen?
if (selection.baseOffset != selection.extentOffset) {
_heuristics.textChanged(editState);
return;
}
var r = _heuristics.textChanged(editState);
if (r != null) {
_textController.value = r.toValue();
var es = _heuristics.textChanged(editState);
if (es != null) {
_textController.value = es.toValue();
}
}