From 078fd35f4fbc22c5de5604ebcf5561283532b9d2 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Wed, 17 Jan 2024 15:52:54 -0800 Subject: [PATCH 1/2] WIP --- crates/editor/src/completions.rs | 28 +++++++++++++++ crates/editor/src/element.rs | 25 +++++++------ .../src/platform/mac/window_appearance.rs | 35 +++++++++++++++++++ 3 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 crates/editor/src/completions.rs create mode 100644 crates/gpui/src/platform/mac/window_appearance.rs diff --git a/crates/editor/src/completions.rs b/crates/editor/src/completions.rs new file mode 100644 index 0000000000..b9461364af --- /dev/null +++ b/crates/editor/src/completions.rs @@ -0,0 +1,28 @@ +use futures::Future; +use gpui::Task; +use smallvec::{smallvec, SmallVec}; +use text::Anchor; + +use crate::Editor; + +struct Completions { + trigger_characters: SmallVec<[char; 1]>, + language: Option, + provider: Box Option>>, +} + +impl Completions { + fn new(f: impl Fn(&mut Editor, &Anchor, &str) -> Option> + 'static) -> Self { + Self { + trigger_characters: smallvec![], + language: None, + provider: Box::new(f), + } + } +} + +impl Editor { + /// Provide completions to the editor when the given character is typed + /// + fn provide_completions(config: Completions) {} +} diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index b82bd55bcf..518e03c27e 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -2543,18 +2543,21 @@ impl EditorElement { move |event: &MouseUpEvent, phase, cx| { if phase == DispatchPhase::Bubble - && interactive_bounds.visibly_contains(&event.position, cx) { - editor.update(cx, |editor, cx| { - Self::mouse_up( - editor, - event, - &position_map, - text_bounds, - &stacking_order, - cx, - ) - }); + // if interactive_bounds.visibly_contains(&event.position, cx) { + editor.update(cx, |editor, cx| { + Self::mouse_up( + editor, + event, + &position_map, + text_bounds, + &stacking_order, + cx, + ) + }); + // } else { + + // } } } }); diff --git a/crates/gpui/src/platform/mac/window_appearance.rs b/crates/gpui/src/platform/mac/window_appearance.rs new file mode 100644 index 0000000000..2edc896289 --- /dev/null +++ b/crates/gpui/src/platform/mac/window_appearance.rs @@ -0,0 +1,35 @@ +use crate::WindowAppearance; +use cocoa::{ + appkit::{NSAppearanceNameVibrantDark, NSAppearanceNameVibrantLight}, + base::id, + foundation::NSString, +}; +use objc::{msg_send, sel, sel_impl}; +use std::ffi::CStr; + +impl WindowAppearance { + pub unsafe fn from_native(appearance: id) -> Self { + let name: id = msg_send![appearance, name]; + if name == NSAppearanceNameVibrantLight { + Self::VibrantLight + } else if name == NSAppearanceNameVibrantDark { + Self::VibrantDark + } else if name == NSAppearanceNameAqua { + Self::Light + } else if name == NSAppearanceNameDarkAqua { + Self::Dark + } else { + println!( + "unknown appearance: {:?}", + CStr::from_ptr(name.UTF8String()) + ); + Self::Light + } + } +} + +#[link(name = "AppKit", kind = "framework")] +extern "C" { + pub static NSAppearanceNameAqua: id; + pub static NSAppearanceNameDarkAqua: id; +} From edb204511c0339de1726038bcad4a8a046bf252e Mon Sep 17 00:00:00 2001 From: Mikayla Date: Wed, 17 Jan 2024 16:24:33 -0800 Subject: [PATCH 2/2] Fix selection bug in editor causing selections to be un-ended --- crates/editor/src/completions.rs | 28 --------------- crates/editor/src/element.rs | 32 ++++++++--------- .../src/platform/mac/window_appearance.rs | 35 ------------------- 3 files changed, 15 insertions(+), 80 deletions(-) delete mode 100644 crates/editor/src/completions.rs delete mode 100644 crates/gpui/src/platform/mac/window_appearance.rs diff --git a/crates/editor/src/completions.rs b/crates/editor/src/completions.rs deleted file mode 100644 index b9461364af..0000000000 --- a/crates/editor/src/completions.rs +++ /dev/null @@ -1,28 +0,0 @@ -use futures::Future; -use gpui::Task; -use smallvec::{smallvec, SmallVec}; -use text::Anchor; - -use crate::Editor; - -struct Completions { - trigger_characters: SmallVec<[char; 1]>, - language: Option, - provider: Box Option>>, -} - -impl Completions { - fn new(f: impl Fn(&mut Editor, &Anchor, &str) -> Option> + 'static) -> Self { - Self { - trigger_characters: smallvec![], - language: None, - provider: Box::new(f), - } - } -} - -impl Editor { - /// Provide completions to the editor when the given character is typed - /// - fn provide_completions(config: Completions) {} -} diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 518e03c27e..d7ce842e1d 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -456,6 +456,7 @@ impl EditorElement { event: &MouseUpEvent, position_map: &PositionMap, text_bounds: Bounds, + interactive_bounds: &InteractiveBounds, stacking_order: &StackingOrder, cx: &mut ViewContext, ) { @@ -466,7 +467,8 @@ impl EditorElement { editor.select(SelectPhase::End, cx); } - if !pending_nonempty_selections + if interactive_bounds.visibly_contains(&event.position, cx) + && !pending_nonempty_selections && event.modifiers.command && text_bounds.contains(&event.position) && cx.was_top_layer(&event.position, stacking_order) @@ -2542,22 +2544,18 @@ impl EditorElement { let interactive_bounds = interactive_bounds.clone(); move |event: &MouseUpEvent, phase, cx| { - if phase == DispatchPhase::Bubble - { - // if interactive_bounds.visibly_contains(&event.position, cx) { - editor.update(cx, |editor, cx| { - Self::mouse_up( - editor, - event, - &position_map, - text_bounds, - &stacking_order, - cx, - ) - }); - // } else { - - // } + if phase == DispatchPhase::Bubble { + editor.update(cx, |editor, cx| { + Self::mouse_up( + editor, + event, + &position_map, + text_bounds, + &interactive_bounds, + &stacking_order, + cx, + ) + }); } } }); diff --git a/crates/gpui/src/platform/mac/window_appearance.rs b/crates/gpui/src/platform/mac/window_appearance.rs deleted file mode 100644 index 2edc896289..0000000000 --- a/crates/gpui/src/platform/mac/window_appearance.rs +++ /dev/null @@ -1,35 +0,0 @@ -use crate::WindowAppearance; -use cocoa::{ - appkit::{NSAppearanceNameVibrantDark, NSAppearanceNameVibrantLight}, - base::id, - foundation::NSString, -}; -use objc::{msg_send, sel, sel_impl}; -use std::ffi::CStr; - -impl WindowAppearance { - pub unsafe fn from_native(appearance: id) -> Self { - let name: id = msg_send![appearance, name]; - if name == NSAppearanceNameVibrantLight { - Self::VibrantLight - } else if name == NSAppearanceNameVibrantDark { - Self::VibrantDark - } else if name == NSAppearanceNameAqua { - Self::Light - } else if name == NSAppearanceNameDarkAqua { - Self::Dark - } else { - println!( - "unknown appearance: {:?}", - CStr::from_ptr(name.UTF8String()) - ); - Self::Light - } - } -} - -#[link(name = "AppKit", kind = "framework")] -extern "C" { - pub static NSAppearanceNameAqua: id; - pub static NSAppearanceNameDarkAqua: id; -}