Skip to content

Commit

Permalink
feat: spell check for post form (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon authored Oct 29, 2024
1 parent 3b026b1 commit 04f1cd7
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/i18n/aria/aria.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ emojiPickerUseDialog: "Display emoji picker as dialog"
enableEmojiFadeIn: "Enable fade-in animations for custom emojis"
enableFederation: "Enable federation"
enablePredictiveBack: "Enable predictive back animations"
enableSpellCheck: "Enable spell check"
endpoint: "Endpoint"
expandNote: "Expand note"
extraMentionsWarning: "This note includes mentions that are not included in the target note of reply"
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/strings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// To regenerate, run: `dart run slang`
///
/// Locales: 31
/// Strings: 54621 (1761 per locale)
/// Strings: 54622 (1762 per locale)
// coverage:ignore-file
// ignore_for_file: type=lint, unused_import
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/strings_en_US.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class TranslationsAriaEnUs {
String get enableEmojiFadeIn => 'Enable fade-in animations for custom emojis';
String get enableFederation => 'Enable federation';
String get enablePredictiveBack => 'Enable predictive back animations';
String get enableSpellCheck => 'Enable spell check';
String get endpoint => 'Endpoint';
String get expandNote => 'Expand note';
String get extraMentionsWarning => 'This note includes mentions that are not included in the target note of reply';
Expand Down
1 change: 1 addition & 0 deletions lib/model/general_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class GeneralSettings with _$GeneralSettings {
@Default(true) bool confirmBeforeFollow,
@Default(false) bool confirmWhenRevealingSensitiveMedia,
@Default(LaunchMode.externalApplication) LaunchMode launchMode,
@Default(false) bool enableSpellCheck,
@Default(false) bool enablePredictiveBack,

// Theme
Expand Down
24 changes: 23 additions & 1 deletion lib/model/general_settings.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ mixin _$GeneralSettings {
bool get confirmWhenRevealingSensitiveMedia =>
throw _privateConstructorUsedError;
LaunchMode get launchMode => throw _privateConstructorUsedError;
bool get enableSpellCheck => throw _privateConstructorUsedError;
bool get enablePredictiveBack => throw _privateConstructorUsedError; // Theme
ThemeMode get themeMode => throw _privateConstructorUsedError;
String get lightThemeId => throw _privateConstructorUsedError;
Expand Down Expand Up @@ -216,6 +217,7 @@ abstract class $GeneralSettingsCopyWith<$Res> {
bool confirmBeforeFollow,
bool confirmWhenRevealingSensitiveMedia,
LaunchMode launchMode,
bool enableSpellCheck,
bool enablePredictiveBack,
ThemeMode themeMode,
String lightThemeId,
Expand Down Expand Up @@ -316,6 +318,7 @@ class _$GeneralSettingsCopyWithImpl<$Res, $Val extends GeneralSettings>
Object? confirmBeforeFollow = null,
Object? confirmWhenRevealingSensitiveMedia = null,
Object? launchMode = null,
Object? enableSpellCheck = null,
Object? enablePredictiveBack = null,
Object? themeMode = null,
Object? lightThemeId = null,
Expand Down Expand Up @@ -640,6 +643,10 @@ class _$GeneralSettingsCopyWithImpl<$Res, $Val extends GeneralSettings>
? _value.launchMode
: launchMode // ignore: cast_nullable_to_non_nullable
as LaunchMode,
enableSpellCheck: null == enableSpellCheck
? _value.enableSpellCheck
: enableSpellCheck // ignore: cast_nullable_to_non_nullable
as bool,
enablePredictiveBack: null == enablePredictiveBack
? _value.enablePredictiveBack
: enablePredictiveBack // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -749,6 +756,7 @@ abstract class _$$GeneralSettingsImplCopyWith<$Res>
bool confirmBeforeFollow,
bool confirmWhenRevealingSensitiveMedia,
LaunchMode launchMode,
bool enableSpellCheck,
bool enablePredictiveBack,
ThemeMode themeMode,
String lightThemeId,
Expand Down Expand Up @@ -847,6 +855,7 @@ class __$$GeneralSettingsImplCopyWithImpl<$Res>
Object? confirmBeforeFollow = null,
Object? confirmWhenRevealingSensitiveMedia = null,
Object? launchMode = null,
Object? enableSpellCheck = null,
Object? enablePredictiveBack = null,
Object? themeMode = null,
Object? lightThemeId = null,
Expand Down Expand Up @@ -1171,6 +1180,10 @@ class __$$GeneralSettingsImplCopyWithImpl<$Res>
? _value.launchMode
: launchMode // ignore: cast_nullable_to_non_nullable
as LaunchMode,
enableSpellCheck: null == enableSpellCheck
? _value.enableSpellCheck
: enableSpellCheck // ignore: cast_nullable_to_non_nullable
as bool,
enablePredictiveBack: null == enablePredictiveBack
? _value.enablePredictiveBack
: enablePredictiveBack // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -1276,6 +1289,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings {
this.confirmBeforeFollow = true,
this.confirmWhenRevealingSensitiveMedia = false,
this.launchMode = LaunchMode.externalApplication,
this.enableSpellCheck = false,
this.enablePredictiveBack = false,
this.themeMode = ThemeMode.system,
this.lightThemeId = 'a58a0abb-ff8c-476a-8dec-0ad7837e7e96',
Expand Down Expand Up @@ -1535,6 +1549,9 @@ class _$GeneralSettingsImpl implements _GeneralSettings {
final LaunchMode launchMode;
@override
@JsonKey()
final bool enableSpellCheck;
@override
@JsonKey()
final bool enablePredictiveBack;
// Theme
@override
Expand All @@ -1549,7 +1566,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings {

@override
String toString() {
return 'GeneralSettings(locale: $locale, collapseRenotes: $collapseRenotes, sensitive: $sensitive, highlightSensitiveMedia: $highlightSensitiveMedia, animatedMfm: $animatedMfm, advancedMfm: $advancedMfm, showReactionsCount: $showReactionsCount, loadRawImages: $loadRawImages, instanceTicker: $instanceTicker, showNoteCreatedAt: $showNoteCreatedAt, showAvatarsInNote: $showAvatarsInNote, showAvatarsInSubNote: $showAvatarsInSubNote, squareAvatars: $squareAvatars, showAvatarDecorations: $showAvatarDecorations, showQuoteButtonInNoteFooter: $showQuoteButtonInNoteFooter, showLikeButtonInNoteFooter: $showLikeButtonInNoteFooter, showClipButtonInNoteFooter: $showClipButtonInNoteFooter, showTranslateButtonInNoteFooter: $showTranslateButtonInNoteFooter, showNoteReactionsViewer: $showNoteReactionsViewer, showSubNoteReactionsViewer: $showSubNoteReactionsViewer, showNoteFooter: $showNoteFooter, showSubNoteFooter: $showSubNoteFooter, alwaysExpandCw: $alwaysExpandCw, alwaysExpandLongNote: $alwaysExpandLongNote, alwaysExpandMediaInSubNote: $alwaysExpandMediaInSubNote, mergeReactionsByName: $mergeReactionsByName, alwaysShowAllReactions: $alwaysShowAllReactions, mediaListWithOneImageAppearance: $mediaListWithOneImageAppearance, thumbnailBoxFit: $thumbnailBoxFit, emojiStyle: $emojiStyle, fontFamily: $fontFamily, fontSize: $fontSize, lineHeight: $lineHeight, avatarScale: $avatarScale, reactionsDisplayScale: $reactionsDisplayScale, limitWidthOfReaction: $limitWidthOfReaction, noteFooterScale: $noteFooterScale, noteVerticalPadding: $noteVerticalPadding, noteHorizontalPadding: $noteHorizontalPadding, publicNoteBackgroundColor: $publicNoteBackgroundColor, homeNoteBackgroundColor: $homeNoteBackgroundColor, followersNoteBackgroundColor: $followersNoteBackgroundColor, specifiedNoteBackgroundColor: $specifiedNoteBackgroundColor, emojiPickerUseDialog: $emojiPickerUseDialog, emojiPickerScale: $emojiPickerScale, emojiPickerAutofocus: $emojiPickerAutofocus, emojiPickerKeepOpen: $emojiPickerKeepOpen, dataSaverMedia: $dataSaverMedia, dataSaverAvatar: $dataSaverAvatar, dataSaverUrlPreview: $dataSaverUrlPreview, disableDataSaverWhenOnWifi: $disableDataSaverWhenOnWifi, reduceAnimation: $reduceAnimation, disableShowingAnimatedImages: $disableShowingAnimatedImages, enableEmojiFadeIn: $enableEmojiFadeIn, forceShowAds: $forceShowAds, useGroupedNotifications: $useGroupedNotifications, showTimelineTabBarAtBottom: $showTimelineTabBarAtBottom, showMenuButtonInTabBar: $showMenuButtonInTabBar, timelinesPageButtonTypes: $timelinesPageButtonTypes, showSmallTimelinesPageButtons: $showSmallTimelinesPageButtons, showSquaredTimelinesPageButtons: $showSquaredTimelinesPageButtons, showTabHeaderInOneLine: $showTabHeaderInOneLine, alwaysShowTabHeader: $alwaysShowTabHeader, showTimelineLastViewedAt: $showTimelineLastViewedAt, showPopupOnNewNote: $showPopupOnNewNote, vibrateNote: $vibrateNote, vibrateNotification: $vibrateNotification, enableInfiniteScroll: $enableInfiniteScroll, keepScreenOn: $keepScreenOn, enableHorizontalSwipe: $enableHorizontalSwipe, openSensitiveMediaOnDoubleTap: $openSensitiveMediaOnDoubleTap, noteTapAction: $noteTapAction, noteDoubleTapAction: $noteDoubleTapAction, noteLongPressAction: $noteLongPressAction, confirmBeforePost: $confirmBeforePost, confirmBeforeReact: $confirmBeforeReact, confirmBeforeFollow: $confirmBeforeFollow, confirmWhenRevealingSensitiveMedia: $confirmWhenRevealingSensitiveMedia, launchMode: $launchMode, enablePredictiveBack: $enablePredictiveBack, themeMode: $themeMode, lightThemeId: $lightThemeId, darkThemeId: $darkThemeId)';
return 'GeneralSettings(locale: $locale, collapseRenotes: $collapseRenotes, sensitive: $sensitive, highlightSensitiveMedia: $highlightSensitiveMedia, animatedMfm: $animatedMfm, advancedMfm: $advancedMfm, showReactionsCount: $showReactionsCount, loadRawImages: $loadRawImages, instanceTicker: $instanceTicker, showNoteCreatedAt: $showNoteCreatedAt, showAvatarsInNote: $showAvatarsInNote, showAvatarsInSubNote: $showAvatarsInSubNote, squareAvatars: $squareAvatars, showAvatarDecorations: $showAvatarDecorations, showQuoteButtonInNoteFooter: $showQuoteButtonInNoteFooter, showLikeButtonInNoteFooter: $showLikeButtonInNoteFooter, showClipButtonInNoteFooter: $showClipButtonInNoteFooter, showTranslateButtonInNoteFooter: $showTranslateButtonInNoteFooter, showNoteReactionsViewer: $showNoteReactionsViewer, showSubNoteReactionsViewer: $showSubNoteReactionsViewer, showNoteFooter: $showNoteFooter, showSubNoteFooter: $showSubNoteFooter, alwaysExpandCw: $alwaysExpandCw, alwaysExpandLongNote: $alwaysExpandLongNote, alwaysExpandMediaInSubNote: $alwaysExpandMediaInSubNote, mergeReactionsByName: $mergeReactionsByName, alwaysShowAllReactions: $alwaysShowAllReactions, mediaListWithOneImageAppearance: $mediaListWithOneImageAppearance, thumbnailBoxFit: $thumbnailBoxFit, emojiStyle: $emojiStyle, fontFamily: $fontFamily, fontSize: $fontSize, lineHeight: $lineHeight, avatarScale: $avatarScale, reactionsDisplayScale: $reactionsDisplayScale, limitWidthOfReaction: $limitWidthOfReaction, noteFooterScale: $noteFooterScale, noteVerticalPadding: $noteVerticalPadding, noteHorizontalPadding: $noteHorizontalPadding, publicNoteBackgroundColor: $publicNoteBackgroundColor, homeNoteBackgroundColor: $homeNoteBackgroundColor, followersNoteBackgroundColor: $followersNoteBackgroundColor, specifiedNoteBackgroundColor: $specifiedNoteBackgroundColor, emojiPickerUseDialog: $emojiPickerUseDialog, emojiPickerScale: $emojiPickerScale, emojiPickerAutofocus: $emojiPickerAutofocus, emojiPickerKeepOpen: $emojiPickerKeepOpen, dataSaverMedia: $dataSaverMedia, dataSaverAvatar: $dataSaverAvatar, dataSaverUrlPreview: $dataSaverUrlPreview, disableDataSaverWhenOnWifi: $disableDataSaverWhenOnWifi, reduceAnimation: $reduceAnimation, disableShowingAnimatedImages: $disableShowingAnimatedImages, enableEmojiFadeIn: $enableEmojiFadeIn, forceShowAds: $forceShowAds, useGroupedNotifications: $useGroupedNotifications, showTimelineTabBarAtBottom: $showTimelineTabBarAtBottom, showMenuButtonInTabBar: $showMenuButtonInTabBar, timelinesPageButtonTypes: $timelinesPageButtonTypes, showSmallTimelinesPageButtons: $showSmallTimelinesPageButtons, showSquaredTimelinesPageButtons: $showSquaredTimelinesPageButtons, showTabHeaderInOneLine: $showTabHeaderInOneLine, alwaysShowTabHeader: $alwaysShowTabHeader, showTimelineLastViewedAt: $showTimelineLastViewedAt, showPopupOnNewNote: $showPopupOnNewNote, vibrateNote: $vibrateNote, vibrateNotification: $vibrateNotification, enableInfiniteScroll: $enableInfiniteScroll, keepScreenOn: $keepScreenOn, enableHorizontalSwipe: $enableHorizontalSwipe, openSensitiveMediaOnDoubleTap: $openSensitiveMediaOnDoubleTap, noteTapAction: $noteTapAction, noteDoubleTapAction: $noteDoubleTapAction, noteLongPressAction: $noteLongPressAction, confirmBeforePost: $confirmBeforePost, confirmBeforeReact: $confirmBeforeReact, confirmBeforeFollow: $confirmBeforeFollow, confirmWhenRevealingSensitiveMedia: $confirmWhenRevealingSensitiveMedia, launchMode: $launchMode, enableSpellCheck: $enableSpellCheck, enablePredictiveBack: $enablePredictiveBack, themeMode: $themeMode, lightThemeId: $lightThemeId, darkThemeId: $darkThemeId)';
}

@override
Expand Down Expand Up @@ -1666,6 +1683,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings {
(identical(other.confirmBeforeFollow, confirmBeforeFollow) || other.confirmBeforeFollow == confirmBeforeFollow) &&
(identical(other.confirmWhenRevealingSensitiveMedia, confirmWhenRevealingSensitiveMedia) || other.confirmWhenRevealingSensitiveMedia == confirmWhenRevealingSensitiveMedia) &&
(identical(other.launchMode, launchMode) || other.launchMode == launchMode) &&
(identical(other.enableSpellCheck, enableSpellCheck) || other.enableSpellCheck == enableSpellCheck) &&
(identical(other.enablePredictiveBack, enablePredictiveBack) || other.enablePredictiveBack == enablePredictiveBack) &&
(identical(other.themeMode, themeMode) || other.themeMode == themeMode) &&
(identical(other.lightThemeId, lightThemeId) || other.lightThemeId == lightThemeId) &&
Expand Down Expand Up @@ -1755,6 +1773,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings {
confirmBeforeFollow,
confirmWhenRevealingSensitiveMedia,
launchMode,
enableSpellCheck,
enablePredictiveBack,
themeMode,
lightThemeId,
Expand Down Expand Up @@ -1860,6 +1879,7 @@ abstract class _GeneralSettings implements GeneralSettings {
final bool confirmBeforeFollow,
final bool confirmWhenRevealingSensitiveMedia,
final LaunchMode launchMode,
final bool enableSpellCheck,
final bool enablePredictiveBack,
final ThemeMode themeMode,
final String lightThemeId,
Expand Down Expand Up @@ -2034,6 +2054,8 @@ abstract class _GeneralSettings implements GeneralSettings {
@override
LaunchMode get launchMode;
@override
bool get enableSpellCheck;
@override
bool get enablePredictiveBack; // Theme
@override
ThemeMode get themeMode;
Expand Down
2 changes: 2 additions & 0 deletions lib/model/general_settings.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/provider/general_settings_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ class GeneralSettingsNotifier extends _$GeneralSettingsNotifier {
await _save();
}

Future<void> setEnableSpellCheck(bool enableSpellCheck) async {
state = state.copyWith(enableSpellCheck: enableSpellCheck);
await _save();
}

Future<void> setEnablePredictiveBack(bool enablePredictiveBack) async {
state = state.copyWith(enablePredictiveBack: enablePredictiveBack);
await _save();
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/general_settings_notifier_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions lib/view/page/settings/behavior_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ class BehaviorPage extends ConsumerWidget {
}
},
),
if (defaultTargetPlatform
case TargetPlatform.android || TargetPlatform.iOS)
SwitchListTile(
title: Text(t.aria.enableSpellCheck),
value: settings.enableSpellCheck,
onChanged: (value) => ref
.read(generalSettingsNotifierProvider.notifier)
.setEnableSpellCheck(value),
),
if (defaultTargetPlatform == TargetPlatform.android)
SwitchListTile(
title: Text(t.aria.enablePredictiveBack),
Expand Down
9 changes: 9 additions & 0 deletions lib/view/widget/post_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ class PostForm extends HookConsumerWidget {
_ when request.renoteId != null => (t.misskey.quote, Icons.send),
_ => (t.misskey.note, Icons.send),
};
final enableSpellCheck = ref.watch(
generalSettingsNotifierProvider
.select((settings) => settings.enableSpellCheck),
);
final useCw =
useState(useMemoized(() => request.cw?.isNotEmpty ?? false, []));
final cwController = this.cwController ??
Expand Down Expand Up @@ -840,6 +844,9 @@ class PostForm extends HookConsumerWidget {
textInputAction: TextInputAction.next,
maxLength: (request.cw?.length ?? 0) > 80 ? 100 : null,
maxLengthEnforcement: MaxLengthEnforcement.none,
spellCheckConfiguration: enableSpellCheck
? const SpellCheckConfiguration()
: null,
),
),
),
Expand Down Expand Up @@ -907,6 +914,8 @@ class PostForm extends HookConsumerWidget {
onLiveTextInput: null,
anchors: editableTextState.contextMenuAnchors,
),
spellCheckConfiguration:
enableSpellCheck ? const SpellCheckConfiguration() : null,
),
),
Padding(
Expand Down

0 comments on commit 04f1cd7

Please sign in to comment.