Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into jk
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradIrwin committed Jan 22, 2024
2 parents 4143d3a + 9bcf27b commit b9c7baf
Show file tree
Hide file tree
Showing 28 changed files with 1,573 additions and 1,394 deletions.
37 changes: 22 additions & 15 deletions crates/diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,27 +1584,34 @@ mod tests {
}

fn editor_blocks(editor: &View<Editor>, cx: &mut WindowContext) -> Vec<(u32, SharedString)> {
let editor_view = editor.clone();
editor.update(cx, |editor, cx| {
let snapshot = editor.snapshot(cx);
snapshot
.blocks_in_range(0..snapshot.max_point().row())
.enumerate()
.filter_map(|(ix, (row, block))| {
let name = match block {
TransformBlock::Custom(block) => block
.render(&mut BlockContext {
view_context: cx,
anchor_x: px(0.),
gutter_padding: px(0.),
gutter_width: px(0.),
line_height: px(0.),
em_width: px(0.),
block_id: ix,
editor_style: &editor::EditorStyle::default(),
})
.inner_id()?
.try_into()
.ok()?,
let name: SharedString = match block {
TransformBlock::Custom(block) => cx.with_element_context({
let editor_view = editor_view.clone();
|cx| -> Option<SharedString> {
block
.render(&mut BlockContext {
context: cx,
anchor_x: px(0.),
gutter_padding: px(0.),
gutter_width: px(0.),
line_height: px(0.),
em_width: px(0.),
block_id: ix,
view: editor_view,
editor_style: &editor::EditorStyle::default(),
})
.inner_id()?
.try_into()
.ok()
}
})?,

TransformBlock::ExcerptHeader {
starts_new_buffer, ..
Expand Down
11 changes: 6 additions & 5 deletions crates/editor/src/display_map/block_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
};
use crate::{Anchor, Editor, EditorStyle, ExcerptId, ExcerptRange, ToPoint as _};
use collections::{Bound, HashMap, HashSet};
use gpui::{AnyElement, Pixels, ViewContext};
use gpui::{AnyElement, ElementContext, Pixels, View};
use language::{BufferSnapshot, Chunk, Patch, Point};
use parking_lot::Mutex;
use std::{
Expand Down Expand Up @@ -81,7 +81,8 @@ pub enum BlockStyle {
}

pub struct BlockContext<'a, 'b> {
pub view_context: &'b mut ViewContext<'a, Editor>,
pub context: &'b mut ElementContext<'a>,
pub view: View<Editor>,
pub anchor_x: Pixels,
pub gutter_width: Pixels,
pub gutter_padding: Pixels,
Expand Down Expand Up @@ -933,16 +934,16 @@ impl BlockDisposition {
}

impl<'a> Deref for BlockContext<'a, '_> {
type Target = ViewContext<'a, Editor>;
type Target = ElementContext<'a>;

fn deref(&self) -> &Self::Target {
self.view_context
self.context
}
}

impl DerefMut for BlockContext<'_, '_> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.view_context
self.context
}
}

Expand Down
27 changes: 16 additions & 11 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3912,7 +3912,7 @@ impl Editor {
gutter_hovered: bool,
_line_height: Pixels,
_gutter_margin: Pixels,
cx: &mut ViewContext<Self>,
editor_view: View<Editor>,
) -> Vec<Option<IconButton>> {
fold_data
.iter()
Expand All @@ -3922,14 +3922,19 @@ impl Editor {
.map(|(fold_status, buffer_row, active)| {
(active || gutter_hovered || fold_status == FoldStatus::Folded).then(|| {
IconButton::new(ix as usize, ui::IconName::ChevronDown)
.on_click(cx.listener(move |editor, _e, cx| match fold_status {
FoldStatus::Folded => {
editor.unfold_at(&UnfoldAt { buffer_row }, cx);
}
FoldStatus::Foldable => {
editor.fold_at(&FoldAt { buffer_row }, cx);
.on_click({
let view = editor_view.clone();
move |_e, cx| {
view.update(cx, |editor, cx| match fold_status {
FoldStatus::Folded => {
editor.unfold_at(&UnfoldAt { buffer_row }, cx);
}
FoldStatus::Foldable => {
editor.fold_at(&FoldAt { buffer_row }, cx);
}
})
}
}))
})
.icon_color(ui::Color::Muted)
.icon_size(ui::IconSize::Small)
.selected(fold_status == FoldStatus::Folded)
Expand Down Expand Up @@ -9575,10 +9580,10 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, _is_valid: bool) -> Ren
.size(ButtonSize::Compact)
.style(ButtonStyle::Transparent)
.visible_on_hover(group_id)
.on_click(cx.listener({
.on_click({
let message = diagnostic.message.clone();
move |_, _, cx| cx.write_to_clipboard(ClipboardItem::new(message.clone()))
}))
move |_click, cx| cx.write_to_clipboard(ClipboardItem::new(message.clone()))
})
.tooltip(|cx| Tooltip::text("Copy diagnostic message", cx)),
)
.into_any_element()
Expand Down
Loading

0 comments on commit b9c7baf

Please sign in to comment.