From d45b4f9c5ce572698155a06f0bc96fc899bd3472 Mon Sep 17 00:00:00 2001 From: Hanif Ariffin Date: Mon, 10 Oct 2022 00:59:11 +0800 Subject: [PATCH] Rewritten a loop-based variable to the more idiomatic iterator-based implementation (#1463) --- lapce-data/src/data.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lapce-data/src/data.rs b/lapce-data/src/data.rs index bb2bd859..71a06128 100644 --- a/lapce-data/src/data.rs +++ b/lapce-data/src/data.rs @@ -3361,12 +3361,11 @@ pub fn widget_close( editor_tab_id: WidgetId, ) { let editor_tab = self.editor_tabs.get(&editor_tab_id).unwrap(); - let mut index = 0; - for (i, child) in editor_tab.children.iter().enumerate() { - if child.widget_id() == widget_id { - index = i; - } - } + let index = editor_tab + .children + .iter() + .position(|child| child.widget_id() == widget_id) + .unwrap_or(0); ctx.submit_command(Command::new( LAPCE_UI_COMMAND, LapceUICommand::EditorTabRemove(index, true, true),