Merge branch 'main' into picker
This commit is contained in:
@@ -12,7 +12,9 @@ use crate::{
|
||||
pub use block_map::{BlockMap, BlockPoint};
|
||||
use collections::{BTreeMap, HashMap, HashSet};
|
||||
use fold_map::FoldMap;
|
||||
use gpui::{Font, FontId, HighlightStyle, Hsla, Line, Model, ModelContext, Pixels, UnderlineStyle};
|
||||
use gpui::{
|
||||
Font, FontId, HighlightStyle, Hsla, Line, Model, ModelContext, Pixels, TextRun, UnderlineStyle,
|
||||
};
|
||||
use inlay_map::InlayMap;
|
||||
use language::{
|
||||
language_settings::language_settings, OffsetUtf16, Point, Subscription as BufferSubscription,
|
||||
@@ -21,7 +23,7 @@ use lsp::DiagnosticSeverity;
|
||||
use std::{any::TypeId, borrow::Cow, fmt::Debug, num::NonZeroU32, ops::Range, sync::Arc};
|
||||
use sum_tree::{Bias, TreeMap};
|
||||
use tab_map::TabMap;
|
||||
use theme::Theme;
|
||||
use theme::{SyntaxTheme, Theme};
|
||||
use wrap_map::WrapMap;
|
||||
|
||||
pub use block_map::{
|
||||
@@ -505,18 +507,18 @@ impl DisplaySnapshot {
|
||||
&'a self,
|
||||
display_rows: Range<u32>,
|
||||
language_aware: bool,
|
||||
theme: &'a Theme,
|
||||
editor_style: &'a EditorStyle,
|
||||
) -> impl Iterator<Item = HighlightedChunk<'a>> {
|
||||
self.chunks(
|
||||
display_rows,
|
||||
language_aware,
|
||||
None, // todo!("add inlay highlight style")
|
||||
None, // todo!("add suggestion highlight style")
|
||||
Some(editor_style.syntax.inlay_style),
|
||||
Some(editor_style.syntax.suggestion_style),
|
||||
)
|
||||
.map(|chunk| {
|
||||
let mut highlight_style = chunk
|
||||
.syntax_highlight_id
|
||||
.and_then(|id| id.style(&theme.styles.syntax));
|
||||
.and_then(|id| id.style(&editor_style.syntax));
|
||||
|
||||
if let Some(chunk_highlight) = chunk.highlight_style {
|
||||
if let Some(highlight_style) = highlight_style.as_mut() {
|
||||
@@ -535,7 +537,8 @@ impl DisplaySnapshot {
|
||||
if let Some(severity) = chunk.diagnostic_severity {
|
||||
// Omit underlines for HINT/INFO diagnostics on 'unnecessary' code.
|
||||
if severity <= DiagnosticSeverity::WARNING || !chunk.is_unnecessary {
|
||||
let diagnostic_color = super::diagnostic_style(severity, true, theme);
|
||||
let diagnostic_color =
|
||||
super::diagnostic_style(severity, true, &editor_style.diagnostic_style);
|
||||
diagnostic_highlight.underline = Some(UnderlineStyle {
|
||||
color: Some(diagnostic_color),
|
||||
thickness: 1.0.into(),
|
||||
@@ -564,53 +567,46 @@ impl DisplaySnapshot {
|
||||
TextLayoutDetails {
|
||||
text_system,
|
||||
editor_style,
|
||||
rem_size,
|
||||
}: &TextLayoutDetails,
|
||||
) -> Line {
|
||||
todo!()
|
||||
// let mut styles = Vec::new();
|
||||
// let mut line = String::new();
|
||||
// let mut ended_in_newline = false;
|
||||
let mut runs = Vec::new();
|
||||
let mut line = String::new();
|
||||
let mut ended_in_newline = false;
|
||||
|
||||
// let range = display_row..display_row + 1;
|
||||
// for chunk in self.highlighted_chunks(range, false, editor_style) {
|
||||
// line.push_str(chunk.chunk);
|
||||
let range = display_row..display_row + 1;
|
||||
for chunk in self.highlighted_chunks(range, false, &editor_style) {
|
||||
line.push_str(chunk.chunk);
|
||||
|
||||
// let text_style = if let Some(style) = chunk.style {
|
||||
// editor_style
|
||||
// .text
|
||||
// .clone()
|
||||
// .highlight(style, text_system)
|
||||
// .map(Cow::Owned)
|
||||
// .unwrap_or_else(|_| Cow::Borrowed(&editor_style.text))
|
||||
// } else {
|
||||
// Cow::Borrowed(&editor_style.text)
|
||||
// };
|
||||
// ended_in_newline = chunk.chunk.ends_with("\n");
|
||||
let text_style = if let Some(style) = chunk.style {
|
||||
editor_style
|
||||
.text
|
||||
.clone()
|
||||
.highlight(style)
|
||||
.map(Cow::Owned)
|
||||
.unwrap_or_else(|_| Cow::Borrowed(&editor_style.text))
|
||||
} else {
|
||||
Cow::Borrowed(&editor_style.text)
|
||||
};
|
||||
ended_in_newline = chunk.chunk.ends_with("\n");
|
||||
|
||||
// styles.push(
|
||||
// todo!(), // len: chunk.chunk.len(),
|
||||
// // font_id: text_style.font_id,
|
||||
// // color: text_style.color,
|
||||
// // underline: text_style.underline,
|
||||
// );
|
||||
// }
|
||||
runs.push(text_style.to_run(chunk.chunk.len()))
|
||||
}
|
||||
|
||||
// // our pixel positioning logic assumes each line ends in \n,
|
||||
// // this is almost always true except for the last line which
|
||||
// // may have no trailing newline.
|
||||
// if !ended_in_newline && display_row == self.max_point().row() {
|
||||
// line.push_str("\n");
|
||||
// our pixel positioning logic assumes each line ends in \n,
|
||||
// this is almost always true except for the last line which
|
||||
// may have no trailing newline.
|
||||
if !ended_in_newline && display_row == self.max_point().row() {
|
||||
line.push_str("\n");
|
||||
runs.push(editor_style.text.to_run("\n".len()));
|
||||
}
|
||||
|
||||
// todo!();
|
||||
// // styles.push(RunStyle {
|
||||
// // len: "\n".len(),
|
||||
// // font_id: editor_style.text.font_id,
|
||||
// // color: editor_style.text_color,
|
||||
// // underline: editor_style.text.underline,
|
||||
// // });
|
||||
// }
|
||||
|
||||
// text_system.layout_text(&line, editor_style.text.font_size, &styles, None)
|
||||
let font_size = editor_style.text.font_size.to_pixels(*rem_size);
|
||||
text_system
|
||||
.layout_text(&line, font_size, &runs, None)
|
||||
.unwrap()
|
||||
.pop()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn x_for_point(
|
||||
|
||||
+405
-397
File diff suppressed because it is too large
Load Diff
@@ -3,15 +3,15 @@ use crate::{
|
||||
editor_settings::ShowScrollbar,
|
||||
git::{diff_hunk_to_display, DisplayDiffHunk},
|
||||
CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
|
||||
Point, Selection, SoftWrap, ToPoint, MAX_LINE_LEN,
|
||||
MoveDown, Point, Selection, SoftWrap, ToPoint, MAX_LINE_LEN,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use collections::{BTreeMap, HashMap};
|
||||
use gpui::{
|
||||
black, hsla, point, px, relative, size, transparent_black, AnyElement, BorrowWindow, Bounds,
|
||||
ContentMask, Corners, DispatchPhase, Edges, Element, ElementId, Hsla, Line, Pixels,
|
||||
ScrollWheelEvent, ShapedGlyph, Size, StatefulInteractivity, Style, TextRun, TextStyle,
|
||||
TextSystem, ViewContext, WindowContext,
|
||||
black, hsla, point, px, relative, size, transparent_black, Action, AnyElement, BorrowWindow,
|
||||
Bounds, ContentMask, Corners, DispatchContext, DispatchPhase, Edges, Element, ElementId,
|
||||
Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Pixels, ScrollWheelEvent, ShapedGlyph,
|
||||
Size, StatefulInteractivity, Style, TextRun, TextStyle, TextSystem, ViewContext, WindowContext,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use language::language_settings::ShowWhitespaceSetting;
|
||||
@@ -20,6 +20,7 @@ use project::project_settings::{GitGutterSetting, ProjectSettings};
|
||||
use settings::Settings;
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
any::TypeId,
|
||||
borrow::Cow,
|
||||
cmp::{self, Ordering},
|
||||
fmt::Write,
|
||||
@@ -94,14 +95,12 @@ impl SelectionLayout {
|
||||
}
|
||||
|
||||
pub struct EditorElement {
|
||||
style: Arc<EditorStyle>,
|
||||
style: EditorStyle,
|
||||
}
|
||||
|
||||
impl EditorElement {
|
||||
pub fn new(style: EditorStyle) -> Self {
|
||||
Self {
|
||||
style: Arc::new(style),
|
||||
}
|
||||
Self { style }
|
||||
}
|
||||
|
||||
// fn attach_mouse_handlers(
|
||||
@@ -1578,12 +1577,10 @@ impl EditorElement {
|
||||
})
|
||||
.collect()
|
||||
} else {
|
||||
let style = &self.style;
|
||||
let chunks = snapshot.highlighted_chunks(rows.clone(), true, cx.theme());
|
||||
|
||||
let chunks = snapshot.highlighted_chunks(rows.clone(), true, &self.style);
|
||||
LineWithInvisibles::from_chunks(
|
||||
chunks,
|
||||
&style.text,
|
||||
&self.style.text,
|
||||
MAX_LINE_LEN,
|
||||
rows.len() as usize,
|
||||
line_number_layouts,
|
||||
@@ -2554,7 +2551,37 @@ impl Element<Editor> for EditorElement {
|
||||
element_state: Option<Self::ElementState>,
|
||||
cx: &mut gpui::ViewContext<Editor>,
|
||||
) -> Self::ElementState {
|
||||
()
|
||||
editor.style = Some(self.style.clone()); // Long-term, we'd like to eliminate this.
|
||||
|
||||
let dispatch_context = editor.dispatch_context(cx);
|
||||
cx.with_element_id(cx.view().entity_id(), |global_id, cx| {
|
||||
cx.with_key_dispatch_context(dispatch_context, |cx| {
|
||||
cx.with_key_listeners(
|
||||
[
|
||||
build_action_listener(Editor::move_left),
|
||||
build_action_listener(Editor::move_right),
|
||||
build_action_listener(Editor::move_down),
|
||||
build_action_listener(Editor::move_up),
|
||||
build_key_listener(
|
||||
move |editor, key_down: &KeyDownEvent, dispatch_context, phase, cx| {
|
||||
if phase == DispatchPhase::Bubble {
|
||||
if let KeyMatch::Some(action) = cx.match_keystroke(
|
||||
&global_id,
|
||||
&key_down.keystroke,
|
||||
dispatch_context,
|
||||
) {
|
||||
return Some(action);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
},
|
||||
),
|
||||
],
|
||||
|cx| cx.with_focus(editor.focus_handle.clone(), |_| {}),
|
||||
);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn layout(
|
||||
@@ -4080,3 +4107,33 @@ fn scale_horizontal_mouse_autoscroll_delta(delta: f32) -> f32 {
|
||||
// .collect()
|
||||
// }
|
||||
// }
|
||||
|
||||
fn build_key_listener<T: 'static>(
|
||||
listener: impl Fn(
|
||||
&mut Editor,
|
||||
&T,
|
||||
&[&DispatchContext],
|
||||
DispatchPhase,
|
||||
&mut ViewContext<Editor>,
|
||||
) -> Option<Box<dyn Action>>
|
||||
+ 'static,
|
||||
) -> (TypeId, KeyListener<Editor>) {
|
||||
(
|
||||
TypeId::of::<T>(),
|
||||
Box::new(move |editor, event, dispatch_context, phase, cx| {
|
||||
let key_event = event.downcast_ref::<T>()?;
|
||||
listener(editor, key_event, dispatch_context, phase, cx)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
fn build_action_listener<T: Action>(
|
||||
listener: impl Fn(&mut Editor, &T, &mut ViewContext<Editor>) + 'static,
|
||||
) -> (TypeId, KeyListener<Editor>) {
|
||||
build_key_listener(move |editor, action: &T, dispatch_context, phase, cx| {
|
||||
if phase == DispatchPhase::Bubble {
|
||||
listener(editor, action, cx);
|
||||
}
|
||||
None
|
||||
})
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ pub fn refresh_matching_bracket_highlights(editor: &mut Editor, cx: &mut ViewCon
|
||||
opening_range.to_anchors(&snapshot.buffer_snapshot),
|
||||
closing_range.to_anchors(&snapshot.buffer_snapshot),
|
||||
],
|
||||
|theme| todo!("theme.editor.document_highlight_read_background"),
|
||||
|theme| theme.editor_document_highlight_read_background,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
|
||||
use crate::{char_kind, CharKind, EditorStyle, ToOffset, ToPoint};
|
||||
use gpui::{px, TextSystem};
|
||||
use gpui::{px, Pixels, TextSystem};
|
||||
use language::Point;
|
||||
use serde::de::IntoDeserializer;
|
||||
use std::ops::Range;
|
||||
use std::{ops::Range, sync::Arc};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum FindRange {
|
||||
@@ -14,8 +14,9 @@ pub enum FindRange {
|
||||
/// TextLayoutDetails encompasses everything we need to move vertically
|
||||
/// taking into account variable width characters.
|
||||
pub struct TextLayoutDetails {
|
||||
pub text_system: TextSystem,
|
||||
pub text_system: Arc<TextSystem>,
|
||||
pub editor_style: EditorStyle,
|
||||
pub rem_size: Pixels,
|
||||
}
|
||||
|
||||
pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
|
||||
|
||||
@@ -349,10 +349,12 @@ impl Editor {
|
||||
self.refresh_inlay_hints(InlayHintRefreshReason::NewLinesShown, cx);
|
||||
}
|
||||
|
||||
// pub fn scroll_position(&self, cx: &mut ViewContext<Self>) -> gpui::Point<Pixels> {
|
||||
// let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
// self.scroll_manager.anchor.scroll_position(&display_map)
|
||||
// }
|
||||
pub fn scroll_position(&self, cx: &mut ViewContext<Self>) -> gpui::Point<Pixels> {
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
// todo!() Should `self.scroll_manager.anchor.scroll_position()` return `Pixels`?
|
||||
// self.scroll_manager.anchor.scroll_position(&display_map)
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn set_scroll_anchor(&mut self, scroll_anchor: ScrollAnchor, cx: &mut ViewContext<Self>) {
|
||||
hide_hover(self, cx);
|
||||
|
||||
Reference in New Issue
Block a user