Skip to content

Commit

Permalink
Merge branch 'main' into feat_workspace_view_overview
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Feb 19, 2024
2 parents 43c77d5 + 42cb032 commit 5a203ce
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ class _MentionDateBlockState extends State<MentionDateBlock> {

try {
if (timeFormat == TimeFormatPB.TwelveHour) {
return twelveHourFormat.parse(timeStr);
return twelveHourFormat.parseStrict(timeStr);
}

return twentyFourHourFormat.parse(timeStr);
return twentyFourHourFormat.parseStrict(timeStr);
} on FormatException {
Log.error("failed to parse time string ($timeStr)");
return DateTime.now();
Expand Down
5 changes: 5 additions & 0 deletions frontend/appflowy_flutter/lib/startup/startup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class FlowyRunner {
IntegrationTestHelper.rustEnvsBuilder = rustEnvsBuilder;
}

// Clear and dispose tasks from previous AppLaunch
if (getIt.isRegistered(instance: AppLauncher)) {
await getIt<AppLauncher>().dispose();
}

// Clear all the states in case of rebuilding.
await getIt.reset();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_picker.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_picker.dart';

final CommandShortcutEvent emojiShortcutEvent = CommandShortcutEvent(
key: 'Ctrl + Alt + E to show emoji picker',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:appflowy_backend/protobuf/flowy-database2/date_entities.pbenum.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
Expand Down Expand Up @@ -96,8 +97,50 @@ class _TimeTextFieldState extends State<TimeTextField> {
? _maxLengthTwelveHour
: _maxLengthTwentyFourHour,
showCounter: false,
inputFormatters: [TimeInputFormatter(widget.timeFormat)],
onSubmitted: widget.onSubmitted,
),
);
}
}

class TimeInputFormatter extends TextInputFormatter {
TimeInputFormatter(this.timeFormat);

final TimeFormatPB timeFormat;
static const int colonPosition = 2;
static const int spacePosition = 5;

@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
final oldText = oldValue.text;
final newText = newValue.text;

// If the user has typed enough for a time separator(:) and hasn't already typed
if (newText.length == colonPosition + 1 &&
oldText.length == colonPosition &&
!newText.contains(":")) {
return _formatText(newText, colonPosition, ':');
}

// If the user has typed enough for an AM/PM separator and hasn't already typed
if (timeFormat == TimeFormatPB.TwelveHour &&
newText.length == spacePosition + 1 &&
oldText.length == spacePosition &&
newText[newText.length - 1] != ' ') {
return _formatText(newText, spacePosition, ' ');
}

return newValue;
}

TextEditingValue _formatText(String text, int index, String separator) {
return TextEditingValue(
text: '${text.substring(0, index)}$separator${text.substring(index)}',
selection: TextSelection.collapsed(offset: text.length + 1),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ String languageFromLocale(Locale locale) {
switch (locale.countryCode) {
case "KU":
return "کوردی";
default:
return locale.languageCode;
}
case "de":
return "Deutsch";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FlowyTextField extends StatefulWidget {
final InputDecoration? decoration;
final TextAlignVertical? textAlignVertical;
final TextInputAction? textInputAction;
final List<TextInputFormatter>? inputFormatters;

const FlowyTextField({
super.key,
Expand Down Expand Up @@ -60,6 +61,7 @@ class FlowyTextField extends StatefulWidget {
this.decoration,
this.textAlignVertical,
this.textInputAction,
this.inputFormatters,
});

@override
Expand Down Expand Up @@ -153,6 +155,7 @@ class FlowyTextFieldState extends State<FlowyTextField> {
style: widget.textStyle ?? Theme.of(context).textTheme.bodySmall,
textAlignVertical: widget.textAlignVertical ?? TextAlignVertical.center,
keyboardType: TextInputType.multiline,
inputFormatters: widget.inputFormatters,
decoration: widget.decoration ??
InputDecoration(
constraints: widget.hintTextConstraints ??
Expand Down

0 comments on commit 5a203ce

Please sign in to comment.