diff --git a/lib/editors/heuristics.dart b/lib/editors/heuristics.dart index 5c7c594f..4307b8b6 100644 --- a/lib/editors/heuristics.dart +++ b/lib/editors/heuristics.dart @@ -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]}#"); } diff --git a/lib/editors/markdown_editor.dart b/lib/editors/markdown_editor.dart index 734a507f..c6d57fc6 100644 --- a/lib/editors/markdown_editor.dart +++ b/lib/editors/markdown_editor.dart @@ -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 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;