From e763d037214476ad38a240e2f22648496a8e9c1c Mon Sep 17 00:00:00 2001 From: jimmyff Date: Fri, 7 Jun 2024 10:41:21 +0100 Subject: [PATCH 1/5] fixes null check operator used on null value if onSelectionChanged is not specified --- packages/flutter_markdown/lib/src/builder.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/flutter_markdown/lib/src/builder.dart b/packages/flutter_markdown/lib/src/builder.dart index b89ef2e7035..66dec8002d1 100644 --- a/packages/flutter_markdown/lib/src/builder.dart +++ b/packages/flutter_markdown/lib/src/builder.dart @@ -961,9 +961,10 @@ class MarkdownBuilder implements md.NodeVisitor { text!, textScaler: styleSheet.textScaler, textAlign: textAlign ?? TextAlign.start, - onSelectionChanged: - (TextSelection selection, SelectionChangedCause? cause) => - onSelectionChanged!(text.text, selection, cause), + onSelectionChanged: onSelectionChanged != null + ? (TextSelection selection, SelectionChangedCause? cause) => + onSelectionChanged!(text.text, selection, cause) + : null, onTap: onTapText, key: k, ); From f80dfa31f65e4f1d063570beba7cab3ee6b0753d Mon Sep 17 00:00:00 2001 From: jimmyff Date: Fri, 7 Jun 2024 10:51:23 +0100 Subject: [PATCH 2/5] Version bump for PR --- packages/flutter_markdown/CHANGELOG.md | 154 +++++++++++++------------ packages/flutter_markdown/pubspec.yaml | 2 +- 2 files changed, 80 insertions(+), 76 deletions(-) diff --git a/packages/flutter_markdown/CHANGELOG.md b/packages/flutter_markdown/CHANGELOG.md index b550b9a29fd..00233907390 100644 --- a/packages/flutter_markdown/CHANGELOG.md +++ b/packages/flutter_markdown/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.7.2 + +* Fixes issue when `onSelectionChanged` is not set + ## 0.7.1 * Allows for choosing a custom font feature to create superscript in footnotes when the font does not support the `supr` font feature. @@ -156,198 +160,198 @@ ## 0.6.10 - * Update `markdown` dependency +* Update `markdown` dependency ## 0.6.9+1 - * Remove build status badge from `README.md` +* Remove build status badge from `README.md` ## 0.6.9 - * Leading spaces in a paragraph and in list items are now ignored according to [GFM #192](https://github.github.com/gfm/#example-192) and [GFM #236](https://github.github.com/gfm/#example-236). +* Leading spaces in a paragraph and in list items are now ignored according to [GFM #192](https://github.github.com/gfm/#example-192) and [GFM #236](https://github.github.com/gfm/#example-236). ## 0.6.8 - * Added option paddingBuilders +* Added option paddingBuilders ## 0.6.7 - * Fix `unnecessary_import` lint errors. - * Added option pPadding - * Added options h1Padding - h6Padding +* Fix `unnecessary_import` lint errors. +* Added option pPadding +* Added options h1Padding - h6Padding ## 0.6.6 - * Soft line break +* Soft line break ## 0.6.5 - * Fix unique Keys for RichText blocks +* Fix unique Keys for RichText blocks ## 0.6.4 - * Fix merging of spans when first span is not a TextSpan +* Fix merging of spans when first span is not a TextSpan ## 0.6.3 - * Fixed `onTap`, now the changed hyperlinks are reflected even with keeping the same link name unchanged. +* Fixed `onTap`, now the changed hyperlinks are reflected even with keeping the same link name unchanged. ## 0.6.2 - * Updated metadata for new source location - * Style changes to conform to flutter/packages analyzer settings +* Updated metadata for new source location +* Style changes to conform to flutter/packages analyzer settings - ## 0.6.1 +## 0.6.1 - * Added builder option bulletBuilder +* Added builder option bulletBuilder ## 0.6.0 - * Null safety release - * Added stylesheet option listBulletPadding - * Fixed blockquote inline styling - * Added onTapText handler for selectable text +* Null safety release +* Added stylesheet option listBulletPadding +* Fixed blockquote inline styling +* Added onTapText handler for selectable text ## 0.6.0-nullsafety.2 - * Dependencies updated for null safety +* Dependencies updated for null safety ## 0.6.0-nullsafety.1 - * Fix null safety on web - * Image test mocks fixed for null safety +* Fix null safety on web +* Image test mocks fixed for null safety ## 0.6.0-nullsafety.0 - * Initial null safety migration. +* Initial null safety migration. ## 0.5.2 - * Added `MarkdownListItemCrossAxisAlignment` to allow for intrinsic height +* Added `MarkdownListItemCrossAxisAlignment` to allow for intrinsic height measurements of lists. ## 0.5.1 - * Fix user defined builders +* Fix user defined builders ## 0.5.0 - * BREAKING CHANGE: `MarkdownTapLinkCallback` now has three parameters, not one, exposing more +* BREAKING CHANGE: `MarkdownTapLinkCallback` now has three parameters, not one, exposing more information about a tapped link. - * Note for upgraders, the old single parameter `href` is now the second parameter to match the specification. - * Android example upgraded - * Test coverage updated to match GitHub Flavoured Markdown and CommonMark - * Handle links with empty descriptions - * Handle empty rows in tables + * Note for upgraders, the old single parameter `href` is now the second parameter to match the specification. +* Android example upgraded +* Test coverage updated to match GitHub Flavoured Markdown and CommonMark +* Handle links with empty descriptions +* Handle empty rows in tables ## 0.4.4 - * Fix handling of newline character in blockquote - * Add new example demo - * Use the start attribute in ordered list to set the first number - * Revert changes made in PR #235 (which broke newline handling) +* Fix handling of newline character in blockquote +* Add new example demo +* Use the start attribute in ordered list to set the first number +* Revert changes made in PR #235 (which broke newline handling) ## 0.4.3 - * Fix merging of `MarkdownStyleSheets` - * Fix `MarkdownStyleSheet` textScaleFactor to use default value of 1.0, if not provided, instead using the textScaleFactor of the nearest MediaQuery +* Fix merging of `MarkdownStyleSheets` +* Fix `MarkdownStyleSheet` textScaleFactor to use default value of 1.0, if not provided, instead using the textScaleFactor of the nearest MediaQuery ## 0.4.2 - * Fix parsing of image caption & alt attributes - * Fix baseline alignment in lists - * Support `LineBreakSyntax` +* Fix parsing of image caption & alt attributes +* Fix baseline alignment in lists +* Support `LineBreakSyntax` ## 0.4.1 - * Downgrade Flutter minimum from 1.17.1 to 1.17.0 for Pub +* Downgrade Flutter minimum from 1.17.1 to 1.17.0 for Pub ## 0.4.0 - * Updated for Flutter 1.17 - * Ignore newlines in paragraphs - * Improve handling of horizontal rules +* Updated for Flutter 1.17 +* Ignore newlines in paragraphs +* Improve handling of horizontal rules ## 0.3.5 - * Fix hardcoded colors and improve Darktheme - * Fix text alignment when formatting is involved +* Fix hardcoded colors and improve Darktheme +* Fix text alignment when formatting is involved ## 0.3.4 - * Add support for text paragraphs and blockquotes. +* Add support for text paragraphs and blockquotes. ## 0.3.3 - * Add the ability to control the scroll position of the `MarkdownWidget`. +* Add the ability to control the scroll position of the `MarkdownWidget`. ## 0.3.2 - * Uplift `package:markdown` dependency version to enable deleting HTML unescape URI workaround - * Explictly state that Flutter 1.10.7 is the minimum supported Flutter version in the library `pubspec.yaml`. +* Uplift `package:markdown` dependency version to enable deleting HTML unescape URI workaround +* Explictly state that Flutter 1.10.7 is the minimum supported Flutter version in the library `pubspec.yaml`. ## 0.3.1 - * Expose `tableColumnWidth` - * Add `MarkdownStyleSheet.fromCupertinoTheme` - * Fix `MarkdownStyleSheet.blockquote` - * Flutter for web support - * Add physic and shrinkWrap to Markdown widget - * Add MarkdownBody.fitContent - * Support select text to copy - * Fix list bullet alignment - * HTML unescape URIs (temporary workaround for [dart-lang/markdown #272](https://github.com/dart-lang/markdown/issues/272)) - * Rebuilt `example/android` and `example/ios` directories +* Expose `tableColumnWidth` +* Add `MarkdownStyleSheet.fromCupertinoTheme` +* Fix `MarkdownStyleSheet.blockquote` +* Flutter for web support +* Add physic and shrinkWrap to Markdown widget +* Add MarkdownBody.fitContent +* Support select text to copy +* Fix list bullet alignment +* HTML unescape URIs (temporary workaround for [dart-lang/markdown #272](https://github.com/dart-lang/markdown/issues/272)) +* Rebuilt `example/android` and `example/ios` directories **Note:** this version has an implicit minimum supported version of Flutter 1.10.7. See [flutter/flutter_markdown issue #156](https://github.com/flutter/flutter_markdown/issues/156) for more detail. ## 0.3.0 - * Support GitHub flavoured Markdown - * Support strikethrough - * Convert TextSpan to use new InlineSpan API +* Support GitHub flavoured Markdown +* Support strikethrough +* Convert TextSpan to use new InlineSpan API ## 0.2.0 - * Updated environment sdk constraints to make the package +* Updated environment sdk constraints to make the package Dart 2 compatible. As a result, usage of this version and higher requires a Dart 2 SDK. ## 0.1.6 - * Updated `markdown` dependency. +* Updated `markdown` dependency. ## 0.1.5 - * Add `mockito` as a dev dependency. Eliminate use of `package:http`, which +* Add `mockito` as a dev dependency. Eliminate use of `package:http`, which is no longer part of Flutter. ## 0.1.4 - * Add `li` style to bullets +* Add `li` style to bullets ## 0.1.3 - * Add `path` and `http` as declared dependencies in `pubspec.yaml` +* Add `path` and `http` as declared dependencies in `pubspec.yaml` ## 0.1.2 - * Add support for horizontal rules. - * Fix the `onTap` callback on images nested in hyperlinks +* Add support for horizontal rules. +* Fix the `onTap` callback on images nested in hyperlinks ## 0.1.1 - * Add support for local file paths in image links. Make sure to set the +* Add support for local file paths in image links. Make sure to set the `imageDirectory` property to specify the base directory containing the image files. ## 0.1.0 - * Roll the dependency on `markdown` to 1.0.0 - * Add a test and example for image links - * Fix the `onTap` callback on hyperlinks +* Roll the dependency on `markdown` to 1.0.0 +* Add a test and example for image links +* Fix the `onTap` callback on hyperlinks ## 0.0.9 - * First published version +* First published version diff --git a/packages/flutter_markdown/pubspec.yaml b/packages/flutter_markdown/pubspec.yaml index 04d24132024..0336c962d17 100644 --- a/packages/flutter_markdown/pubspec.yaml +++ b/packages/flutter_markdown/pubspec.yaml @@ -4,7 +4,7 @@ description: A Markdown renderer for Flutter. Create rich text output, formatted with simple Markdown tags. repository: https://github.com/flutter/packages/tree/main/packages/flutter_markdown issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_markdown%22 -version: 0.7.1 +version: 0.7.2 environment: sdk: ^3.3.0 From af9ca1b898253d97a91577dcb2a37e684d30bc3d Mon Sep 17 00:00:00 2001 From: jimmyff Date: Fri, 7 Jun 2024 15:52:00 +0100 Subject: [PATCH 3/5] Added widget test, test fails without PR and passes with --- packages/flutter_markdown/test/text_test.dart | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packages/flutter_markdown/test/text_test.dart b/packages/flutter_markdown/test/text_test.dart index 27f16cc9004..e8e8835eb2b 100644 --- a/packages/flutter_markdown/test/text_test.dart +++ b/packages/flutter_markdown/test/text_test.dart @@ -284,6 +284,50 @@ void defineTests() { }, ); + testWidgets( + 'Selectable without onSelectionChanged', + (WidgetTester tester) async { + const String data = '# abc def ghi\njkl opq'; + + await tester.pumpWidget( + const MaterialApp( + home: Material( + child: MarkdownBody( + data: data, + selectable: true, + ), + ), + ), + ); + + // Find the positions before character 'd' and 'f'. + final Offset dPos = positionInRenderedText(tester, 'abc def ghi', 4); + final Offset fPos = positionInRenderedText(tester, 'abc def ghi', 6); + // Select from 'd' until 'f'. + final TestGesture firstGesture = + await tester.startGesture(dPos, kind: PointerDeviceKind.mouse); + addTearDown(firstGesture.removePointer); + await tester.pump(); + await firstGesture.moveTo(fPos); + await firstGesture.up(); + await tester.pump(); + + // Find the positions before character 'j' and 'o'. + final Offset jPos = positionInRenderedText(tester, 'jkl opq', 0); + final Offset oPos = positionInRenderedText(tester, 'jkl opq', 4); + // Select from 'j' until 'o'. + final TestGesture secondGesture = + await tester.startGesture(jPos, kind: PointerDeviceKind.mouse); + addTearDown(secondGesture.removePointer); + await tester.pump(); + await secondGesture.moveTo(oPos); + await secondGesture.up(); + await tester.pump(); + + expect(tester.takeException(), isNull); + }, + ); + testWidgets( 'header with line of text and onSelectionChanged callback', (WidgetTester tester) async { From d970ee4c35b060b8a3171bd054314e5d48ecde36 Mon Sep 17 00:00:00 2001 From: jimmyff Date: Tue, 18 Jun 2024 09:03:34 +0100 Subject: [PATCH 4/5] Provided more detail in the changelog re: text selection fix --- packages/flutter_markdown/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_markdown/CHANGELOG.md b/packages/flutter_markdown/CHANGELOG.md index 7bc3b294182..3522fb3d7ec 100644 --- a/packages/flutter_markdown/CHANGELOG.md +++ b/packages/flutter_markdown/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.7.3 -* Fixes issue when `onSelectionChanged` is not set +* Fixes a crash caused by text selection when `selectable` is true and `onSelectionChanged` is null. ## 0.7.2 From 1f79f67dc185c2c1c0f37496e30b77fc01e6c79e Mon Sep 17 00:00:00 2001 From: jimmyff Date: Tue, 18 Jun 2024 09:06:10 +0100 Subject: [PATCH 5/5] Changed version number to 0.7.2+1 --- packages/flutter_markdown/CHANGELOG.md | 2 +- packages/flutter_markdown/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/flutter_markdown/CHANGELOG.md b/packages/flutter_markdown/CHANGELOG.md index 3522fb3d7ec..f787fabbc05 100644 --- a/packages/flutter_markdown/CHANGELOG.md +++ b/packages/flutter_markdown/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.7.3 +## 0.7.2+1 * Fixes a crash caused by text selection when `selectable` is true and `onSelectionChanged` is null. diff --git a/packages/flutter_markdown/pubspec.yaml b/packages/flutter_markdown/pubspec.yaml index ecfd21ea000..f7b58ed2888 100644 --- a/packages/flutter_markdown/pubspec.yaml +++ b/packages/flutter_markdown/pubspec.yaml @@ -4,7 +4,7 @@ description: A Markdown renderer for Flutter. Create rich text output, formatted with simple Markdown tags. repository: https://github.com/flutter/packages/tree/main/packages/flutter_markdown issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_markdown%22 -version: 0.7.3 +version: 0.7.2+1 environment: sdk: ^3.3.0