mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
Editor Heurisitics: Should work even if the items have spaces
This commit is contained in:
@ -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*)([^\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");
|
||||||
|
@ -74,15 +74,31 @@ void main() {
|
|||||||
expect(result.cursorPos, result.text.length);
|
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', () {
|
test('Adds a bullet point with many spaces - in the middle', () {
|
||||||
var origText = "* One\nFire";
|
var origText = "* One\nFire";
|
||||||
var newText = origText + '\n';
|
var newText = "* One\n\nFire";
|
||||||
|
|
||||||
var result = autoAddBulletList(origText, newText, 8);
|
var result = autoAddBulletList(origText, newText, 8);
|
||||||
expect(result.text, "* One\n* \nFire");
|
expect(result.text, "* One\n* \nFire");
|
||||||
expect(result.cursorPos, 12);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user