Skip to content

Commit

Permalink
Autofocus the input widget on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
reykjalin committed Mar 26, 2024
1 parent 35b6bdf commit 8ef9fbc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ pub struct TemplateApp {

#[serde(skip)]
file_channel: (Sender<FileMessage>, Receiver<FileMessage>),

#[serde(skip)]
autofocus: bool,
}

impl Default for TemplateApp {
Expand All @@ -94,6 +97,7 @@ impl Default for TemplateApp {
text: "".to_owned(),
selection: CursorRange::default(),
file_channel: channel(),
autofocus: true,
}
}
}
Expand Down Expand Up @@ -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.
// =============================
Expand Down

0 comments on commit 8ef9fbc

Please sign in to comment.