diff --git a/src/app.rs b/src/app.rs index bb1b511..4e8da92 100644 --- a/src/app.rs +++ b/src/app.rs @@ -84,6 +84,9 @@ pub struct TemplateApp { #[serde(skip)] file_channel: (Sender, Receiver), + + #[serde(skip)] + autofocus: bool, } impl Default for TemplateApp { @@ -94,6 +97,7 @@ impl Default for TemplateApp { text: "".to_owned(), selection: CursorRange::default(), file_channel: channel(), + autofocus: true, } } } @@ -359,6 +363,14 @@ impl eframe::App for TemplateApp { }) } + // ============================= + // Autofocus the text widget on startup. + // ============================= + if self.autofocus { + content_ui.memory_mut(|m| m.request_focus(id)); + self.autofocus = false; + } + // ============================= // Do interactions. // =============================