Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
101 lines
3.0 KiB
Dart
101 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
const _softBreak = '\u200B';
|
|
|
|
String _breakLongAsciiRuns(String text) {
|
|
final result = StringBuffer();
|
|
int? previous;
|
|
for (final rune in text.runes) {
|
|
if (previous != null &&
|
|
previous >= 0x21 &&
|
|
previous <= 0x7e &&
|
|
rune >= 0x21 &&
|
|
rune <= 0x7e) {
|
|
result.write(_softBreak);
|
|
}
|
|
result.writeCharCode(rune);
|
|
previous = rune;
|
|
}
|
|
return result.toString();
|
|
}
|
|
|
|
class _CopyPlainTextIntent extends Intent {
|
|
const _CopyPlainTextIntent();
|
|
}
|
|
|
|
/// Allows paths and other long ASCII runs to wrap without changing copied text.
|
|
class BreakableSelectableText extends StatefulWidget {
|
|
const BreakableSelectableText({
|
|
super.key,
|
|
required this.text,
|
|
required this.style,
|
|
});
|
|
|
|
final String text;
|
|
final TextStyle style;
|
|
|
|
@override
|
|
State<BreakableSelectableText> createState() =>
|
|
_BreakableSelectableTextState();
|
|
}
|
|
|
|
class _BreakableSelectableTextState extends State<BreakableSelectableText> {
|
|
TextSelection _selection = const TextSelection.collapsed(offset: -1);
|
|
|
|
void _copySelection(String displayText, TextSelection selection) {
|
|
if (!selection.isValid || selection.isCollapsed) return;
|
|
final text = selection.textInside(displayText).replaceAll(_softBreak, '');
|
|
Clipboard.setData(ClipboardData(text: text));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final displayText = _breakLongAsciiRuns(widget.text);
|
|
return Shortcuts(
|
|
shortcuts: const {
|
|
SingleActivator(LogicalKeyboardKey.keyC, meta: true):
|
|
_CopyPlainTextIntent(),
|
|
SingleActivator(LogicalKeyboardKey.keyC, control: true):
|
|
_CopyPlainTextIntent(),
|
|
},
|
|
child: Actions(
|
|
actions: {
|
|
_CopyPlainTextIntent: CallbackAction<_CopyPlainTextIntent>(
|
|
onInvoke: (_) {
|
|
_copySelection(displayText, _selection);
|
|
return null;
|
|
},
|
|
),
|
|
},
|
|
child: SelectableText(
|
|
displayText,
|
|
style: widget.style,
|
|
textAlign: TextAlign.start,
|
|
semanticsLabel: widget.text,
|
|
onSelectionChanged: (selection, _) => _selection = selection,
|
|
contextMenuBuilder: (context, editable) =>
|
|
AdaptiveTextSelectionToolbar.buttonItems(
|
|
anchors: editable.contextMenuAnchors,
|
|
buttonItems: [
|
|
for (final button in editable.contextMenuButtonItems)
|
|
if (button.type == ContextMenuButtonType.copy)
|
|
button.copyWith(
|
|
onPressed: () {
|
|
_copySelection(
|
|
displayText,
|
|
editable.textEditingValue.selection,
|
|
);
|
|
editable.hideToolbar();
|
|
},
|
|
)
|
|
else
|
|
button,
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|