MarkdownToolBar: Make bold work with newlines

This commit is contained in:
Vishesh Handa
2020-08-15 12:36:13 +02:00
parent 2c8bf8d5ae
commit 850e9c7826
2 changed files with 13 additions and 2 deletions

View File

@ -132,14 +132,15 @@ TextEditingValue modifyCurrentWord(
} }
//print('CursorPos: $cursorPos'); //print('CursorPos: $cursorPos');
var wordStartPos = text.lastIndexOf(' ', cursorPos == 0 ? 0 : cursorPos - 1); var wordStartPos =
text.lastIndexOf(RegExp('\\s'), cursorPos == 0 ? 0 : cursorPos - 1);
if (wordStartPos == -1) { if (wordStartPos == -1) {
wordStartPos = 0; wordStartPos = 0;
} else { } else {
wordStartPos += 1; wordStartPos += 1;
} }
var wordEndPos = text.indexOf(' ', cursorPos); var wordEndPos = text.indexOf(RegExp('\\s'), cursorPos);
if (wordEndPos == -1) { if (wordEndPos == -1) {
wordEndPos = text.length; wordEndPos = text.length;
} }

View File

@ -167,6 +167,16 @@ void main() {
); );
}); });
test("Surrounds the middle word with a newline", () {
_testWord(
before: 'Hello\nHydra Person',
beforeOffset: 8,
after: 'Hello\n**Hydra** Person',
afterOffset: 13,
char: '**',
);
});
// //
// Navigation // Navigation
// //