From 3b2639e99e8e10ba8285a7e4d6bd8a6c4d40e4d1 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 20 Jul 2022 17:24:56 +0200 Subject: [PATCH] harbour: Disable note preview on click going to editor Closes https://github.com/jld3103/nextcloud-harbour/issues/14 --- .../lib/src/apps/notes/pages/note.dart | 70 ++++++++----------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/packages/harbour/lib/src/apps/notes/pages/note.dart b/packages/harbour/lib/src/apps/notes/pages/note.dart index 352e77c2..5c0f0835 100644 --- a/packages/harbour/lib/src/apps/notes/pages/note.dart +++ b/packages/harbour/lib/src/apps/notes/pages/note.dart @@ -24,11 +24,6 @@ class _NotesNotePageState extends State { bool _showEditor = false; bool _synced = true; - void _focusEditor() { - _contentFocusNode.requestFocus(); - _contentController.selection = TextSelection.collapsed(offset: _contentController.text.length); - } - void _update([final String? selectedCategory]) { final updatedTitle = _note.title != _titleController.text ? _titleController.text : null; final updatedCategory = selectedCategory != null && _note.category != selectedCategory ? selectedCategory : null; @@ -137,7 +132,8 @@ class _NotesNotePageState extends State { _showEditor = !_showEditor; }); if (_showEditor) { - _focusEditor(); + _contentFocusNode.requestFocus(); + _contentController.selection = TextSelection.collapsed(offset: _contentController.text.length); } else { // Prevent the cursor going back to the title field _contentFocusNode.unfocus(); @@ -165,42 +161,34 @@ class _NotesNotePageState extends State { ), ], ), - body: GestureDetector( - onTap: () { - setState(() { - _showEditor = true; - }); - _focusEditor(); - }, - child: Container( - padding: EdgeInsets.symmetric( - vertical: 10, - horizontal: _showEditor ? 20 : 10, - ), - color: Colors.transparent, - constraints: const BoxConstraints.expand(), - child: _showEditor - ? TextField( - controller: _contentController, - focusNode: _contentFocusNode, - keyboardType: TextInputType.multiline, - maxLines: null, - decoration: const InputDecoration( - border: InputBorder.none, - ), - ) - : MarkdownBody( - data: _contentController.text, - onTapLink: (final text, final href, final title) { - if (href != null) { - launchUrlString( - href, - mode: LaunchMode.externalApplication, - ); - } - }, - ), + body: Container( + padding: EdgeInsets.symmetric( + vertical: 10, + horizontal: _showEditor ? 20 : 10, ), + color: Colors.transparent, + constraints: const BoxConstraints.expand(), + child: _showEditor + ? TextField( + controller: _contentController, + focusNode: _contentFocusNode, + keyboardType: TextInputType.multiline, + maxLines: null, + decoration: const InputDecoration( + border: InputBorder.none, + ), + ) + : MarkdownBody( + data: _contentController.text, + onTapLink: (final text, final href, final title) { + if (href != null) { + launchUrlString( + href, + mode: LaunchMode.externalApplication, + ); + } + }, + ), ), ), );