Fix a few edge cases

This commit is contained in:
Dániel Buga 2022-03-31 20:04:09 +02:00
parent 9ea66f669b
commit e57203c603
1 changed files with 16 additions and 4 deletions

View File

@ -4,8 +4,8 @@
kurbo::Line,
piet::{Text, TextLayout as TextLayoutTrait, TextLayoutBuilder},
BoxConstraints, Command, Env, Event, EventCtx, FontFamily, LayoutCtx, LifeCycle,
LifeCycleCtx, MouseEvent, PaintCtx, Point, RenderContext, Size, Target,
UpdateCtx, Widget, WidgetId,
LifeCycleCtx, MouseButton, MouseEvent, PaintCtx, Point, RenderContext, Size,
Target, UpdateCtx, Widget, WidgetId,
};
use lapce_data::{
buffer::BufferContent,
@ -46,6 +46,11 @@ fn icon_hit_test(&self, mouse_event: &MouseEvent) -> bool {
false
}
fn cancel_pending_drag(&mut self, data: &mut LapceTabData) {
self.mouse_down_target = None;
*Arc::make_mut(&mut data.drag) = None;
}
fn mouse_down(
&mut self,
ctx: &mut EventCtx,
@ -64,6 +69,7 @@ fn mouse_down(
.unwrap();
let editor_tab = Arc::make_mut(editor_tab);
if tab_rect.close_rect.contains(mouse_event.pos) {
self.cancel_pending_drag(data);
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::EditorTabRemove(i, true, true),
@ -103,6 +109,12 @@ fn mouse_move(
}
ctx.request_paint();
if !mouse_event.buttons.contains(MouseButton::Left) {
// If drag data exists, mouse was released outside of the view.
self.cancel_pending_drag(data);
return;
}
if data.drag.is_none() {
if let Some(target) = self.mouse_down_target {
let editor_tab =
@ -170,13 +182,12 @@ fn event(
self.mouse_down(ctx, data, mouse_event);
}
Event::MouseUp(mouse_event) if mouse_event.button.is_left() => {
self.mouse_down_target = None;
if let Some((
_,
DragContent::EditorTab(from_id, from_index, child, _),
)) = Arc::make_mut(&mut data.drag).take()
{
self.mouse_down_target = None;
let mut mouse_index = self.drag_target_idx(mouse_event.pos);
let editor_tab = data
@ -247,6 +258,7 @@ fn lifecycle(
_env: &Env,
) {
if let LifeCycle::HotChanged(_) = event {
// Prevent re-entering with MouseDown to pick up a random tab.
self.mouse_down_target = None;
}
}