mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 17:29:50 +08:00
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:
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user