Merge branch 'main' into editor2_tests
This commit is contained in:
@@ -992,10 +992,6 @@ impl Interactivity {
|
||||
let interactive_bounds = interactive_bounds.clone();
|
||||
|
||||
cx.on_mouse_event(move |event: &MouseMoveEvent, phase, cx| {
|
||||
if phase != DispatchPhase::Bubble {
|
||||
return;
|
||||
}
|
||||
|
||||
let is_hovered = interactive_bounds.visibly_contains(&event.position, cx)
|
||||
&& pending_mouse_down.borrow().is_none();
|
||||
if !is_hovered {
|
||||
@@ -1003,6 +999,10 @@ impl Interactivity {
|
||||
return;
|
||||
}
|
||||
|
||||
if phase != DispatchPhase::Bubble {
|
||||
return;
|
||||
}
|
||||
|
||||
if active_tooltip.borrow().is_none() {
|
||||
let task = cx.spawn({
|
||||
let active_tooltip = active_tooltip.clone();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::{
|
||||
Bounds, DispatchPhase, Element, ElementId, IntoElement, LayoutId, MouseDownEvent, MouseUpEvent,
|
||||
Pixels, Point, SharedString, Size, TextRun, WhiteSpace, WindowContext, WrappedLine,
|
||||
Bounds, DispatchPhase, Element, ElementId, HighlightStyle, IntoElement, LayoutId,
|
||||
MouseDownEvent, MouseUpEvent, Pixels, Point, SharedString, Size, TextRun, TextStyle,
|
||||
WhiteSpace, WindowContext, WrappedLine,
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use parking_lot::{Mutex, MutexGuard};
|
||||
@@ -87,7 +88,28 @@ impl StyledText {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_runs(mut self, runs: Vec<TextRun>) -> Self {
|
||||
pub fn with_highlights(
|
||||
mut self,
|
||||
default_style: &TextStyle,
|
||||
highlights: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>,
|
||||
) -> Self {
|
||||
let mut runs = Vec::new();
|
||||
let mut ix = 0;
|
||||
for (range, highlight) in highlights {
|
||||
if ix < range.start {
|
||||
runs.push(default_style.clone().to_run(range.start - ix));
|
||||
}
|
||||
runs.push(
|
||||
default_style
|
||||
.clone()
|
||||
.highlight(highlight)
|
||||
.to_run(range.len()),
|
||||
);
|
||||
ix = range.end;
|
||||
}
|
||||
if ix < self.text.len() {
|
||||
runs.push(default_style.to_run(self.text.len() - ix));
|
||||
}
|
||||
self.runs = Some(runs);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -472,13 +472,27 @@ pub enum PromptLevel {
|
||||
Critical,
|
||||
}
|
||||
|
||||
/// The style of the cursor (pointer)
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum CursorStyle {
|
||||
Arrow,
|
||||
ResizeLeftRight,
|
||||
ResizeUpDown,
|
||||
PointingHand,
|
||||
IBeam,
|
||||
Crosshair,
|
||||
ClosedHand,
|
||||
OpenHand,
|
||||
PointingHand,
|
||||
ResizeLeft,
|
||||
ResizeRight,
|
||||
ResizeLeftRight,
|
||||
ResizeUp,
|
||||
ResizeDown,
|
||||
ResizeUpDown,
|
||||
DisappearingItem,
|
||||
IBeamCursorForVerticalLayout,
|
||||
OperationNotAllowed,
|
||||
DragLink,
|
||||
DragCopy,
|
||||
ContextualMenu,
|
||||
}
|
||||
|
||||
impl Default for CursorStyle {
|
||||
|
||||
@@ -724,16 +724,35 @@ impl Platform for MacPlatform {
|
||||
}
|
||||
}
|
||||
|
||||
/// Match cursor style to one of the styles available
|
||||
/// in macOS's [NSCursor](https://developer.apple.com/documentation/appkit/nscursor).
|
||||
fn set_cursor_style(&self, style: CursorStyle) {
|
||||
unsafe {
|
||||
let new_cursor: id = match style {
|
||||
CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor],
|
||||
CursorStyle::ResizeLeftRight => {
|
||||
msg_send![class!(NSCursor), resizeLeftRightCursor]
|
||||
}
|
||||
CursorStyle::ResizeUpDown => msg_send![class!(NSCursor), resizeUpDownCursor],
|
||||
CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor],
|
||||
CursorStyle::IBeam => msg_send![class!(NSCursor), IBeamCursor],
|
||||
CursorStyle::Crosshair => msg_send![class!(NSCursor), crosshairCursor],
|
||||
CursorStyle::ClosedHand => msg_send![class!(NSCursor), closedHandCursor],
|
||||
CursorStyle::OpenHand => msg_send![class!(NSCursor), openHandCursor],
|
||||
CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor],
|
||||
CursorStyle::ResizeLeft => msg_send![class!(NSCursor), resizeLeftCursor],
|
||||
CursorStyle::ResizeRight => msg_send![class!(NSCursor), resizeRightCursor],
|
||||
CursorStyle::ResizeLeftRight => msg_send![class!(NSCursor), resizeLeftRightCursor],
|
||||
CursorStyle::ResizeUp => msg_send![class!(NSCursor), resizeUpCursor],
|
||||
CursorStyle::ResizeDown => msg_send![class!(NSCursor), resizeDownCursor],
|
||||
CursorStyle::ResizeUpDown => msg_send![class!(NSCursor), resizeUpDownCursor],
|
||||
CursorStyle::DisappearingItem => {
|
||||
msg_send![class!(NSCursor), disappearingItemCursor]
|
||||
}
|
||||
CursorStyle::IBeamCursorForVerticalLayout => {
|
||||
msg_send![class!(NSCursor), IBeamCursorForVerticalLayout]
|
||||
}
|
||||
CursorStyle::OperationNotAllowed => {
|
||||
msg_send![class!(NSCursor), operationNotAllowedCursor]
|
||||
}
|
||||
CursorStyle::DragLink => msg_send![class!(NSCursor), dragLinkCursor],
|
||||
CursorStyle::DragCopy => msg_send![class!(NSCursor), dragCopyCursor],
|
||||
CursorStyle::ContextualMenu => msg_send![class!(NSCursor), contextualMenuCursor],
|
||||
};
|
||||
|
||||
let old_cursor: id = msg_send![class!(NSCursor), currentCursor];
|
||||
|
||||
@@ -238,11 +238,11 @@ impl Platform for TestPlatform {
|
||||
true
|
||||
}
|
||||
|
||||
fn write_to_clipboard(&self, item: crate::ClipboardItem) {
|
||||
fn write_to_clipboard(&self, item: ClipboardItem) {
|
||||
*self.current_clipboard_item.lock() = Some(item);
|
||||
}
|
||||
|
||||
fn read_from_clipboard(&self) -> Option<crate::ClipboardItem> {
|
||||
fn read_from_clipboard(&self) -> Option<ClipboardItem> {
|
||||
self.current_clipboard_item.lock().clone()
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,125 @@ pub trait Styled: Sized {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `text`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_text(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::IBeam);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `move`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_move(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::ClosedHand);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `not-allowed`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_not_allowed(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::OperationNotAllowed);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `context-menu`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_context_menu(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::ContextualMenu);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `crosshair`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_crosshair(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::Crosshair);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `vertical-text`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_vertical_text(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::IBeamCursorForVerticalLayout);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `alias`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_alias(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::DragLink);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `copy`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_copy(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::DragCopy);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `no-drop`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_no_drop(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::OperationNotAllowed);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `grab`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_grab(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::OpenHand);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `grabbing`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_grabbing(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::ClosedHand);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `col-resize`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_col_resize(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::ResizeLeftRight);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `row-resize`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_row_resize(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::ResizeUpDown);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `n-resize`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_n_resize(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::ResizeUp);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `e-resize`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_e_resize(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::ResizeRight);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `s-resize`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_s_resize(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::ResizeDown);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cursor style when hovering over an element to `w-resize`.
|
||||
/// [Docs](https://tailwindcss.com/docs/cursor)
|
||||
fn cursor_w_resize(mut self) -> Self {
|
||||
self.style().mouse_cursor = Some(CursorStyle::ResizeLeft);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the whitespace of the element to `normal`.
|
||||
/// [Docs](https://tailwindcss.com/docs/whitespace#normal)
|
||||
fn whitespace_normal(mut self) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user