Browse Source

neon: Add back note preview tap listener, make it less annoying

pull/34/head
jld3103 2 years ago
parent
commit
f4a7c8cb97
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 72
      packages/neon/lib/src/apps/notes/pages/note.dart

72
packages/neon/lib/src/apps/notes/pages/note.dart

@ -24,6 +24,11 @@ class _NotesNotePageState extends State<NotesNotePage> {
bool _showEditor = false; bool _showEditor = false;
bool _synced = true; bool _synced = true;
void _focusEditor() {
_contentFocusNode.requestFocus();
_contentController.selection = TextSelection.collapsed(offset: _contentController.text.length);
}
void _update([final String? selectedCategory]) { void _update([final String? selectedCategory]) {
final updatedTitle = _note.title != _titleController.text ? _titleController.text : null; final updatedTitle = _note.title != _titleController.text ? _titleController.text : null;
final updatedCategory = selectedCategory != null && _note.category != selectedCategory ? selectedCategory : null; final updatedCategory = selectedCategory != null && _note.category != selectedCategory ? selectedCategory : null;
@ -76,8 +81,7 @@ class _NotesNotePageState extends State<NotesNotePage> {
setState(() { setState(() {
_showEditor = true; _showEditor = true;
}); });
_contentFocusNode.requestFocus(); _focusEditor();
_contentController.selection = TextSelection.collapsed(offset: _contentController.text.length);
} }
}); });
} }
@ -132,8 +136,7 @@ class _NotesNotePageState extends State<NotesNotePage> {
_showEditor = !_showEditor; _showEditor = !_showEditor;
}); });
if (_showEditor) { if (_showEditor) {
_contentFocusNode.requestFocus(); _focusEditor();
_contentController.selection = TextSelection.collapsed(offset: _contentController.text.length);
} else { } else {
// Prevent the cursor going back to the title field // Prevent the cursor going back to the title field
_contentFocusNode.unfocus(); _contentFocusNode.unfocus();
@ -161,34 +164,41 @@ class _NotesNotePageState extends State<NotesNotePage> {
), ),
], ],
), ),
body: Container( body: GestureDetector(
padding: EdgeInsets.symmetric( onTap: () {
vertical: 10, setState(() {
horizontal: _showEditor ? 20 : 10, _showEditor = true;
), });
color: Colors.transparent, },
constraints: const BoxConstraints.expand(), child: Container(
child: _showEditor padding: EdgeInsets.symmetric(
? TextField( vertical: 10,
controller: _contentController, horizontal: _showEditor ? 20 : 10,
focusNode: _contentFocusNode, ),
keyboardType: TextInputType.multiline, color: Colors.transparent,
maxLines: null, constraints: const BoxConstraints.expand(),
decoration: const InputDecoration( child: _showEditor
border: InputBorder.none, ? 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,
);
}
},
), ),
) ),
: MarkdownBody(
data: _contentController.text,
onTapLink: (final text, final href, final title) {
if (href != null) {
launchUrlString(
href,
mode: LaunchMode.externalApplication,
);
}
},
),
), ),
), ),
); );

Loading…
Cancel
Save