Skip to content

Commit 22200b8

Browse files
authored
1. changed translation locale country code to lower case (singerdmx#946)
1 parent 206d524 commit 22200b8

File tree

9 files changed

+684
-14
lines changed

9 files changed

+684
-14
lines changed

example/assets/sample_data_nomedia.json

Lines changed: 521 additions & 0 deletions
Large diffs are not rendered by default.

example/lib/main.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter/material.dart';
2-
2+
import 'package:flutter_localizations/flutter_localizations.dart';
33
import 'pages/home_page.dart';
44

55
void main() {
@@ -30,6 +30,15 @@ class MyApp extends StatelessWidget {
3030
// closer together (more dense) than on mobile platforms.
3131
visualDensity: VisualDensity.adaptivePlatformDensity,
3232
),
33+
localizationsDelegates: [
34+
GlobalMaterialLocalizations.delegate,
35+
GlobalWidgetsLocalizations.delegate,
36+
GlobalCupertinoLocalizations.delegate,
37+
],
38+
supportedLocales: [
39+
const Locale('en', "US"),
40+
const Locale('zh', "HK"),
41+
],
3342
home: HomePage(),
3443
);
3544
}

example/lib/pages/home_page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:filesystem_picker/filesystem_picker.dart';
77
import 'package:flutter/foundation.dart';
88
import 'package:flutter/material.dart';
99
import 'package:flutter/services.dart';
10+
import 'package:flutter_quill/extensions.dart';
1011
import 'package:flutter_quill/flutter_quill.dart' hide Text;
1112
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
1213
import 'package:path/path.dart';
@@ -33,7 +34,7 @@ class _HomePageState extends State<HomePage> {
3334

3435
Future<void> _loadFromAssets() async {
3536
try {
36-
final result = await rootBundle.loadString('assets/sample_data.json');
37+
final result = await rootBundle.loadString(isDesktop() ? 'assets/sample_data_nomedia.json' : 'assets/sample_data.json');
3738
final doc = Document.fromJson(jsonDecode(result));
3839
setState(() {
3940
_controller = QuillController(

example/lib/pages/read_only_page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/foundation.dart';
22
import 'package:flutter/material.dart';
3+
import 'package:flutter_quill/extensions.dart';
34
import 'package:flutter_quill/flutter_quill.dart' hide Text;
45
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
56

@@ -19,7 +20,7 @@ class _ReadOnlyPageState extends State<ReadOnlyPage> {
1920
@override
2021
Widget build(BuildContext context) {
2122
return DemoScaffold(
22-
documentFilename: 'sample_data.json',
23+
documentFilename: isDesktop() ? 'assets/sample_data_nomedia.json' : 'sample_data_nomedia.json',
2324
builder: _buildContent,
2425
showToolbar: _edit == true,
2526
floatingActionButton: FloatingActionButton.extended(

lib/src/translations/toolbar.i18n.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ extension Localization on String {
734734
'Camera': 'Camera',
735735
'Video': 'Video',
736736
},
737-
'zh_HK': {
737+
'zh_hk': {
738738
'Paste a link': '貼上連結',
739739
'Ok': '確定',
740740
'Select Color': '選擇顏色',

lib/src/widgets/delegate.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
22
import 'package:flutter/gestures.dart';
33
import 'package:flutter/material.dart';
44
import 'package:flutter/scheduler.dart';
5+
import 'package:flutter_quill/src/utils/platform.dart';
56

67
import '../../flutter_quill.dart';
78
import 'text_selection.dart';
@@ -111,6 +112,7 @@ class EditorTextSelectionGestureDetectorBuilder {
111112
// For backwards-compatibility, we treat a null kind the same as touch.
112113
final kind = details.kind;
113114
shouldShowSelectionToolbar = kind == null ||
115+
kind == PointerDeviceKind.mouse || // this is added to enable word selection by mouse double tap
114116
kind == PointerDeviceKind.touch ||
115117
kind == PointerDeviceKind.stylus;
116118
}
@@ -178,6 +180,14 @@ class EditorTextSelectionGestureDetectorBuilder {
178180
}
179181
}
180182

183+
/// onSingleTapUp for mouse right click
184+
@protected
185+
void onSecondarySingleTapUp(TapUpDetails details) { // added to show toolbar by right click
186+
if (shouldShowSelectionToolbar) {
187+
editor!.showToolbar();
188+
}
189+
}
190+
181191
/// Handler for [EditorTextSelectionGestureDetector.onSingleTapCancel].
182192
///
183193
/// By default, it services as place holder to enable subclass override.
@@ -311,6 +321,13 @@ class EditorTextSelectionGestureDetectorBuilder {
311321
@protected
312322
void onDragSelectionEnd(DragEndDetails details) {
313323
renderEditor!.handleDragEnd(details);
324+
if (isDesktop()) { // added to show selection copy/paste toolbar after drag to select
325+
if (delegate.selectionEnabled) {
326+
if (shouldShowSelectionToolbar) {
327+
editor!.showToolbar();
328+
}
329+
}
330+
}
314331
}
315332

316333
/// Returns a [EditorTextSelectionGestureDetector] configured with
@@ -330,6 +347,10 @@ class EditorTextSelectionGestureDetectorBuilder {
330347
onSingleLongTapMoveUpdate: onSingleLongTapMoveUpdate,
331348
onSingleLongTapEnd: onSingleLongTapEnd,
332349
onDoubleTapDown: onDoubleTapDown,
350+
onSecondaryTapDown: null,
351+
onSecondarySingleTapUp: onSecondarySingleTapUp,
352+
onSecondarySingleTapCancel: null,
353+
onSecondaryDoubleTapDown: null,
333354
onDragSelectionStart: onDragSelectionStart,
334355
onDragSelectionUpdate: onDragSelectionUpdate,
335356
onDragSelectionEnd: onDragSelectionEnd,

lib/src/widgets/editor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
640640
try {
641641
if (delegate.selectionEnabled && !_isPositionSelected(details)) {
642642
final _platform = Theme.of(_state.context).platform;
643-
if (isAppleOS(_platform)) {
643+
if (isAppleOS(_platform) || isDesktop()) { // added isDesktop() to enable extend selection in Windows platform
644644
switch (details.kind) {
645645
case PointerDeviceKind.mouse:
646646
case PointerDeviceKind.stylus:

lib/src/widgets/raw_editor.dart

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,21 @@ class RawEditorState extends EditorState
362362

363363
return QuillStyles(
364364
data: _styles!,
365-
child: Actions(
366-
actions: _actions,
367-
child: Focus(
368-
focusNode: widget.focusNode,
369-
child: QuillKeyboardListener(
370-
child: Container(
371-
constraints: constraints,
372-
child: child,
365+
child: Shortcuts(
366+
shortcuts: <LogicalKeySet, Intent>{ // shortcuts added for Windows platform
367+
LogicalKeySet(LogicalKeyboardKey.escape): HideSelectionToolbarIntent(),
368+
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyZ): const UndoTextIntent(SelectionChangedCause.keyboard),
369+
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyY): const RedoTextIntent(SelectionChangedCause.keyboard),
370+
},
371+
child: Actions(
372+
actions: _actions,
373+
child: Focus(
374+
focusNode: widget.focusNode,
375+
child: QuillKeyboardListener(
376+
child: Container(
377+
constraints: constraints,
378+
child: child,
379+
),
373380
),
374381
),
375382
),
@@ -1172,6 +1179,10 @@ class RawEditorState extends EditorState
11721179
CopySelectionTextIntent: _makeOverridable(_CopySelectionAction(this)),
11731180
PasteTextIntent: _makeOverridable(CallbackAction<PasteTextIntent>(
11741181
onInvoke: (intent) => pasteText(intent.cause))),
1182+
1183+
HideSelectionToolbarIntent: _makeOverridable(_HideSelectionToolbarAction(this)),
1184+
UndoTextIntent: _makeOverridable(_UndoKeyboardAction(this)),
1185+
RedoTextIntent: _makeOverridable(_RedoKeyboardAction(this)),
11751186
};
11761187

11771188
@override
@@ -1868,3 +1879,56 @@ class _CopySelectionAction extends ContextAction<CopySelectionTextIntent> {
18681879
state.textEditingValue.selection.isValid &&
18691880
!state.textEditingValue.selection.isCollapsed;
18701881
}
1882+
1883+
// intent class for "escape" key to dismiss selection toolbar in Windows platform
1884+
class HideSelectionToolbarIntent extends Intent {
1885+
const HideSelectionToolbarIntent();
1886+
}
1887+
1888+
class _HideSelectionToolbarAction extends ContextAction<HideSelectionToolbarIntent> {
1889+
_HideSelectionToolbarAction(this.state);
1890+
1891+
final RawEditorState state;
1892+
1893+
@override
1894+
void invoke(HideSelectionToolbarIntent intent, [BuildContext? context]) {
1895+
state.hideToolbar();
1896+
}
1897+
1898+
@override
1899+
bool get isActionEnabled =>
1900+
state.textEditingValue.selection.isValid;
1901+
}
1902+
1903+
class _UndoKeyboardAction extends ContextAction<UndoTextIntent> {
1904+
_UndoKeyboardAction(this.state);
1905+
1906+
final RawEditorState state;
1907+
1908+
@override
1909+
void invoke(UndoTextIntent intent, [BuildContext? context]) {
1910+
if (state.controller.hasUndo) {
1911+
state.controller.undo();
1912+
}
1913+
}
1914+
1915+
@override
1916+
bool get isActionEnabled => true;
1917+
}
1918+
1919+
class _RedoKeyboardAction extends ContextAction<RedoTextIntent> {
1920+
_RedoKeyboardAction(this.state);
1921+
1922+
final RawEditorState state;
1923+
1924+
@override
1925+
void invoke(RedoTextIntent intent, [BuildContext? context]) {
1926+
if (state.controller.hasRedo) {
1927+
state.controller.redo();
1928+
}
1929+
}
1930+
1931+
@override
1932+
bool get isActionEnabled => true;
1933+
}
1934+

lib/src/widgets/text_selection.dart

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,10 @@ class EditorTextSelectionGestureDetector extends StatefulWidget {
695695
this.onForcePressEnd,
696696
this.onSingleTapUp,
697697
this.onSingleTapCancel,
698+
this.onSecondaryTapDown,
699+
this.onSecondarySingleTapUp,
700+
this.onSecondarySingleTapCancel,
701+
this.onSecondaryDoubleTapDown,
698702
this.onSingleLongTapStart,
699703
this.onSingleLongTapMoveUpdate,
700704
this.onSingleLongTapEnd,
@@ -730,6 +734,15 @@ class EditorTextSelectionGestureDetector extends StatefulWidget {
730734
/// another gesture from the touch is recognized.
731735
final GestureTapCancelCallback? onSingleTapCancel;
732736

737+
/// onTapDown for mouse right click
738+
final GestureTapDownCallback? onSecondaryTapDown;
739+
/// onTapUp for mouse right click
740+
final GestureTapUpCallback? onSecondarySingleTapUp;
741+
/// onTapCancel for mouse right click
742+
final GestureTapCancelCallback? onSecondarySingleTapCancel;
743+
/// onDoubleTap for mouse right click
744+
final GestureTapDownCallback? onSecondaryDoubleTapDown;
745+
733746
/// Called for a single long tap that's sustained for longer than
734747
/// [kLongPressTimeout] but not necessarily lifted. Not called for a
735748
/// double-tap-hold, which calls [onDoubleTapDown] instead.
@@ -781,6 +794,9 @@ class _EditorTextSelectionGestureDetectorState
781794
// subsequent tap up / tap hold of the same tap.
782795
bool _isDoubleTap = false;
783796

797+
// _isDoubleTap for mouse right click
798+
bool _isSecondaryDoubleTap = false;
799+
784800
@override
785801
void dispose() {
786802
_doubleTapTimer?.cancel();
@@ -829,6 +845,40 @@ class _EditorTextSelectionGestureDetectorState
829845
}
830846
}
831847

848+
// added secondary tap function for mouse right click to show toolbar
849+
void _handleSecondaryTapDown(TapDownDetails details) {
850+
if (widget.onSecondaryTapDown != null) {
851+
widget.onSecondaryTapDown!(details);
852+
}
853+
if (_doubleTapTimer != null &&
854+
_isWithinDoubleTapTolerance(details.globalPosition)) {
855+
if (widget.onSecondaryDoubleTapDown != null) {
856+
widget.onSecondaryDoubleTapDown!(details);
857+
}
858+
859+
_doubleTapTimer!.cancel();
860+
_doubleTapTimeout();
861+
_isDoubleTap = true;
862+
}
863+
}
864+
865+
void _handleSecondaryTapUp(TapUpDetails details) {
866+
if (!_isSecondaryDoubleTap) {
867+
if (widget.onSecondarySingleTapUp != null) {
868+
widget.onSecondarySingleTapUp!(details);
869+
}
870+
_lastTapOffset = details.globalPosition;
871+
_doubleTapTimer = Timer(kDoubleTapTimeout, _doubleTapTimeout);
872+
}
873+
_isSecondaryDoubleTap = false;
874+
}
875+
876+
void _handleSecondaryTapCancel() {
877+
if (widget.onSecondarySingleTapCancel != null) {
878+
widget.onSecondarySingleTapCancel!();
879+
}
880+
}
881+
832882
DragStartDetails? _lastDragStartDetails;
833883
DragUpdateDetails? _lastDragUpdateDetails;
834884
Timer? _dragUpdateThrottleTimer;
@@ -940,7 +990,10 @@ class _EditorTextSelectionGestureDetectorState
940990
instance
941991
..onTapDown = _handleTapDown
942992
..onTapUp = _handleTapUp
943-
..onTapCancel = _handleTapCancel;
993+
..onTapCancel = _handleTapCancel
994+
..onSecondaryTapDown = _handleSecondaryTapDown
995+
..onSecondaryTapUp = _handleSecondaryTapUp
996+
..onSecondaryTapCancel = _handleSecondaryTapCancel;
944997
},
945998
);
946999

0 commit comments

Comments
 (0)