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.
This commit is contained in:
Vishesh Handa
2020-06-01 23:26:49 +02:00
parent a5a7211788
commit 47e8ac8b08
2 changed files with 10 additions and 1 deletions

View File

@ -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;

View File

@ -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);
});
});
}