-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5181519
commit 0de1d68
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum InputBarContextMenu { | ||
copy, | ||
cut, | ||
paste, | ||
} |
40 changes: 40 additions & 0 deletions
40
lib/presentation/extensions/text_editting_controller_extension.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:fluffychat/utils/clipboard.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart' as flutter; | ||
|
||
extension TextEdittingControllerExtension on TextEditingController { | ||
Future<void> pasteText() async { | ||
final start = selection.start; | ||
final end = selection.end; | ||
final pastedText = await Clipboard.instance.pasteText(); | ||
if (pastedText != null) { | ||
if (start == -1 || end == -1) { | ||
text = pastedText + text; | ||
return; | ||
} | ||
if (start == end) { | ||
final startText = text.substring(0, start); | ||
final trailingText = text.substring(end, text.length); | ||
text = startText + pastedText + trailingText; | ||
} else { | ||
text = text.replaceRange(start, end, pastedText); | ||
} | ||
} | ||
} | ||
|
||
Future<void> copyText() async { | ||
final start = selection.start; | ||
final end = selection.end; | ||
if (start < end) { | ||
await flutter.Clipboard.setData( | ||
flutter.ClipboardData( | ||
text: text.substring(start, end), | ||
), | ||
); | ||
} | ||
} | ||
|
||
Future<void> cutText() async { | ||
//TO-DO: | ||
} | ||
} |