mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
Bullet Lists: Auto add bullets lists even when modifying in the middle
This commit is contained in:
@ -12,17 +12,11 @@ EditorHeuristicResult autoAddBulletList(
|
||||
return null;
|
||||
}
|
||||
|
||||
// Only when getting a new line
|
||||
// Only when adding a new line
|
||||
if (curText[cursorPos - 1] != '\n') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Only add the bullets at the end of the document
|
||||
// FIXME: We should do this anywhere
|
||||
if (curText.length != cursorPos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var prevLineStart = curText.lastIndexOf('\n', cursorPos - 2);
|
||||
prevLineStart = prevLineStart == -1 ? 0 : prevLineStart + 1;
|
||||
var prevLine = curText.substring(prevLineStart, cursorPos - 1);
|
||||
@ -35,6 +29,11 @@ EditorHeuristicResult autoAddBulletList(
|
||||
|
||||
var indent = match.group(1) ?? "";
|
||||
var text = curText.substring(0, cursorPos) + indent + match.group(2) + ' ';
|
||||
if (cursorPos == curText.length) {
|
||||
return EditorHeuristicResult(text, text.length);
|
||||
}
|
||||
|
||||
return EditorHeuristicResult(text, text.length);
|
||||
text += '\n' + curText.substring(cursorPos + 1);
|
||||
var extraChars = indent.length + match.group(2).length + 1;
|
||||
return EditorHeuristicResult(text, cursorPos + extraChars);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ void main() {
|
||||
expect(result, null);
|
||||
});
|
||||
|
||||
test('Adds a bullet item', () {
|
||||
test('Adds a bullet point at the end', () {
|
||||
var origText = "Hello\n* One";
|
||||
var newText = "Hello\n* One\n";
|
||||
|
||||
@ -19,5 +19,14 @@ void main() {
|
||||
expect(result.text, "Hello\n* One\n* ");
|
||||
expect(result.cursorPos, result.text.length);
|
||||
});
|
||||
|
||||
test('Adds a bullet point in the middle', () {
|
||||
var origText = "Hello\n* One\n* Three";
|
||||
var newText = "Hello\n* One\n\n* Three";
|
||||
|
||||
var result = autoAddBulletList(origText, newText, 12);
|
||||
expect(result.text, "Hello\n* One\n* \n* Three");
|
||||
expect(result.cursorPos, 14);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user