Skip to content

Commit 3e7ec1b

Browse files
committed
Fix title and description fields clearing on focus loss, closes #1101
1 parent c801939 commit 3e7ec1b

4 files changed

Lines changed: 46 additions & 22 deletions

File tree

app/lib/selections/document.dart

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class _UtilitiesViewState extends State<_UtilitiesView>
5050
with TickerProviderStateMixin {
5151
late final TabController _tabController;
5252
final TextEditingController _descriptionController = TextEditingController();
53+
final FocusNode _descriptionFocusNode = FocusNode();
5354

5455
@override
5556
void initState() {
@@ -62,10 +63,11 @@ class _UtilitiesViewState extends State<_UtilitiesView>
6263

6364
@override
6465
void dispose() {
65-
super.dispose();
66-
6766
_tabController.dispose();
6867
_descriptionController.dispose();
68+
_descriptionFocusNode.dispose();
69+
70+
super.dispose();
6971
}
7072

7173
@override
@@ -84,7 +86,8 @@ class _UtilitiesViewState extends State<_UtilitiesView>
8486
final state = bloc.state;
8587
if (state is! DocumentLoadSuccess) return const SizedBox.shrink();
8688
final metadata = state.metadata;
87-
if (_descriptionController.text != metadata.description) {
89+
if (!_descriptionFocusNode.hasFocus &&
90+
_descriptionController.text != metadata.description) {
8891
_descriptionController.text = metadata.description;
8992
}
9093
void submitDescription(String? value) {
@@ -130,16 +133,23 @@ class _UtilitiesViewState extends State<_UtilitiesView>
130133
builder: (context) => [
131134
Column(
132135
children: [
133-
TextFormField(
134-
minLines: 3,
135-
maxLines: 5,
136-
controller: _descriptionController,
137-
decoration: InputDecoration(
138-
labelText: AppLocalizations.of(context).description,
139-
border: const OutlineInputBorder(),
136+
Focus(
137+
onFocusChange: (hasFocus) {
138+
if (!hasFocus) submitDescription(null);
139+
},
140+
child: TextFormField(
141+
minLines: 3,
142+
maxLines: 5,
143+
controller: _descriptionController,
144+
focusNode: _descriptionFocusNode,
145+
decoration: InputDecoration(
146+
labelText: AppLocalizations.of(context).description,
147+
border: const OutlineInputBorder(),
148+
),
149+
onTapOutside: (_) => submitDescription(null),
150+
onFieldSubmitted: submitDescription,
151+
onSaved: submitDescription,
140152
),
141-
onFieldSubmitted: submitDescription,
142-
onSaved: submitDescription,
143153
),
144154
const SizedBox(height: 8),
145155
ListTile(

app/lib/views/app_bar.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,15 @@ class _AppBarTitle extends StatefulWidget {
124124
class _AppBarTitleState extends State<_AppBarTitle> {
125125
final TextEditingController _nameController = TextEditingController(),
126126
_areaController = TextEditingController();
127+
final FocusNode _nameFocusNode = FocusNode(), _areaFocusNode = FocusNode();
127128

128129
@override
129130
void dispose() {
130-
super.dispose();
131131
_nameController.dispose();
132132
_areaController.dispose();
133+
_nameFocusNode.dispose();
134+
_areaFocusNode.dispose();
135+
super.dispose();
133136
}
134137

135138
@override
@@ -167,10 +170,14 @@ class _AppBarTitleState extends State<_AppBarTitle> {
167170
? state.currentAreaName
168171
: null;
169172
if (state is DocumentLoaded &&
173+
!_nameFocusNode.hasFocus &&
170174
state.metadata.name != _nameController.text) {
171175
_nameController.text = state.metadata.name;
172176
}
173-
_areaController.text = area?.name ?? '';
177+
if (!_areaFocusNode.hasFocus &&
178+
_areaController.text != (area?.name ?? '')) {
179+
_areaController.text = area?.name ?? '';
180+
}
174181
return BlocBuilder<SettingsCubit, ButterflySettings>(
175182
buildWhen: (previous, current) =>
176183
previous.flags != current.flags ||
@@ -295,10 +302,16 @@ class _AppBarTitleState extends State<_AppBarTitle> {
295302
mainAxisSize: MainAxisSize.min,
296303
children: [
297304
Focus(
305+
onFocusChange: (hasFocus) {
306+
if (!hasFocus) submit(null);
307+
},
298308
child: TextFormField(
299309
controller: area == null
300310
? _nameController
301311
: _areaController,
312+
focusNode: area == null
313+
? _nameFocusNode
314+
: _areaFocusNode,
302315
onFieldSubmitted: submit,
303316
onSaved: submit,
304317
readOnly: currentIndex.embedding?.editable == false,

app/pubspec.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,10 @@ packages:
413413
dependency: "direct main"
414414
description:
415415
name: file_picker
416-
sha256: "0204695694b687b167fd497da5252e9f4aaa162e8d274d6fa1e757380f2a5f46"
416+
sha256: fc83774ce5bd7ce08168333b5e53dbe9090ec04eb21e7aa7cd7bac921032c934
417417
url: "https://pub.dev"
418418
source: hosted
419-
version: "12.0.0-beta.4"
419+
version: "12.0.0-beta.5"
420420
fixnum:
421421
dependency: transitive
422422
description:
@@ -1065,10 +1065,10 @@ packages:
10651065
dependency: transitive
10661066
description:
10671067
name: pdfium_dart
1068-
sha256: "07bba420737d88913773aacbaa3dd40b42d6119967816130fc381fbed8f34c92"
1068+
sha256: b536c19a10f8c86c160274a54ca6f29bc4c88001324ddcda4cca316033f2dc96
10691069
url: "https://pub.dev"
10701070
source: hosted
1071-
version: "0.2.3"
1071+
version: "0.2.4"
10721072
pdfium_flutter:
10731073
dependency: transitive
10741074
description:
@@ -1081,10 +1081,10 @@ packages:
10811081
dependency: "direct main"
10821082
description:
10831083
name: pdfrx
1084-
sha256: d20b2826add5f26dbb0ee44d4828aafd255388c8a3d84b1e7f4d4dee00371ecd
1084+
sha256: "6b3571565fb412fb7d0a325a76154d0685bd0a0659c3f41ee007f408d48cfd46"
10851085
url: "https://pub.dev"
10861086
source: hosted
1087-
version: "2.4.2"
1087+
version: "2.4.3"
10881088
pdfrx_engine:
10891089
dependency: transitive
10901090
description:
@@ -1641,10 +1641,10 @@ packages:
16411641
dependency: transitive
16421642
description:
16431643
name: vector_graphics_compiler
1644-
sha256: b9b3f391857781aa96acacef96066f2f49b4cd03cf9fce3ca4d8da2ef5ea129e
1644+
sha256: "09854c7633b215e6f7bb2a9adb607bc525bae8655c7fc29db880c33e62f72230"
16451645
url: "https://pub.dev"
16461646
source: hosted
1647-
version: "1.2.3"
1647+
version: "1.2.4"
16481648
vector_math:
16491649
dependency: transitive
16501650
description:

metadata/en-US/changelogs/183.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Fix texture tool configuration scrolling getting stuck ([#1092](https://github.com/LinwoodDev/Butterfly/issues/1092))
66
* Fix temporary tools being cleared after canvas gestures ([#1093](https://github.com/LinwoodDev/Butterfly/issues/1093))
77
* Fix image operations temporarily showing gray boxes ([#1097](https://github.com/LinwoodDev/Butterfly/issues/1097))
8+
* Fix title and description fields clearing on focus loss ([#1101](https://github.com/LinwoodDev/Butterfly/issues/1101))
89
* Fix pressure not used for inverted stylus
910

1011
Read more here: https://linwood.dev/butterfly/2.5.3-rc.0

0 commit comments

Comments
 (0)