Skip to content

Custom hint style + border style for link dialog + Toggle tool bar when user single tap at same position #2592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion lib/src/editor/editor.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:math' as math;

import 'package:flutter/cupertino.dart'
Expand Down Expand Up @@ -221,6 +222,20 @@ class QuillEditorState extends State<QuillEditor>
_editorKey.currentState?.hideToolbar();
}
});

controller.addListener(_controllerListener);
}

@override
void dispose() {
controller.removeListener(_controllerListener);
_selectionGestureDetectorBuilder.dispose();
super.dispose();
}

void _controllerListener() {
final position = controller.selection.extentOffset;
_selectionGestureDetectorBuilder.setCurrentCursorPosition(position);
}

@override
Expand Down Expand Up @@ -499,6 +514,45 @@ class _QuillEditorSelectionGestureDetectorBuilder
pressed.contains(LogicalKeyboardKey.shiftRight));
}

int? _previousCursorPosition;
int? _currentCursorPosition;

Timer? _timer;

@override
void dispose() {
_timer?.cancel();
super.dispose();
}

@override
void setCurrentCursorPosition(int? position) {
if (_currentCursorPosition != null) {
_previousCursorPosition = _currentCursorPosition;
}

_currentCursorPosition = position;
}

void _handleToggleToolbar() {
final position = renderEditor!.selection.extentOffset;

final shouldShow = _currentCursorPosition != null &&
_currentCursorPosition == _previousCursorPosition;

_currentCursorPosition = position;
_previousCursorPosition = position;

if (shouldShow) {
SchedulerBinding.instance.addPostFrameCallback((_) {
editor!.showToolbar();
_currentCursorPosition = null;
});
} else {
editor!.hideToolbar();
}
}

@override
void onSingleTapUp(TapUpDetails details) {
if (_state.config.onTapUp != null &&
Expand All @@ -510,7 +564,8 @@ class _QuillEditorSelectionGestureDetectorBuilder
return;
}

editor!.hideToolbar();
_timer?.cancel();
_timer = Timer(const Duration(milliseconds: 100), _handleToggleToolbar);

try {
if (delegate.selectionEnabled && !_isPositionSelected(details)) {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/editor/widgets/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,8 @@ class EditorTextSelectionGestureDetectorBuilder {
child: child,
);
}

void dispose() {}

void setCurrentCursorPosition(int? position) {}
}
122 changes: 63 additions & 59 deletions lib/src/l10n/generated/quill_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ import 'quill_localizations_zh.dart';
/// property.
abstract class FlutterQuillLocalizations {
FlutterQuillLocalizations(String locale)
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
: localeName = intl.Intl.canonicalizedLocale(locale.toString());

final String localeName;

static FlutterQuillLocalizations? of(BuildContext context) {
return Localizations.of<FlutterQuillLocalizations>(
context, FlutterQuillLocalizations);
context,
FlutterQuillLocalizations,
);
}

static const LocalizationsDelegate<FlutterQuillLocalizations> delegate =
Expand All @@ -130,11 +132,11 @@ abstract class FlutterQuillLocalizations {
/// of delegates is preferred or required.
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
<LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];

/// A list of this localizations delegate's supported locales.
static const List<Locale> supportedLocales = <Locale>[
Expand Down Expand Up @@ -188,7 +190,7 @@ abstract class FlutterQuillLocalizations {
Locale('vi'),
Locale('zh'),
Locale('zh', 'CN'),
Locale('zh', 'HK')
Locale('zh', 'HK'),
];

/// No description provided for @pasteLink.
Expand Down Expand Up @@ -835,57 +837,58 @@ class _FlutterQuillLocalizationsDelegate
@override
Future<FlutterQuillLocalizations> load(Locale locale) {
return SynchronousFuture<FlutterQuillLocalizations>(
lookupFlutterQuillLocalizations(locale));
lookupFlutterQuillLocalizations(locale),
);
}

@override
bool isSupported(Locale locale) => <String>[
'ar',
'bg',
'bn',
'bs',
'ca',
'cs',
'da',
'de',
'el',
'en',
'es',
'fa',
'fi',
'fr',
'gu',
'he',
'hi',
'hr',
'hu',
'id',
'it',
'ja',
'km',
'ko',
'ku',
'mk',
'ms',
'ne',
'nl',
'no',
'pl',
'pt',
'ro',
'ru',
'sk',
'sr',
'sv',
'sw',
'th',
'tk',
'tr',
'uk',
'ur',
'vi',
'zh'
].contains(locale.languageCode);
'ar',
'bg',
'bn',
'bs',
'ca',
'cs',
'da',
'de',
'el',
'en',
'es',
'fa',
'fi',
'fr',
'gu',
'he',
'hi',
'hr',
'hu',
'id',
'it',
'ja',
'km',
'ko',
'ku',
'mk',
'ms',
'ne',
'nl',
'no',
'pl',
'pt',
'ro',
'ru',
'sk',
'sr',
'sv',
'sw',
'th',
'tk',
'tr',
'uk',
'ur',
'vi',
'zh',
].contains(locale.languageCode);

