Skip to content

Commit

Permalink
Allow quoting selected text from post/comment reply (thunder-app#1374)
Browse files Browse the repository at this point in the history
* Allow quoting selected text from post/comment reply

* Update package

* Update markdown package reference
  • Loading branch information
micahmo authored Jul 2, 2024
1 parent 3406504 commit 65a574b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/comment/view/create_comment_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ class _CreateCommentPageState extends State<CreateCommentPage> {
/// The ID of the post we're responding to
int? postId;

// The ID of the comment we're responding to
/// The ID of the comment we're responding to
int? parentCommentId;

/// Contains the text that is currently being selected in the post/comment that we are replying to
String? replyViewSelection;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -328,6 +331,7 @@ class _CreateCommentPageState extends State<CreateCommentPage> {
showExpandableButton: false,
selectable: true,
showReplyEditorButtons: true,
onSelectionChanged: (selection) => replyViewSelection = selection,
),
),
),
Expand All @@ -354,6 +358,7 @@ class _CreateCommentPageState extends State<CreateCommentPage> {
disableActions: true,
selectable: true,
showReplyEditorButtons: true,
onSelectionChanged: (selection) => replyViewSelection = selection,
),
),
),
Expand Down Expand Up @@ -469,6 +474,7 @@ class _CreateCommentPageState extends State<CreateCommentPage> {
String imagePath = await selectImageToUpload();
if (context.mounted) context.read<CreateCommentCubit>().uploadImage(imagePath);
},
getAlternativeSelection: () => replyViewSelection,
),
),
),
Expand Down
3 changes: 3 additions & 0 deletions lib/post/widgets/post_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class PostSubview extends StatefulWidget {
final bool showExpandableButton;
final bool selectable;
final bool showReplyEditorButtons;
final void Function(String? selection)? onSelectionChanged;

const PostSubview({
super.key,
Expand All @@ -67,6 +68,7 @@ class PostSubview extends StatefulWidget {
this.showExpandableButton = true,
this.selectable = false,
this.showReplyEditorButtons = false,
this.onSelectionChanged,
});

@override
Expand Down Expand Up @@ -200,6 +202,7 @@ class _PostSubviewState extends State<PostSubview> with SingleTickerProviderStat
anchors: selectableRegionState.contextMenuAnchors,
);
},
onSelectionChanged: (value) => widget.onSelectionChanged?.call(value?.plainText),
child: child,
);
},
Expand Down
3 changes: 3 additions & 0 deletions lib/shared/comment_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CommentContent extends StatefulWidget {
final void Function() onViewSourceToggled;
final bool selectable;
final bool showReplyEditorButtons;
final void Function(String? selection)? onSelectionChanged;

const CommentContent({
super.key,
Expand All @@ -54,6 +55,7 @@ class CommentContent extends StatefulWidget {
required this.onViewSourceToggled,
this.selectable = false,
this.showReplyEditorButtons = false,
this.onSelectionChanged,
});

@override
Expand Down Expand Up @@ -130,6 +132,7 @@ class _CommentContentState extends State<CommentContent> with SingleTickerProvid
anchors: selectableRegionState.contextMenuAnchors,
);
},
onSelectionChanged: (value) => widget.onSelectionChanged?.call(value?.plainText),
child: child,
);
},
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "3196471d8e1b26873aecaf04254043cf9817bbe3"
resolved-ref: "3196471d8e1b26873aecaf04254043cf9817bbe3"
ref: "514e3718a42d4398619d66b6ac1ccd53bafd9b3f"
resolved-ref: "514e3718a42d4398619d66b6ac1ccd53bafd9b3f"
url: "https://github.com/thunder-app/markdown-editor.git"
source: git
version: "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
markdown_editor:
git:
url: https://github.com/thunder-app/markdown-editor.git
ref: 3196471d8e1b26873aecaf04254043cf9817bbe3
ref: 514e3718a42d4398619d66b6ac1ccd53bafd9b3f
lemmy_api_client:
git:
url: https://github.com/thunder-app/lemmy_api_client.git
Expand Down

0 comments on commit 65a574b

Please sign in to comment.