From 47e8ac8b082592642c52ea12311d6513f483bf22 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Mon, 1 Jun 2020 23:26:49 +0200 Subject: [PATCH] Auto add numbered lists when typing Since we're using markdown it's kinda awesome that we can re-use the same last number and markdown will arrange the numbers properly. --- lib/editors/heuristics.dart | 2 +- test/editor_heuristics_test.dart | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/editors/heuristics.dart b/lib/editors/heuristics.dart index b7c6e3e8..b635bb25 100644 --- a/lib/editors/heuristics.dart +++ b/lib/editors/heuristics.dart @@ -21,7 +21,7 @@ EditorHeuristicResult autoAddBulletList( prevLineStart = prevLineStart == -1 ? 0 : prevLineStart + 1; var prevLine = curText.substring(prevLineStart, cursorPos - 1); - var pattern = RegExp(r'^(\s*)([*\-])'); + var pattern = RegExp(r'^(\s*)([*\-]|[0-9]\.)'); var match = pattern.firstMatch(prevLine); if (match == null) { return null; diff --git a/test/editor_heuristics_test.dart b/test/editor_heuristics_test.dart index 8298e979..7d47cd4b 100644 --- a/test/editor_heuristics_test.dart +++ b/test/editor_heuristics_test.dart @@ -28,5 +28,14 @@ void main() { expect(result.text, "Hello\n* One\n* \n* Three"); expect(result.cursorPos, 14); }); + + test('Adds a numbered list at the end', () { + var origText = "Hello\n1. One"; + var newText = "Hello\n1. One\n"; + + var result = autoAddBulletList(origText, newText, newText.length); + expect(result.text, "Hello\n1. One\n1. "); + expect(result.cursorPos, result.text.length); + }); }); }