From a43498ef6d50c7d34d42c54c8adf26a7292c937f Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Mon, 8 Jun 2020 00:26:16 +0200 Subject: [PATCH] Editor Heurisitics: Should work even if the items have spaces --- lib/editors/heuristics.dart | 2 +- test/editor_heuristics_test.dart | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/editors/heuristics.dart b/lib/editors/heuristics.dart index 8f28fe25..3606ee40 100644 --- a/lib/editors/heuristics.dart +++ b/lib/editors/heuristics.dart @@ -34,7 +34,7 @@ EditorHeuristicResult autoAddBulletList( prevLineStart = prevLineStart == -1 ? 0 : prevLineStart + 1; var prevLine = curText.substring(prevLineStart, cursorPos - 1); - var pattern = RegExp(r'^(\s*)([*\-]|[0-9]\.)(\s*)([^\s]*)$'); + var pattern = RegExp(r'^(\s*)([*\-]|[0-9]\.)(\s*)(.*)$'); var match = pattern.firstMatch(prevLine); if (match == null) { //print("no match"); diff --git a/test/editor_heuristics_test.dart b/test/editor_heuristics_test.dart index f0b045a8..a56f881b 100644 --- a/test/editor_heuristics_test.dart +++ b/test/editor_heuristics_test.dart @@ -74,15 +74,31 @@ void main() { expect(result.cursorPos, result.text.length); }); - /* + test('Adds a numbered list in the first line', () { + var origText = "1. Hello"; + var newText = origText + '\n'; + + var result = autoAddBulletList(origText, newText, newText.length); + expect(result.text, "1. Hello\n1. "); + expect(result.cursorPos, result.text.length); + }); + test('Adds a bullet point with many spaces - in the middle', () { var origText = "* One\nFire"; - var newText = origText + '\n'; + var newText = "* One\n\nFire"; var result = autoAddBulletList(origText, newText, 8); expect(result.text, "* One\n* \nFire"); expect(result.cursorPos, 12); }); - */ + + test('Works with item with spaces', () { + var origText = "* Hi There"; + var newText = origText + '\n'; + + var result = autoAddBulletList(origText, newText, newText.length); + expect(result.text, "* Hi There\n* "); + expect(result.cursorPos, result.text.length); + }); }); }