Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge branch 'main' into picker

Max Brunsfeld69eb49a2ed4a
diff --cc crates/editor2/src/element.rs
index 4e42124c02d,4d8cd57abcf..5623374b3ee
--- a/crates/editor2/src/element.rs
+++ b/crates/editor2/src/element.rs
@@@ -1,20 -1,35 +1,35 @@@
- use super::{
- display_map::ToDisplayPoint, DisplayPoint, Editor, EditorSnapshot, ToPoint, MAX_LINE_LEN,
- };
use crate::{
- display_map::{BlockStyle, DisplaySnapshot},
- EditorMode, EditorStyle, SoftWrap,
+ display_map::{BlockStyle, DisplaySnapshot, FoldStatus, HighlightedChunk, ToDisplayPoint},
+ editor_settings::ShowScrollbar,
+ git::{diff_hunk_to_display, DisplayDiffHunk},
+ CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
+ Point, Selection, SoftWrap, ToPoint, MAX_LINE_LEN,
};
use anyhow::Result;
+ use collections::{BTreeMap, HashMap};
use gpui::{
- black, point, px, relative, size, AnyElement, Bounds, Element, Hsla, Line, Pixels, Size, Style,
- TextRun, TextSystem, ViewContext,
+ black, hsla, point, px, relative, size, transparent_black, AnyElement, BorrowWindow, Bounds,
+ ContentMask, Corners, DispatchPhase, Edges, Element, ElementId, Hsla, Line, Pixels,
- ScrollWheelEvent, ShapedGlyph, Size, StatefulInteraction, Style, TextRun, TextStyle,
++ ScrollWheelEvent, ShapedGlyph, Size, StatefulInteractivity, Style, TextRun, TextStyle,
+ TextSystem, ViewContext, WindowContext,
};
- use language::{CursorShape, Selection};
+ use itertools::Itertools;
+ use language::language_settings::ShowWhitespaceSetting;
+ use multi_buffer::Anchor;
+ use project::project_settings::{GitGutterSetting, ProjectSettings};
+ use settings::Settings;
use smallvec::SmallVec;
- use std::{cmp, ops::Range, sync::Arc};
+ use std::{
+ borrow::Cow,
+ cmp::{self, Ordering},
+ fmt::Write,
+ iter,
+ ops::Range,
+ sync::Arc,
+ };
use sum_tree::Bias;
- use theme::ActiveTheme;
+ use theme::{ActiveTheme, PlayerColor};
+ use workspace::item::Item;
enum FoldMarkers {}
diff --cc crates/gpui2/src/elements/div.rs
index 77d066729e5,061ec095f89..9b8c9dbf855
--- a/crates/gpui2/src/elements/div.rs
+++ b/crates/gpui2/src/elements/div.rs
@@@ -213,10 -209,10 +213,10 @@@ wher
cx: &mut ViewContext<V>,
) -> Self::ElementState {
let mut element_state = element_state.unwrap_or_default();
- self.focus
- .initialize(element_state.focus_handle.take(), cx, |focus_handle, cx| {
- element_state.focus_handle = focus_handle;
- self.interactivity.initialize(cx, |cx| {
- self.interaction.initialize(cx, |cx| {
++ self.interactivity.initialize(cx, |cx| {
+ self.focus
+ .initialize(element_state.focus_handle.take(), cx, |focus_handle, cx| {
+ element_state.focus_handle = focus_handle;
for child in &mut self.children {
child.initialize(view_state, cx);
}
diff --cc crates/gpui2/src/geometry.rs
index a9df7569325,e16635be362..c5209239aea
--- a/crates/gpui2/src/geometry.rs
+++ b/crates/gpui2/src/geometry.rs
@@@ -757,8 -747,17 +774,9 @@@ impl MulAssign<f32> for Pixels
}
impl Pixels {
+ pub const ZERO: Pixels = Pixels(0.0);
pub const MAX: Pixels = Pixels(f32::MAX);
- pub fn as_usize(&self) -> usize {
- self.0 as usize
- }
-
- pub fn as_isize(&self) -> isize {
- self.0 as isize
- }
-
pub fn floor(&self) -> Self {
Self(self.0.floor())
}
diff --cc crates/gpui2/src/interactive.rs
index 9d0b896673f,0725a10aca0..2fa3ceeac2e
--- a/crates/gpui2/src/interactive.rs
+++ b/crates/gpui2/src/interactive.rs
@@@ -1255,3 -1230,70 +1255,70 @@@ pub type KeyListener<V> = Box
) -> Option<Box<dyn Action>>
+ 'static,
>;
+
+ #[cfg(test)]
+ mod test {
+ use crate::{
+ self as gpui, div, Div, FocusHandle, KeyBinding, Keystroke, ParentElement, Render,
- StatefulInteraction, StatelessInteractive, TestAppContext, VisualContext,
++ StatefulInteractivity, StatelessInteractive, TestAppContext, VisualContext,
+ };
+
+ struct TestView {
+ saw_key_down: bool,
+ saw_action: bool,
+ focus_handle: FocusHandle,
+ }
+
+ actions!(TestAction);
+
+ impl Render for TestView {
- type Element = Div<Self, StatefulInteraction<Self>>;
++ type Element = Div<Self, StatefulInteractivity<Self>>;
+
+ fn render(&mut self, _: &mut gpui::ViewContext<Self>) -> Self::Element {
+ div().id("testview").child(
+ div()
+ .on_key_down(|this: &mut TestView, _, _, _| {
+ dbg!("ola!");
+ this.saw_key_down = true
+ })
- .on_action(|this: &mut TestView, _: &TestAction, _, _| {
++ .on_action(|this: &mut TestView, _: &TestAction, _| {
+ dbg!("ola!");
+ this.saw_action = true
+ })
+ .track_focus(&self.focus_handle),
+ )
+ }
+ }
+
+ #[gpui::test]
+ fn test_on_events(cx: &mut TestAppContext) {
+ let window = cx.update(|cx| {
+ cx.open_window(Default::default(), |cx| {
+ cx.build_view(|cx| TestView {
+ saw_key_down: false,
+ saw_action: false,
+ focus_handle: cx.focus_handle(),
+ })
+ })
+ });
+
+ cx.update(|cx| {
+ cx.bind_keys(vec![KeyBinding::new("ctrl-g", TestAction, None)]);
+ });
+
+ window
+ .update(cx, |test_view, cx| cx.focus(&test_view.focus_handle))
+ .unwrap();
+
+ cx.dispatch_keystroke(*window, Keystroke::parse("space").unwrap(), false);
+ cx.dispatch_keystroke(*window, Keystroke::parse("ctrl-g").unwrap(), false);
+
+ window
+ .update(cx, |test_view, _| {
+ assert!(test_view.saw_key_down || test_view.saw_action);
+ assert!(test_view.saw_key_down);
+ assert!(test_view.saw_action);
+ })
+ .unwrap();
+ }
+ }
diff --cc crates/gpui2/src/styled.rs
index f45e6a219e1,06be0368c02..c27347f2b1b
--- a/crates/gpui2/src/styled.rs
+++ b/crates/gpui2/src/styled.rs
@@@ -1,10 -1,9 +1,10 @@@
use crate::{
- self as gpui, hsla, point, px, relative, rems, AlignItems, CursorStyle, DefiniteLength,
- Display, Fill, FlexDirection, Hsla, JustifyContent, Length, Position, Rems, SharedString,
- Style, StyleRefinement, Visibility,
+ self as gpui, hsla, point, px, relative, rems, AbsoluteLength, AlignItems, CursorStyle,
+ DefiniteLength, Display, Fill, FlexDirection, Hsla, JustifyContent, Length, Position,
- SharedString, StyleRefinement, Visibility,
++ SharedString, Style, StyleRefinement, Visibility,
};
use crate::{BoxShadow, TextStyleRefinement};
+use refineable::Refineable;
use smallvec::smallvec;
pub trait Styled {
diff --cc crates/storybook2/src/stories/focus.rs
index bfd7d5fa1c2,0f580d0cbf1..cae68c21e83
--- a/crates/storybook2/src/stories/focus.rs
+++ b/crates/storybook2/src/stories/focus.rs
@@@ -1,18 -1,10 +1,10 @@@
use gpui::{
- div, Div, FocusEnabled, Focusable, KeyBinding, ParentElement, Render, StatefulInteractivity,
- StatelessInteractive, Styled, View, VisualContext, WindowContext,
+ actions, div, Div, FocusEnabled, Focusable, KeyBinding, ParentElement, Render,
- StatefulInteraction, StatelessInteractive, Styled, View, VisualContext, WindowContext,
++ StatefulInteractivity, StatelessInteractive, Styled, View, VisualContext, WindowContext,
};
- use serde::Deserialize;
use theme2::ActiveTheme;
- #[derive(Clone, Default, PartialEq, Deserialize)]
- struct ActionA;
-
- #[derive(Clone, Default, PartialEq, Deserialize)]
- struct ActionB;
-
- #[derive(Clone, Default, PartialEq, Deserialize)]
- struct ActionC;
+ actions!(ActionA, ActionB, ActionC);
pub struct FocusStory {}