mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-14 23:40:30 +08:00
EditorHeuristics: Handle edge cases
This commit is contained in:
@ -11,6 +11,9 @@ EditorHeuristicResult autoAddBulletList(
|
||||
if (curText.length <= oldText.length) {
|
||||
return null;
|
||||
}
|
||||
if (cursorPos <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Only when adding a new line
|
||||
if (curText[cursorPos - 1] != '\n') {
|
||||
@ -18,7 +21,19 @@ EditorHeuristicResult autoAddBulletList(
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
print("CursorPos: $cursorPos");
|
||||
print("Text Length: ${curText.length}");
|
||||
*/
|
||||
|
||||
if (cursorPos - 2 < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var prevLineStart = curText.lastIndexOf('\n', cursorPos - 2);
|
||||
if (prevLineStart < 0 || (cursorPos - 1) < 0) {
|
||||
return null;
|
||||
}
|
||||
prevLineStart = prevLineStart == -1 ? 0 : prevLineStart + 1;
|
||||
var prevLine = curText.substring(prevLineStart, cursorPos - 1);
|
||||
|
||||
@ -37,8 +52,6 @@ EditorHeuristicResult autoAddBulletList(
|
||||
curText.length > cursorPos ? curText.substring(cursorPos) : "";
|
||||
|
||||
/*
|
||||
print("CursorPos: $cursorPos");
|
||||
print("Text Length: ${curText.length}");
|
||||
if (remainingText.isNotEmpty) {
|
||||
print("At cursor: #${curText[cursorPos]}#");
|
||||
}
|
||||
|
@ -5,7 +5,9 @@ import 'package:gitjournal/core/note.dart';
|
||||
import 'package:gitjournal/editors/common.dart';
|
||||
import 'package:gitjournal/editors/heuristics.dart';
|
||||
import 'package:gitjournal/editors/note_title_editor.dart';
|
||||
import 'package:gitjournal/error_reporting.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
import 'package:gitjournal/utils/logger.dart';
|
||||
import 'package:gitjournal/widgets/editor_scroll_view.dart';
|
||||
import 'package:gitjournal/widgets/note_viewer.dart';
|
||||
|
||||
@ -155,8 +157,9 @@ class MarkdownEditorState extends State<MarkdownEditor> implements EditorState {
|
||||
void _noteTextChanged() {
|
||||
try {
|
||||
_applyHeuristics();
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} catch (e, stackTrace) {
|
||||
Log.e("EditorHeuristics: $e");
|
||||
logExceptionWarning(e, stackTrace);
|
||||
}
|
||||
if (_noteModified && !widget.isNewNote) return;
|
||||
|
||||
|
Reference in New Issue
Block a user