From 440ee96639a766643d4838de896edf4d2ecd580c Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Fri, 14 Aug 2020 21:21:08 +0200 Subject: [PATCH] MarkdownToolbar: Bold: Add more tests --- lib/widgets/markdown_toolbar.dart | 2 ++ test/markdown_toolbar_test.dart | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/widgets/markdown_toolbar.dart b/lib/widgets/markdown_toolbar.dart index c78a6f83..47b8e41e 100644 --- a/lib/widgets/markdown_toolbar.dart +++ b/lib/widgets/markdown_toolbar.dart @@ -110,6 +110,8 @@ TextEditingValue modifyCurrentWord( var wordStartPos = text.lastIndexOf(' ', cursorPos == 0 ? 0 : cursorPos - 1); if (wordStartPos == -1) { wordStartPos = 0; + } else { + wordStartPos += 1; } var wordEndPos = text.indexOf(' ', cursorPos); diff --git a/test/markdown_toolbar_test.dart b/test/markdown_toolbar_test.dart index bd0ca2d8..a3f99b98 100644 --- a/test/markdown_toolbar_test.dart +++ b/test/markdown_toolbar_test.dart @@ -146,4 +146,24 @@ void main() { char: '**', ); }); + + test("Surrounds the middle word", () { + _testWord( + before: 'Hello Hydra Person', + beforeOffset: 8, + after: 'Hello **Hydra** Person', + afterOffset: 13, + char: '**', + ); + }); + + test("Removes the middle word", () { + _testWord( + before: 'Hello **Hydra** Person', + beforeOffset: 9, + after: 'Hello Hydra Person', + afterOffset: 11, + char: '**', + ); + }); }