Hook up mouse_down function handler
Co-authored-by: Antonio <antonio@zed.dev>
This commit is contained in:
parent
e30449e61a
commit
dd20032eab
1 changed files with 62 additions and 59 deletions
|
@ -8,8 +8,8 @@ use crate::{
|
||||||
},
|
},
|
||||||
scroll::scroll_amount::ScrollAmount,
|
scroll::scroll_amount::ScrollAmount,
|
||||||
CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
|
CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
|
||||||
HalfPageDown, HalfPageUp, LineDown, LineUp, MoveDown, PageDown, PageUp, Point, Selection,
|
HalfPageDown, HalfPageUp, LineDown, LineUp, MoveDown, PageDown, PageUp, Point, SelectPhase,
|
||||||
SoftWrap, ToPoint, MAX_LINE_LEN,
|
Selection, SoftWrap, ToPoint, MAX_LINE_LEN,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use collections::{BTreeMap, HashMap};
|
use collections::{BTreeMap, HashMap};
|
||||||
|
@ -17,8 +17,8 @@ use gpui::{
|
||||||
black, hsla, point, px, relative, size, transparent_black, Action, AnyElement,
|
black, hsla, point, px, relative, size, transparent_black, Action, AnyElement,
|
||||||
BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase,
|
BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase,
|
||||||
Edges, Element, ElementId, Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Modifiers,
|
Edges, Element, ElementId, Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Modifiers,
|
||||||
MouseMoveEvent, Pixels, ScrollWheelEvent, ShapedGlyph, Size, StatefulInteraction, Style,
|
MouseDownEvent, MouseMoveEvent, Pixels, ScrollWheelEvent, ShapedGlyph, Size,
|
||||||
TextRun, TextStyle, TextSystem, ViewContext, WindowContext,
|
StatefulInteraction, Style, TextRun, TextStyle, TextSystem, ViewContext, WindowContext,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use language::language_settings::ShowWhitespaceSetting;
|
use language::language_settings::ShowWhitespaceSetting;
|
||||||
|
@ -242,63 +242,54 @@ impl EditorElement {
|
||||||
// )
|
// )
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// fn mouse_down(
|
fn mouse_down(
|
||||||
// editor: &mut Editor,
|
editor: &mut Editor,
|
||||||
// MouseButtonEvent {
|
event: &MouseDownEvent,
|
||||||
// position,
|
position_map: &PositionMap,
|
||||||
// modifiers:
|
text_bounds: Bounds<Pixels>,
|
||||||
// Modifiers {
|
gutter_bounds: Bounds<Pixels>,
|
||||||
// shift,
|
cx: &mut ViewContext<Editor>,
|
||||||
// ctrl,
|
) -> bool {
|
||||||
// alt,
|
let mut click_count = event.click_count;
|
||||||
// cmd,
|
let modifiers = event.modifiers;
|
||||||
// ..
|
|
||||||
// },
|
|
||||||
// mut click_count,
|
|
||||||
// ..
|
|
||||||
// }: MouseButtonEvent,
|
|
||||||
// position_map: &PositionMap,
|
|
||||||
// text_bounds: Bounds<Pixels>,
|
|
||||||
// gutter_bounds: Bounds<Pixels>,
|
|
||||||
// cx: &mut EventContext<Editor>,
|
|
||||||
// ) -> bool {
|
|
||||||
// if gutter_bounds.contains_point(position) {
|
|
||||||
// click_count = 3; // Simulate triple-click when clicking the gutter to select lines
|
|
||||||
// } else if !text_bounds.contains_point(position) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let point_for_position = position_map.point_for_position(text_bounds, position);
|
if gutter_bounds.contains_point(&event.position) {
|
||||||
// let position = point_for_position.previous_valid;
|
click_count = 3; // Simulate triple-click when clicking the gutter to select lines
|
||||||
// if shift && alt {
|
} else if !text_bounds.contains_point(&event.position) {
|
||||||
// editor.select(
|
return false;
|
||||||
// SelectPhase::BeginColumnar {
|
}
|
||||||
// position,
|
|
||||||
// goal_column: point_for_position.exact_unclipped.column(),
|
|
||||||
// },
|
|
||||||
// cx,
|
|
||||||
// );
|
|
||||||
// } else if shift && !ctrl && !alt && !cmd {
|
|
||||||
// editor.select(
|
|
||||||
// SelectPhase::Extend {
|
|
||||||
// position,
|
|
||||||
// click_count,
|
|
||||||
// },
|
|
||||||
// cx,
|
|
||||||
// );
|
|
||||||
// } else {
|
|
||||||
// editor.select(
|
|
||||||
// SelectPhase::Begin {
|
|
||||||
// position,
|
|
||||||
// add: alt,
|
|
||||||
// click_count,
|
|
||||||
// },
|
|
||||||
// cx,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// true
|
let point_for_position = position_map.point_for_position(text_bounds, event.position);
|
||||||
// }
|
let position = point_for_position.previous_valid;
|
||||||
|
if modifiers.shift && modifiers.alt {
|
||||||
|
editor.select(
|
||||||
|
SelectPhase::BeginColumnar {
|
||||||
|
position,
|
||||||
|
goal_column: point_for_position.exact_unclipped.column(),
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
} else if modifiers.shift && !modifiers.control && !modifiers.alt && !modifiers.command {
|
||||||
|
editor.select(
|
||||||
|
SelectPhase::Extend {
|
||||||
|
position,
|
||||||
|
click_count,
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
editor.select(
|
||||||
|
SelectPhase::Begin {
|
||||||
|
position,
|
||||||
|
add: modifiers.alt,
|
||||||
|
click_count,
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
// fn mouse_right_down(
|
// fn mouse_right_down(
|
||||||
// editor: &mut Editor,
|
// editor: &mut Editor,
|
||||||
|
@ -2796,6 +2787,18 @@ impl Element<Editor> for EditorElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
cx.on_mouse_event({
|
||||||
|
let position_map = layout.position_map.clone();
|
||||||
|
move |editor, event: &MouseDownEvent, phase, cx| {
|
||||||
|
if phase != DispatchPhase::Bubble {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if Self::mouse_down(editor, event, &position_map, text_bounds, gutter_bounds, cx) {
|
||||||
|
cx.stop_propagation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if editor.focus_handle.is_focused(cx) {
|
if editor.focus_handle.is_focused(cx) {
|
||||||
cx.handle_text_input();
|
cx.handle_text_input();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue