mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-01 20:43:20 +08:00
MarkdownToolbar: Replace current line
Add a few more tests
This commit is contained in:
@ -98,6 +98,8 @@ TextEditingValue modifyCurrentLine(
|
|||||||
var lineStartPos = text.lastIndexOf('\n', cursorPos == 0 ? 0 : cursorPos - 1);
|
var lineStartPos = text.lastIndexOf('\n', cursorPos == 0 ? 0 : cursorPos - 1);
|
||||||
if (lineStartPos == -1) {
|
if (lineStartPos == -1) {
|
||||||
lineStartPos = 0;
|
lineStartPos = 0;
|
||||||
|
} else {
|
||||||
|
lineStartPos += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lineEndPos = text.indexOf('\n', cursorPos);
|
var lineEndPos = text.indexOf('\n', cursorPos);
|
||||||
|
@ -17,4 +17,55 @@ void main() {
|
|||||||
|
|
||||||
expect(modifyCurrentLine(val, '# '), expectedVal);
|
expect(modifyCurrentLine(val, '# '), expectedVal);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Adds a header to the last line correctly', () {
|
||||||
|
var val = const TextEditingValue(
|
||||||
|
text: 'Hi\nHello',
|
||||||
|
selection: TextSelection.collapsed(offset: 8),
|
||||||
|
);
|
||||||
|
|
||||||
|
var expectedVal = const TextEditingValue(
|
||||||
|
text: 'Hi\n# Hello',
|
||||||
|
selection: TextSelection.collapsed(offset: 10),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(modifyCurrentLine(val, '# '), expectedVal);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Adds a header to a middle line correctly', () {
|
||||||
|
var val = const TextEditingValue(
|
||||||
|
text: 'Hi\nHello\nFire',
|
||||||
|
selection: TextSelection.collapsed(offset: 8),
|
||||||
|
);
|
||||||
|
|
||||||
|
var expectedVal = const TextEditingValue(
|
||||||
|
text: 'Hi\n# Hello\nFire',
|
||||||
|
selection: TextSelection.collapsed(offset: 10),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(modifyCurrentLine(val, '# '), expectedVal);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Adds a header to a middle line middle word correctly', () {
|
||||||
|
var val = const TextEditingValue(
|
||||||
|
text: 'Hi\nHello Darkness\nFire',
|
||||||
|
selection: TextSelection.collapsed(offset: 8),
|
||||||
|
);
|
||||||
|
|
||||||
|
var expectedVal = const TextEditingValue(
|
||||||
|
text: 'Hi\n# Hello Darkness\nFire',
|
||||||
|
selection: TextSelection.collapsed(offset: 10),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(modifyCurrentLine(val, '# '), expectedVal);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Removes from first line
|
||||||
|
// Removes from last line
|
||||||
|
// Removes from middle line
|
||||||
|
// Removes when cursor is in the middle of a word
|
||||||
|
// Removes when cursor is at the start of the line
|
||||||
|
// Removes when cursor is in between '#' and ' '
|
||||||
|
|
||||||
|
// TODO: Simplify the tests, avoid all this code duplication
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user