mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Use a lot more let-else (#7582)
This commit is contained in:
@@ -421,10 +421,11 @@ mod tests {
|
||||
}
|
||||
|
||||
fn remove_leading_emoji(full_name: &str) -> &str {
|
||||
if let Some((start, name)) = full_name.split_once(' ') {
|
||||
if start.len() <= 4 && start.bytes().next().is_some_and(|byte| byte >= 128) {
|
||||
return name;
|
||||
}
|
||||
if let Some((start, name)) = full_name.split_once(' ')
|
||||
&& start.len() <= 4
|
||||
&& start.bytes().next().is_some_and(|byte| byte >= 128)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
full_name
|
||||
}
|
||||
|
||||
@@ -336,5 +336,5 @@ fn long_text(row_index: usize) -> String {
|
||||
}
|
||||
|
||||
fn thick_row(row_index: usize) -> bool {
|
||||
row_index % 6 == 0
|
||||
row_index.is_multiple_of(6)
|
||||
}
|
||||
|
||||
@@ -67,10 +67,9 @@ impl crate::View for ClipboardTest {
|
||||
|
||||
if let Ok(egui::load::ImagePoll::Ready { image }) =
|
||||
ui.ctx().try_load_image(&uri, Default::default())
|
||||
&& ui.button("📋").clicked()
|
||||
{
|
||||
if ui.button("📋").clicked() {
|
||||
ui.ctx().copy_image((*image).clone());
|
||||
}
|
||||
ui.ctx().copy_image((*image).clone());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ struct DeduplicatedHistory {
|
||||
|
||||
impl DeduplicatedHistory {
|
||||
fn add(&mut self, summary: String, full: String) {
|
||||
if let Some(entry) = self.history.back_mut() {
|
||||
if entry.summary == summary {
|
||||
entry.entries.push(full);
|
||||
return;
|
||||
}
|
||||
if let Some(entry) = self.history.back_mut()
|
||||
&& entry.summary == summary
|
||||
{
|
||||
entry.entries.push(full);
|
||||
return;
|
||||
}
|
||||
self.history.push_back(HistoryEntry {
|
||||
summary,
|
||||
|
||||
@@ -10,11 +10,11 @@ struct DeduplicatedHistory {
|
||||
|
||||
impl DeduplicatedHistory {
|
||||
fn add(&mut self, text: String) {
|
||||
if let Some(entry) = self.history.back_mut() {
|
||||
if entry.text == text {
|
||||
entry.repeated += 1;
|
||||
return;
|
||||
}
|
||||
if let Some(entry) = self.history.back_mut()
|
||||
&& entry.text == text
|
||||
{
|
||||
entry.repeated += 1;
|
||||
return;
|
||||
}
|
||||
self.history.push_back(HistoryEntry { text, repeated: 1 });
|
||||
if self.history.len() > 100 {
|
||||
|
||||
@@ -65,20 +65,20 @@ impl crate::View for TextEditDemo {
|
||||
egui::Label::new("Press ctrl+Y to toggle the case of selected text (cmd+Y on Mac)"),
|
||||
);
|
||||
|
||||
if ui.input_mut(|i| i.consume_key(egui::Modifiers::COMMAND, egui::Key::Y)) {
|
||||
if let Some(text_cursor_range) = output.cursor_range {
|
||||
use egui::TextBuffer as _;
|
||||
let selected_chars = text_cursor_range.as_sorted_char_range();
|
||||
let selected_text = text.char_range(selected_chars.clone());
|
||||
let upper_case = selected_text.to_uppercase();
|
||||
let new_text = if selected_text == upper_case {
|
||||
selected_text.to_lowercase()
|
||||
} else {
|
||||
upper_case
|
||||
};
|
||||
text.delete_char_range(selected_chars.clone());
|
||||
text.insert_text(&new_text, selected_chars.start);
|
||||
}
|
||||
if ui.input_mut(|i| i.consume_key(egui::Modifiers::COMMAND, egui::Key::Y))
|
||||
&& let Some(text_cursor_range) = output.cursor_range
|
||||
{
|
||||
use egui::TextBuffer as _;
|
||||
let selected_chars = text_cursor_range.as_sorted_char_range();
|
||||
let selected_text = text.char_range(selected_chars.clone());
|
||||
let upper_case = selected_text.to_uppercase();
|
||||
let new_text = if selected_text == upper_case {
|
||||
selected_text.to_lowercase()
|
||||
} else {
|
||||
upper_case
|
||||
};
|
||||
text.delete_char_range(selected_chars.clone());
|
||||
text.insert_text(&new_text, selected_chars.start);
|
||||
}
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
|
||||
@@ -60,15 +60,11 @@ impl crate::View for UndoRedoDemo {
|
||||
let undo = ui.add_enabled(can_undo, Button::new("⟲ Undo")).clicked();
|
||||
let redo = ui.add_enabled(can_redo, Button::new("⟳ Redo")).clicked();
|
||||
|
||||
if undo {
|
||||
if let Some(undo_text) = self.undoer.undo(&self.state) {
|
||||
self.state = undo_text.clone();
|
||||
}
|
||||
if undo && let Some(undo_text) = self.undoer.undo(&self.state) {
|
||||
self.state = undo_text.clone();
|
||||
}
|
||||
if redo {
|
||||
if let Some(redo_text) = self.undoer.redo(&self.state) {
|
||||
self.state = redo_text.clone();
|
||||
}
|
||||
if redo && let Some(redo_text) = self.undoer.redo(&self.state) {
|
||||
self.state = redo_text.clone();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user