From 8ef9fbcc7e3cb5ffb42d3365c9189d987a3e001c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristo=CC=81fer=20R?= Date: Tue, 26 Mar 2024 03:58:56 +0000 Subject: [PATCH] Autofocus the input widget on startup --- src/app.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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. // =============================