Bug: Typing '---' + Enter creates a new list

This commit is contained in:
Vishesh Handa
2020-09-08 23:08:14 +02:00
parent 984fc6864e
commit dc2c81648e
2 changed files with 11 additions and 4 deletions

@ -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*)(.*)$');
var pattern = RegExp(r'^(\s*)([*\-]|[0-9]\.)(\s+)(.*)$');
var match = pattern.firstMatch(prevLine);
if (match == null) {
//print("no match");

@ -57,13 +57,12 @@ void main() {
expect(result.cursorPos, 12);
});
test('Adds a bullet point without spaces', () {
test('Does not add a bullet point without spaces', () {
var origText = "*One";
var newText = origText + '\n';
var result = autoAddBulletList(origText, newText, newText.length);
expect(result.text, "*One\n*");
expect(result.cursorPos, result.text.length);
expect(result, null);
});
test('Adds a bullet point with many spaces', () {
@ -101,5 +100,13 @@ void main() {
expect(result.text, "* Hi There\n* ");
expect(result.cursorPos, result.text.length);
});
test('Triple dashs', () {
var origText = "---";
var newText = origText + '\n';
var result = autoAddBulletList(origText, newText, newText.length);
expect(result, null);
});
});
}