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

View File

@ -34,7 +34,7 @@ EditorHeuristicResult autoAddBulletList(
prevLineStart = prevLineStart == -1 ? 0 : prevLineStart + 1; prevLineStart = prevLineStart == -1 ? 0 : prevLineStart + 1;
var prevLine = curText.substring(prevLineStart, cursorPos - 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); var match = pattern.firstMatch(prevLine);
if (match == null) { if (match == null) {
//print("no match"); //print("no match");

View File

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