Skip to content

Commit

Permalink
Disable language tool check for text field
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 authored and hoangdat committed Dec 17, 2024
1 parent 8892c4b commit 050a885
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 154 deletions.
17 changes: 0 additions & 17 deletions contact/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -688,15 +688,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.6.1"
languagetool_textfield:
dependency: transitive
description:
path: "."
ref: twake-supported
resolved-ref: f47dd9829e145acc795b4e3e62f8bc668135fcd6
url: "https://github.com/dab246/languagetool_textfield.git"
source: git
version: "0.1.0"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -1110,14 +1101,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.0"
throttling:
dependency: transitive
description:
name: throttling
sha256: e48a4c681b1838b8bf99c1a4f822efe43bb69132f9a56091cd5b7d931c862255
url: "https://pub.dev"
source: hosted
version: "2.0.1"
timing:
dependency: transitive
description:
Expand Down
82 changes: 18 additions & 64 deletions core/lib/presentation/views/text/text_field_builder.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/utils/direction_utils.dart';
import 'package:flutter/material.dart';
import 'package:languagetool_textfield/languagetool_textfield.dart';

class TextFieldBuilder extends StatefulWidget {

Expand All @@ -26,7 +25,6 @@ class TextFieldBuilder extends StatefulWidget {
final TextDirection textDirection;
final bool readOnly;
final MouseCursor? mouseCursor;
final LanguageToolController? languageToolController;

const TextFieldBuilder({
super.key,
Expand All @@ -42,7 +40,6 @@ class TextFieldBuilder extends StatefulWidget {
this.maxLines,
this.minLines,
this.controller,
this.languageToolController,
this.keyboardType,
this.focusNode,
this.fromValue,
Expand All @@ -61,66 +58,24 @@ class TextFieldBuilder extends StatefulWidget {
class _TextFieldBuilderState extends State<TextFieldBuilder> {

TextEditingController? _controller;
LanguageToolController? _languageToolController;

late TextDirection _textDirection;

@override
void initState() {
super.initState();
if (widget.languageToolController != null) {
_languageToolController = widget.languageToolController;
if (widget.fromValue != null) {
_languageToolController?.value = TextEditingValue(text: widget.fromValue!);
}
if (widget.fromValue != null) {
_controller = TextEditingController.fromValue(
TextEditingValue(text: widget.fromValue!),
);
} else {
if (widget.fromValue != null) {
_controller = TextEditingController.fromValue(TextEditingValue(text: widget.fromValue!));
} else {
_controller = widget.controller ?? TextEditingController();
}
_controller = widget.controller ?? TextEditingController();
}
_textDirection = widget.textDirection;
}

@override
Widget build(BuildContext context) {
if (_languageToolController != null) {
return LanguageToolTextField(
key: widget.key,
controller: _languageToolController!,
cursorColor: widget.cursorColor,
autocorrect: widget.autocorrect,
textInputAction: widget.textInputAction,
decoration: widget.decoration,
maxLines: widget.maxLines,
minLines: widget.minLines,
keyboardAppearance: widget.keyboardAppearance,
style: widget.textStyle,
keyboardType: widget.keyboardType,
autoFocus: widget.autoFocus,
focusNode: widget.focusNode,
alignCenter: false,
textDirection: _textDirection,
readOnly: widget.readOnly,
mouseCursor: widget.mouseCursor,
onTextChange: (value) {
widget.onTextChange?.call(value);
if (value.isNotEmpty) {
final directionByText = DirectionUtils.getDirectionByEndsText(value);
if (directionByText != _textDirection) {
setState(() {
_textDirection = directionByText;
});
}
}
},
onTextSubmitted: widget.onTextSubmitted,
onTap: widget.onTap,
onTapOutside: widget.onTapOutside,
);
}

return TextField(
key: widget.key,
controller: _controller,
Expand All @@ -139,31 +94,30 @@ class _TextFieldBuilderState extends State<TextFieldBuilder> {
textDirection: _textDirection,
readOnly: widget.readOnly,
mouseCursor: widget.mouseCursor,
onChanged: (value) {
widget.onTextChange?.call(value);
if (value.isNotEmpty) {
final directionByText = DirectionUtils.getDirectionByEndsText(value);
if (directionByText != _textDirection) {
setState(() {
_textDirection = directionByText;
});
}
}
},
onChanged: _onTextChanged,
onSubmitted: widget.onTextSubmitted,
onTap: widget.onTap,
onTapOutside: widget.onTapOutside,
);
}

void _onTextChanged(String value) {
widget.onTextChange?.call(value);

if (value.trim().isEmpty) return;

final directionByText = DirectionUtils.getDirectionByEndsText(value);
if (directionByText != _textDirection) {
setState(() {
_textDirection = directionByText;
});
}
}
@override
void dispose() {
if (widget.controller == null) {
_controller?.dispose();
}
if (widget.languageToolController == null) {
_languageToolController?.dispose();
}
super.dispose();
}
}
17 changes: 0 additions & 17 deletions core/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -656,15 +656,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.9.0"
languagetool_textfield:
dependency: "direct main"
description:
path: "."
ref: twake-supported
resolved-ref: f47dd9829e145acc795b4e3e62f8bc668135fcd6
url: "https://github.com/dab246/languagetool_textfield.git"
source: git
version: "0.1.0"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -1055,14 +1046,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.0"
throttling:
dependency: transitive
description:
name: throttling
sha256: e48a4c681b1838b8bf99c1a4f822efe43bb69132f9a56091cd5b7d931c862255
url: "https://pub.dev"
source: hosted
version: "2.0.1"
timing:
dependency: transitive
description:
Expand Down
7 changes: 0 additions & 7 deletions core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ dependencies:
sdk: flutter

### Dependencies from git ###
# TODO: We will change it when the PR in upstream repository will be merged
# https://github.com/solid-software/languagetool_textfield/pull/83
languagetool_textfield:
git:
url: https://github.com/dab246/languagetool_textfield.git
ref: twake-supported

# Sanitize_html is restricting Tags and Attributes. So some of our own tags and attributes (signature, public asset,...) will be lost when sanitizing html.
# TODO: We will change it when the PR in upstream repository will be merged
# https://github.com/google/dart-neats/pull/259
Expand Down
6 changes: 1 addition & 5 deletions lib/features/composer/presentation/composer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:languagetool_textfield/languagetool_textfield.dart';
import 'package:model/model.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
Expand Down Expand Up @@ -156,9 +155,7 @@ class ComposerController extends BaseController
List<EmailAddress> listReplyToEmailAddress = <EmailAddress>[];
ContactSuggestionSource _contactSuggestionSource = ContactSuggestionSource.tMailContact;

final subjectEmailInputController = LanguageToolController(
delay: const Duration(milliseconds: 200),
);
final subjectEmailInputController = TextEditingController();
final toEmailAddressController = TextEditingController();
final ccEmailAddressController = TextEditingController();
final bccEmailAddressController = TextEditingController();
Expand Down Expand Up @@ -2030,7 +2027,6 @@ class ComposerController extends BaseController

void handleOnFocusHtmlEditorWeb() {
FocusManager.instance.primaryFocus?.unfocus();
subjectEmailInputController.popupWidget?.popupRenderer.dismiss();
richTextWebController?.editorController.setFocus();
richTextWebController?.closeAllMenuPopup();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import 'package:core/presentation/views/text/text_field_builder.dart';
import 'package:core/utils/direction_utils.dart';
import 'package:flutter/material.dart';
import 'package:languagetool_textfield/languagetool_textfield.dart';
import 'package:tmail_ui_user/features/composer/presentation/styles/subject_composer_widget_style.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';

class SubjectComposerWidget extends StatelessWidget {

final FocusNode? focusNode;
final LanguageToolController textController;
final TextEditingController textController;
final ValueChanged<String>? onTextChange;
final EdgeInsetsGeometry? margin;
final EdgeInsetsGeometry? padding;
Expand Down Expand Up @@ -51,7 +50,7 @@ class SubjectComposerWidget extends StatelessWidget {
decoration: const InputDecoration(border: InputBorder.none),
textDirection: DirectionUtils.getDirectionByLanguage(context),
textStyle: SubjectComposerWidgetStyle.inputTextStyle,
languageToolController: textController,
controller: textController,
)
)
]
Expand Down
17 changes: 0 additions & 17 deletions model/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -680,15 +680,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.6.1"
languagetool_textfield:
dependency: transitive
description:
path: "."
ref: twake-supported
resolved-ref: f47dd9829e145acc795b4e3e62f8bc668135fcd6
url: "https://github.com/dab246/languagetool_textfield.git"
source: git
version: "0.1.0"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -1087,14 +1078,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.0"
throttling:
dependency: transitive
description:
name: throttling
sha256: e48a4c681b1838b8bf99c1a4f822efe43bb69132f9a56091cd5b7d931c862255
url: "https://pub.dev"
source: hosted
version: "2.0.1"
timing:
dependency: transitive
description:
Expand Down
17 changes: 0 additions & 17 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1344,15 +1344,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.6.1"
languagetool_textfield:
dependency: "direct main"
description:
path: "."
ref: twake-supported
resolved-ref: f47dd9829e145acc795b4e3e62f8bc668135fcd6
url: "https://github.com/dab246/languagetool_textfield.git"
source: git
version: "0.1.0"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -2056,14 +2047,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.2"
throttling:
dependency: transitive
description:
name: throttling
sha256: e48a4c681b1838b8bf99c1a4f822efe43bb69132f9a56091cd5b7d931c862255
url: "https://pub.dev"
source: hosted
version: "2.0.1"
timeago:
dependency: "direct main"
description:
Expand Down
7 changes: 0 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ dependencies:
url: https://github.com/linagora/flutter_pdf_render.git
ref: main

# TODO: We will change it when the PR in upstream repository will be merged
# https://github.com/solid-software/languagetool_textfield/pull/83
languagetool_textfield:
git:
url: https://github.com/dab246/languagetool_textfield.git
ref: twake-supported

linagora_design_flutter:
git:
url: https://github.com/linagora/linagora-design-flutter.git
Expand Down

0 comments on commit 050a885

Please sign in to comment.