Flatten code a bit
@@ -171,11 +171,13 @@ fn event(
}
Event::MouseUp(mouse_event) => {
self.mouse_down_target = None;
- if let Some((_, drag_content)) = data.drag.clone().as_ref() {
- match drag_content {
- DragContent::EditorTab(from_id, from_index, child, _) => {
- let mut mouse_index =
- self.drag_target_idx(mouse_event.pos);
+
+ if let Some((
+ _,
+ DragContent::EditorTab(from_id, from_index, child, _),
+ )) = Arc::make_mut(&mut data.drag).take()
+ {
+ let mut mouse_index = self.drag_target_idx(mouse_event.pos);
let editor_tab = data
.main_split
@@ -184,17 +186,17 @@ fn event(
.unwrap()
.clone();
- if &editor_tab.widget_id == from_id {
+ if editor_tab.widget_id == from_id {
// Take the removed tab into account.
- if mouse_index > *from_index {
+ if mouse_index > from_index {
mouse_index = mouse_index.saturating_sub(1);
}
- if mouse_index != *from_index {
+ if mouse_index != from_index {
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::EditorTabSwap(
- *from_index,
+ from_index,
mouse_index,
),
Target::Widget(editor_tab.widget_id),
@@ -205,7 +207,9 @@ fn event(
Target::Widget(child.widget_id()),
));
}
- } else {
+ return;
+ }
+
child.set_editor_tab(data, editor_tab.widget_id);
let editor_tab = data
.main_split
@@ -213,15 +217,10 @@ fn event(
.get_mut(&self.widget_id)
.unwrap();
let editor_tab = Arc::make_mut(editor_tab);
- editor_tab
- .children
- .insert(mouse_index, child.clone());
+ editor_tab.children.insert(mouse_index, child.clone());
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
- LapceUICommand::EditorTabAdd(
- mouse_index,
- child.clone(),
- ),
+ LapceUICommand::EditorTabAdd(mouse_index, child.clone()),
Target::Widget(editor_tab.widget_id),
));
ctx.submit_command(Command::new(
@@ -231,21 +230,11 @@ fn event(
));
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
- LapceUICommand::EditorTabRemove(
- *from_index,
- false,
- false,
- ),
- Target::Widget(*from_id),
+ LapceUICommand::EditorTabRemove(from_index, false, false),
+ Target::Widget(from_id),
));
}
}
- };
- }
- if data.drag.is_some() {
- *Arc::make_mut(&mut data.drag) = None;
- }
- }
_ => (),
}
}
