RawEditor: Give focus when using it for a new note

This commit is contained in:
Vishesh Handa
2020-02-18 16:31:34 +01:00
parent 59d379ab62
commit 27ebd9686b
4 changed files with 16 additions and 4 deletions

View File

@ -23,6 +23,8 @@ class ChecklistEditor extends StatefulWidget implements Editor {
@override
final NoteCallback discardChangesSelected;
final bool autofocusOnEditor;
ChecklistEditor({
Key key,
@required this.note,
@ -32,6 +34,7 @@ class ChecklistEditor extends StatefulWidget implements Editor {
@required this.renameNoteSelected,
@required this.moveNoteToFolderSelected,
@required this.discardChangesSelected,
@required this.autofocusOnEditor,
}) : super(key: key);
@override

View File

@ -31,7 +31,7 @@ class MarkdownEditor extends StatefulWidget implements Editor {
@required this.renameNoteSelected,
@required this.moveNoteToFolderSelected,
@required this.discardChangesSelected,
this.autofocusOnEditor = false,
@required this.autofocusOnEditor,
}) : super(key: key);
@override

View File

@ -20,6 +20,8 @@ class RawEditor extends StatefulWidget implements Editor {
@override
final NoteCallback discardChangesSelected;
final bool autofocusOnEditor;
RawEditor({
Key key,
@required this.note,
@ -29,6 +31,7 @@ class RawEditor extends StatefulWidget implements Editor {
@required this.renameNoteSelected,
@required this.moveNoteToFolderSelected,
@required this.discardChangesSelected,
@required this.autofocusOnEditor,
}) : super(key: key);
@override
@ -58,7 +61,10 @@ class RawEditorState extends State<RawEditor> implements EditorState {
var editor = Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: _NoteEditor(_textController),
child: _NoteEditor(
_textController,
autofocus: widget.autofocusOnEditor,
),
),
);
@ -78,8 +84,9 @@ class RawEditorState extends State<RawEditor> implements EditorState {
class _NoteEditor extends StatelessWidget {
final TextEditingController textController;
final bool autofocus;
_NoteEditor(this.textController);
_NoteEditor(this.textController, {this.autofocus = false});
@override
Widget build(BuildContext context) {
@ -87,7 +94,7 @@ class _NoteEditor extends StatelessWidget {
Theme.of(context).textTheme.subhead.copyWith(fontFamily: "Roboto Mono");
return TextField(
autofocus: false,
autofocus: autofocus,
autocorrect: false,
keyboardType: TextInputType.multiline,
maxLines: null,

View File

@ -103,6 +103,7 @@ class NoteEditorState extends State<NoteEditor> {
renameNoteSelected: _renameNoteSelected,
moveNoteToFolderSelected: _moveNoteToFolderSelected,
discardChangesSelected: _discardChangesSelected,
autofocusOnEditor: _isNewNote,
);
case EditorType.Checklist:
return ChecklistEditor(
@ -114,6 +115,7 @@ class NoteEditorState extends State<NoteEditor> {
renameNoteSelected: _renameNoteSelected,
moveNoteToFolderSelected: _moveNoteToFolderSelected,
discardChangesSelected: _discardChangesSelected,
autofocusOnEditor: _isNewNote,
);
}
return null;