@override
bool shouldReload(_FlutterQuillLocalizationsDelegate old) => false;
Expand Down Expand Up @@ -1033,8 +1036,9 @@ FlutterQuillLocalizations lookupFlutterQuillLocalizations(Locale locale) {
}

throw FlutterError(
'FlutterQuillLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.');
'FlutterQuillLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.',
);
}
8 changes: 8 additions & 0 deletions lib/src/toolbar/buttons/link_style/link_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ class LinkDialogState extends State<LinkDialog> {
decoration: InputDecoration(
labelText: context.loc.text,
hintText: context.loc.pleaseEnterTextForYourLink,
hintStyle: widget.dialogTheme?.inputHintTextStyle,
labelStyle: widget.dialogTheme?.labelTextStyle,
floatingLabelStyle: widget.dialogTheme?.labelTextStyle,
border: widget.dialogTheme?.inputBorder,
enabledBorder: widget.dialogTheme?.inputBorder,
focusedBorder: widget.dialogTheme?.inputFocusedBorder,
),
autofocus: true,
onChanged: _textChanged,
Expand All @@ -98,8 +102,12 @@ class LinkDialogState extends State<LinkDialog> {
decoration: InputDecoration(
labelText: context.loc.link,
hintText: context.loc.pleaseEnterTheLinkURL,
hintStyle: widget.dialogTheme?.inputHintTextStyle,
labelStyle: widget.dialogTheme?.labelTextStyle,
floatingLabelStyle: widget.dialogTheme?.labelTextStyle,
border: widget.dialogTheme?.inputBorder,
enabledBorder: widget.dialogTheme?.inputBorder,
focusedBorder: widget.dialogTheme?.inputFocusedBorder,
),
onChanged: _linkChanged,
controller: _linkController,
Expand Down
12 changes: 12 additions & 0 deletions lib/src/toolbar/theme/quill_dialog_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class QuillDialogTheme with Diagnosticable {
this.buttonTextStyle,
this.labelTextStyle,
this.inputTextStyle,
this.inputHintTextStyle,
this.inputBorder,
this.inputFocusedBorder,
this.dialogBackgroundColor,
this.shape,
this.buttonStyle,
Expand All @@ -29,6 +32,15 @@ class QuillDialogTheme with Diagnosticable {
///The text style to use for the input text shown in the link-input dialog
final TextStyle? inputTextStyle;

/// The text style to use for the hint text shown in the input text field
final TextStyle? inputHintTextStyle;

/// The border to use for the input text field
final InputBorder? inputBorder;

/// The border to use for the focused input text field
final InputBorder? inputFocusedBorder;

///The background color for the Quill dialog
final Color? dialogBackgroundColor;

Expand Down
Loading