Editor Heurisitics: Should work even if the items have spaces

This commit is contained in:
Vishesh Handa
2020-06-08 00:26:16 +02:00
parent fa9b3196f7
commit a43498ef6d
2 changed files with 20 additions and 4 deletions

View File

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

View File

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