commit
4bf3a4e3d4
17 changed files with 639 additions and 481 deletions
|
@ -12,7 +12,9 @@ use crate::{
|
||||||
pub use block_map::{BlockMap, BlockPoint};
|
pub use block_map::{BlockMap, BlockPoint};
|
||||||
use collections::{BTreeMap, HashMap, HashSet};
|
use collections::{BTreeMap, HashMap, HashSet};
|
||||||
use fold_map::FoldMap;
|
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 inlay_map::InlayMap;
|
||||||
use language::{
|
use language::{
|
||||||
language_settings::language_settings, OffsetUtf16, Point, Subscription as BufferSubscription,
|
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 std::{any::TypeId, borrow::Cow, fmt::Debug, num::NonZeroU32, ops::Range, sync::Arc};
|
||||||
use sum_tree::{Bias, TreeMap};
|
use sum_tree::{Bias, TreeMap};
|
||||||
use tab_map::TabMap;
|
use tab_map::TabMap;
|
||||||
use theme::Theme;
|
use theme::{SyntaxTheme, Theme};
|
||||||
use wrap_map::WrapMap;
|
use wrap_map::WrapMap;
|
||||||
|
|
||||||
pub use block_map::{
|
pub use block_map::{
|
||||||
|
@ -505,18 +507,18 @@ impl DisplaySnapshot {
|
||||||
&'a self,
|
&'a self,
|
||||||
display_rows: Range<u32>,
|
display_rows: Range<u32>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
theme: &'a Theme,
|
editor_style: &'a EditorStyle,
|
||||||
) -> impl Iterator<Item = HighlightedChunk<'a>> {
|
) -> impl Iterator<Item = HighlightedChunk<'a>> {
|
||||||
self.chunks(
|
self.chunks(
|
||||||
display_rows,
|
display_rows,
|
||||||
language_aware,
|
language_aware,
|
||||||
None, // todo!("add inlay highlight style")
|
Some(editor_style.syntax.inlay_style),
|
||||||
None, // todo!("add suggestion highlight style")
|
Some(editor_style.syntax.suggestion_style),
|
||||||
)
|
)
|
||||||
.map(|chunk| {
|
.map(|chunk| {
|
||||||
let mut highlight_style = chunk
|
let mut highlight_style = chunk
|
||||||
.syntax_highlight_id
|
.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(chunk_highlight) = chunk.highlight_style {
|
||||||
if let Some(highlight_style) = highlight_style.as_mut() {
|
if let Some(highlight_style) = highlight_style.as_mut() {
|
||||||
|
@ -535,7 +537,8 @@ impl DisplaySnapshot {
|
||||||
if let Some(severity) = chunk.diagnostic_severity {
|
if let Some(severity) = chunk.diagnostic_severity {
|
||||||
// Omit underlines for HINT/INFO diagnostics on 'unnecessary' code.
|
// Omit underlines for HINT/INFO diagnostics on 'unnecessary' code.
|
||||||
if severity <= DiagnosticSeverity::WARNING || !chunk.is_unnecessary {
|
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 {
|
diagnostic_highlight.underline = Some(UnderlineStyle {
|
||||||
color: Some(diagnostic_color),
|
color: Some(diagnostic_color),
|
||||||
thickness: 1.0.into(),
|
thickness: 1.0.into(),
|
||||||
|
@ -564,53 +567,46 @@ impl DisplaySnapshot {
|
||||||
TextLayoutDetails {
|
TextLayoutDetails {
|
||||||
text_system,
|
text_system,
|
||||||
editor_style,
|
editor_style,
|
||||||
|
rem_size,
|
||||||
}: &TextLayoutDetails,
|
}: &TextLayoutDetails,
|
||||||
) -> Line {
|
) -> Line {
|
||||||
todo!()
|
let mut runs = Vec::new();
|
||||||
// let mut styles = Vec::new();
|
let mut line = String::new();
|
||||||
// let mut line = String::new();
|
let mut ended_in_newline = false;
|
||||||
// let mut ended_in_newline = false;
|
|
||||||
|
|
||||||
// let range = display_row..display_row + 1;
|
let range = display_row..display_row + 1;
|
||||||
// for chunk in self.highlighted_chunks(range, false, editor_style) {
|
for chunk in self.highlighted_chunks(range, false, &editor_style) {
|
||||||
// line.push_str(chunk.chunk);
|
line.push_str(chunk.chunk);
|
||||||
|
|
||||||
// let text_style = if let Some(style) = chunk.style {
|
let text_style = if let Some(style) = chunk.style {
|
||||||
// editor_style
|
editor_style
|
||||||
// .text
|
.text
|
||||||
// .clone()
|
.clone()
|
||||||
// .highlight(style, text_system)
|
.highlight(style)
|
||||||
// .map(Cow::Owned)
|
.map(Cow::Owned)
|
||||||
// .unwrap_or_else(|_| Cow::Borrowed(&editor_style.text))
|
.unwrap_or_else(|_| Cow::Borrowed(&editor_style.text))
|
||||||
// } else {
|
} else {
|
||||||
// Cow::Borrowed(&editor_style.text)
|
Cow::Borrowed(&editor_style.text)
|
||||||
// };
|
};
|
||||||
// ended_in_newline = chunk.chunk.ends_with("\n");
|
ended_in_newline = chunk.chunk.ends_with("\n");
|
||||||
|
|
||||||
// styles.push(
|
runs.push(text_style.to_run(chunk.chunk.len()))
|
||||||
// todo!(), // len: chunk.chunk.len(),
|
}
|
||||||
// // font_id: text_style.font_id,
|
|
||||||
// // color: text_style.color,
|
|
||||||
// // underline: text_style.underline,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // our pixel positioning logic assumes each line ends in \n,
|
// our pixel positioning logic assumes each line ends in \n,
|
||||||
// // this is almost always true except for the last line which
|
// this is almost always true except for the last line which
|
||||||
// // may have no trailing newline.
|
// may have no trailing newline.
|
||||||
// if !ended_in_newline && display_row == self.max_point().row() {
|
if !ended_in_newline && display_row == self.max_point().row() {
|
||||||
// line.push_str("\n");
|
line.push_str("\n");
|
||||||
|
runs.push(editor_style.text.to_run("\n".len()));
|
||||||
|
}
|
||||||
|
|
||||||
// todo!();
|
let font_size = editor_style.text.font_size.to_pixels(*rem_size);
|
||||||
// // styles.push(RunStyle {
|
text_system
|
||||||
// // len: "\n".len(),
|
.layout_text(&line, font_size, &runs, None)
|
||||||
// // font_id: editor_style.text.font_id,
|
.unwrap()
|
||||||
// // color: editor_style.text_color,
|
.pop()
|
||||||
// // underline: editor_style.text.underline,
|
.unwrap()
|
||||||
// // });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// text_system.layout_text(&line, editor_style.text.font_size, &styles, None)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn x_for_point(
|
pub fn x_for_point(
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,15 +3,15 @@ use crate::{
|
||||||
editor_settings::ShowScrollbar,
|
editor_settings::ShowScrollbar,
|
||||||
git::{diff_hunk_to_display, DisplayDiffHunk},
|
git::{diff_hunk_to_display, DisplayDiffHunk},
|
||||||
CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
|
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 anyhow::Result;
|
||||||
use collections::{BTreeMap, HashMap};
|
use collections::{BTreeMap, HashMap};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
black, hsla, point, px, relative, size, transparent_black, AnyElement, BorrowWindow, Bounds,
|
black, hsla, point, px, relative, size, transparent_black, Action, AnyElement, BorrowWindow,
|
||||||
ContentMask, Corners, DispatchPhase, Edges, Element, ElementId, Hsla, Line, Pixels,
|
Bounds, ContentMask, Corners, DispatchContext, DispatchPhase, Edges, Element, ElementId,
|
||||||
ScrollWheelEvent, ShapedGlyph, Size, StatefulInteraction, Style, TextRun, TextStyle,
|
Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Pixels, ScrollWheelEvent, ShapedGlyph,
|
||||||
TextSystem, ViewContext, WindowContext,
|
Size, StatefulInteraction, Style, TextRun, TextStyle, TextSystem, ViewContext, WindowContext,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use language::language_settings::ShowWhitespaceSetting;
|
use language::language_settings::ShowWhitespaceSetting;
|
||||||
|
@ -20,6 +20,7 @@ use project::project_settings::{GitGutterSetting, ProjectSettings};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::{
|
use std::{
|
||||||
|
any::TypeId,
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
cmp::{self, Ordering},
|
cmp::{self, Ordering},
|
||||||
fmt::Write,
|
fmt::Write,
|
||||||
|
@ -94,14 +95,12 @@ impl SelectionLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EditorElement {
|
pub struct EditorElement {
|
||||||
style: Arc<EditorStyle>,
|
style: EditorStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EditorElement {
|
impl EditorElement {
|
||||||
pub fn new(style: EditorStyle) -> Self {
|
pub fn new(style: EditorStyle) -> Self {
|
||||||
Self {
|
Self { style }
|
||||||
style: Arc::new(style),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn attach_mouse_handlers(
|
// fn attach_mouse_handlers(
|
||||||
|
@ -1578,12 +1577,10 @@ impl EditorElement {
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
let style = &self.style;
|
let chunks = snapshot.highlighted_chunks(rows.clone(), true, &self.style);
|
||||||
let chunks = snapshot.highlighted_chunks(rows.clone(), true, cx.theme());
|
|
||||||
|
|
||||||
LineWithInvisibles::from_chunks(
|
LineWithInvisibles::from_chunks(
|
||||||
chunks,
|
chunks,
|
||||||
&style.text,
|
&self.style.text,
|
||||||
MAX_LINE_LEN,
|
MAX_LINE_LEN,
|
||||||
rows.len() as usize,
|
rows.len() as usize,
|
||||||
line_number_layouts,
|
line_number_layouts,
|
||||||
|
@ -2554,7 +2551,37 @@ impl Element<Editor> for EditorElement {
|
||||||
element_state: Option<Self::ElementState>,
|
element_state: Option<Self::ElementState>,
|
||||||
cx: &mut gpui::ViewContext<Editor>,
|
cx: &mut gpui::ViewContext<Editor>,
|
||||||
) -> Self::ElementState {
|
) -> 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(
|
fn layout(
|
||||||
|
@ -4080,3 +4107,33 @@ fn scale_horizontal_mouse_autoscroll_delta(delta: f32) -> f32 {
|
||||||
// .collect()
|
// .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),
|
opening_range.to_anchors(&snapshot.buffer_snapshot),
|
||||||
closing_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,
|
cx,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
|
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
|
||||||
use crate::{char_kind, CharKind, EditorStyle, ToOffset, ToPoint};
|
use crate::{char_kind, CharKind, EditorStyle, ToOffset, ToPoint};
|
||||||
use gpui::{px, TextSystem};
|
use gpui::{px, Pixels, TextSystem};
|
||||||
use language::Point;
|
use language::Point;
|
||||||
use serde::de::IntoDeserializer;
|
use serde::de::IntoDeserializer;
|
||||||
use std::ops::Range;
|
use std::{ops::Range, sync::Arc};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum FindRange {
|
pub enum FindRange {
|
||||||
|
@ -14,8 +14,9 @@ pub enum FindRange {
|
||||||
/// TextLayoutDetails encompasses everything we need to move vertically
|
/// TextLayoutDetails encompasses everything we need to move vertically
|
||||||
/// taking into account variable width characters.
|
/// taking into account variable width characters.
|
||||||
pub struct TextLayoutDetails {
|
pub struct TextLayoutDetails {
|
||||||
pub text_system: TextSystem,
|
pub text_system: Arc<TextSystem>,
|
||||||
pub editor_style: EditorStyle,
|
pub editor_style: EditorStyle,
|
||||||
|
pub rem_size: Pixels,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
|
pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
|
||||||
|
|
|
@ -24,12 +24,12 @@ macro_rules! actions {
|
||||||
|
|
||||||
( $name:ident ) => {
|
( $name:ident ) => {
|
||||||
#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug, ::std::cmp::PartialEq, $crate::serde::Deserialize)]
|
#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug, ::std::cmp::PartialEq, $crate::serde::Deserialize)]
|
||||||
struct $name;
|
pub struct $name;
|
||||||
};
|
};
|
||||||
|
|
||||||
( $name:ident { $($token:tt)* } ) => {
|
( $name:ident { $($token:tt)* } ) => {
|
||||||
#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug, ::std::cmp::PartialEq, $crate::serde::Deserialize)]
|
#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug, ::std::cmp::PartialEq, $crate::serde::Deserialize)]
|
||||||
struct $name { $($token)* }
|
pub struct $name { $($token)* }
|
||||||
};
|
};
|
||||||
|
|
||||||
( $name:ident, $($rest:tt)* ) => {
|
( $name:ident, $($rest:tt)* ) => {
|
||||||
|
|
|
@ -779,11 +779,21 @@ impl AppContext {
|
||||||
(build)(params)
|
(build)(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Halt propagation of a mouse event, keyboard event, or action. This prevents listeners
|
/// Event handlers propagate events by default. Call this method to stop dispatching to
|
||||||
/// that have not yet been invoked from receiving the event.
|
/// event handlers with a lower z-index (mouse) or higher in the tree (keyboard). This is
|
||||||
|
/// the opposite of [propagate]. It's also possible to cancel a call to [propagate] by
|
||||||
|
/// calling this method before effects are flushed.
|
||||||
pub fn stop_propagation(&mut self) {
|
pub fn stop_propagation(&mut self) {
|
||||||
self.propagate_event = false;
|
self.propagate_event = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Action handlers stop propagation by default during the bubble phase of action dispatch
|
||||||
|
/// dispatching to action handlers higher in the element tree. This is the opposite of
|
||||||
|
/// [stop_propagation]. It's also possible to cancel a call to [stop_propagate] by calling
|
||||||
|
/// this method before effects are flushed.
|
||||||
|
pub fn propagate(&mut self) {
|
||||||
|
self.propagate_event = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context for AppContext {
|
impl Context for AppContext {
|
||||||
|
|
|
@ -300,7 +300,8 @@ impl Window {
|
||||||
|
|
||||||
/// When constructing the element tree, we maintain a stack of key dispatch frames until we
|
/// When constructing the element tree, we maintain a stack of key dispatch frames until we
|
||||||
/// find the focused element. We interleave key listeners with dispatch contexts so we can use the
|
/// find the focused element. We interleave key listeners with dispatch contexts so we can use the
|
||||||
/// contexts when matching key events against the keymap.
|
/// contexts when matching key events against the keymap. A key listener can be either an action
|
||||||
|
/// handler or a [KeyDown] / [KeyUp] event listener.
|
||||||
enum KeyDispatchStackFrame {
|
enum KeyDispatchStackFrame {
|
||||||
Listener {
|
Listener {
|
||||||
event_type: TypeId,
|
event_type: TypeId,
|
||||||
|
@ -1048,6 +1049,10 @@ impl<'a> WindowContext<'a> {
|
||||||
|
|
||||||
/// Dispatch a mouse or keyboard event on the window.
|
/// Dispatch a mouse or keyboard event on the window.
|
||||||
pub fn dispatch_event(&mut self, event: InputEvent) -> bool {
|
pub fn dispatch_event(&mut self, event: InputEvent) -> bool {
|
||||||
|
// Handlers may set this to false by calling `stop_propagation`
|
||||||
|
self.app.propagate_event = true;
|
||||||
|
self.window.default_prevented = false;
|
||||||
|
|
||||||
let event = match event {
|
let event = match event {
|
||||||
// Track the mouse position with our own state, since accessing the platform
|
// Track the mouse position with our own state, since accessing the platform
|
||||||
// API for the mouse position can only occur on the main thread.
|
// API for the mouse position can only occur on the main thread.
|
||||||
|
@ -1101,10 +1106,6 @@ impl<'a> WindowContext<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(any_mouse_event) = event.mouse_event() {
|
if let Some(any_mouse_event) = event.mouse_event() {
|
||||||
// Handlers may set this to false by calling `stop_propagation`
|
|
||||||
self.app.propagate_event = true;
|
|
||||||
self.window.default_prevented = false;
|
|
||||||
|
|
||||||
if let Some(mut handlers) = self
|
if let Some(mut handlers) = self
|
||||||
.window
|
.window
|
||||||
.mouse_listeners
|
.mouse_listeners
|
||||||
|
@ -1314,6 +1315,7 @@ impl<'a> WindowContext<'a> {
|
||||||
} = stack_frame
|
} = stack_frame
|
||||||
{
|
{
|
||||||
if action_type == *event_type {
|
if action_type == *event_type {
|
||||||
|
self.app.propagate_event = false;
|
||||||
listener(action.as_any(), &[], DispatchPhase::Bubble, self);
|
listener(action.as_any(), &[], DispatchPhase::Bubble, self);
|
||||||
if !self.app.propagate_event {
|
if !self.app.propagate_event {
|
||||||
break;
|
break;
|
||||||
|
@ -1328,6 +1330,7 @@ impl<'a> WindowContext<'a> {
|
||||||
self.app.global_action_listeners.remove(&action_type)
|
self.app.global_action_listeners.remove(&action_type)
|
||||||
{
|
{
|
||||||
for listener in global_listeners.iter().rev() {
|
for listener in global_listeners.iter().rev() {
|
||||||
|
self.app.propagate_event = false;
|
||||||
listener(action.as_ref(), DispatchPhase::Bubble, self);
|
listener(action.as_ref(), DispatchPhase::Bubble, self);
|
||||||
if !self.app.propagate_event {
|
if !self.app.propagate_event {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -95,6 +95,8 @@ mod tests {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(name, color)| (name.to_string(), (*color).into()))
|
.map(|(name, color)| (name.to_string(), (*color).into()))
|
||||||
.collect(),
|
.collect(),
|
||||||
|
inlay_style: HighlightStyle::default(),
|
||||||
|
suggestion_style: HighlightStyle::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let capture_names = &[
|
let capture_names = &[
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{settings_store::SettingsStore, Settings};
|
use crate::{settings_store::SettingsStore, KeymapFile, Settings};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use futures::{channel::mpsc, StreamExt};
|
use futures::{channel::mpsc, StreamExt};
|
||||||
|
@ -117,3 +117,50 @@ pub fn update_settings_file<T: Settings>(
|
||||||
})
|
})
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_default_keymap(cx: &mut AppContext) {
|
||||||
|
for path in ["keymaps/default.json", "keymaps/vim.json"] {
|
||||||
|
KeymapFile::load_asset(path, cx).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo!()
|
||||||
|
// if let Some(asset_path) = settings::get::<BaseKeymap>(cx).asset_path() {
|
||||||
|
// KeymapFile::load_asset(asset_path, cx).unwrap();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_keymap_file_changes(
|
||||||
|
mut user_keymap_file_rx: mpsc::UnboundedReceiver<String>,
|
||||||
|
cx: &mut AppContext,
|
||||||
|
) {
|
||||||
|
cx.spawn(move |cx| async move {
|
||||||
|
// let mut settings_subscription = None;
|
||||||
|
while let Some(user_keymap_content) = user_keymap_file_rx.next().await {
|
||||||
|
if let Some(keymap_content) = KeymapFile::parse(&user_keymap_content).log_err() {
|
||||||
|
cx.update(|cx| reload_keymaps(cx, &keymap_content)).ok();
|
||||||
|
|
||||||
|
// todo!()
|
||||||
|
// let mut old_base_keymap = cx.read(|cx| *settings::get::<BaseKeymap>(cx));
|
||||||
|
// drop(settings_subscription);
|
||||||
|
// settings_subscription = Some(cx.update(|cx| {
|
||||||
|
// cx.observe_global::<SettingsStore, _>(move |cx| {
|
||||||
|
// let new_base_keymap = *settings::get::<BaseKeymap>(cx);
|
||||||
|
// if new_base_keymap != old_base_keymap {
|
||||||
|
// old_base_keymap = new_base_keymap.clone();
|
||||||
|
// reload_keymaps(cx, &keymap_content);
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reload_keymaps(cx: &mut AppContext, keymap_content: &KeymapFile) {
|
||||||
|
// todo!()
|
||||||
|
// cx.clear_bindings();
|
||||||
|
load_default_keymap(cx);
|
||||||
|
keymap_content.clone().add_to_cx(cx).log_err();
|
||||||
|
// cx.set_menus(menus::menus());
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::Hsla;
|
use gpui::Hsla;
|
||||||
use refineable::Refineable;
|
use refineable::Refineable;
|
||||||
|
|
||||||
|
@ -145,7 +147,7 @@ pub struct ThemeStyles {
|
||||||
pub status: StatusColors,
|
pub status: StatusColors,
|
||||||
pub git: GitStatusColors,
|
pub git: GitStatusColors,
|
||||||
pub player: PlayerColors,
|
pub player: PlayerColors,
|
||||||
pub syntax: SyntaxTheme,
|
pub syntax: Arc<SyntaxTheme>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -138,6 +138,8 @@ impl SyntaxTheme {
|
||||||
("variable.special".into(), red().light().step_7().into()),
|
("variable.special".into(), red().light().step_7().into()),
|
||||||
("variant".into(), red().light().step_7().into()),
|
("variant".into(), red().light().step_7().into()),
|
||||||
],
|
],
|
||||||
|
inlay_style: tomato().light().step_1().into(), // todo!("nate: use a proper style")
|
||||||
|
suggestion_style: orange().light().step_1().into(), // todo!("nate: use proper style")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,6 +195,8 @@ impl SyntaxTheme {
|
||||||
("variable.special".into(), red().dark().step_7().into()),
|
("variable.special".into(), red().dark().step_7().into()),
|
||||||
("variant".into(), red().dark().step_7().into()),
|
("variant".into(), red().dark().step_7().into()),
|
||||||
],
|
],
|
||||||
|
inlay_style: tomato().dark().step_1().into(), // todo!("nate: use a proper style")
|
||||||
|
suggestion_style: orange().dark().step_1().into(), // todo!("nate: use a proper style")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
colors::{GitStatusColors, PlayerColors, StatusColors, SystemColors, ThemeColors, ThemeStyles},
|
colors::{GitStatusColors, PlayerColors, StatusColors, SystemColors, ThemeColors, ThemeStyles},
|
||||||
default_color_scales, Appearance, SyntaxTheme, Theme, ThemeFamily,
|
default_color_scales, Appearance, SyntaxTheme, Theme, ThemeFamily,
|
||||||
|
@ -14,7 +16,7 @@ fn zed_pro_daylight() -> Theme {
|
||||||
status: StatusColors::default(),
|
status: StatusColors::default(),
|
||||||
git: GitStatusColors::default(),
|
git: GitStatusColors::default(),
|
||||||
player: PlayerColors::default(),
|
player: PlayerColors::default(),
|
||||||
syntax: SyntaxTheme::default_light(),
|
syntax: Arc::new(SyntaxTheme::default_light()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +32,7 @@ pub(crate) fn zed_pro_moonlight() -> Theme {
|
||||||
status: StatusColors::default(),
|
status: StatusColors::default(),
|
||||||
git: GitStatusColors::default(),
|
git: GitStatusColors::default(),
|
||||||
player: PlayerColors::default(),
|
player: PlayerColors::default(),
|
||||||
syntax: SyntaxTheme::default_dark(),
|
syntax: Arc::new(SyntaxTheme::default_dark()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,8 @@ impl ThemeRegistry {
|
||||||
git: GitStatusColors::default(),
|
git: GitStatusColors::default(),
|
||||||
player: PlayerColors::default(),
|
player: PlayerColors::default(),
|
||||||
syntax: match user_theme.appearance {
|
syntax: match user_theme.appearance {
|
||||||
Appearance::Light => SyntaxTheme::default_light(),
|
Appearance::Light => Arc::new(SyntaxTheme::default_light()),
|
||||||
Appearance::Dark => SyntaxTheme::default_dark(),
|
Appearance::Dark => Arc::new(SyntaxTheme::default_dark()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ use gpui::{HighlightStyle, Hsla};
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct SyntaxTheme {
|
pub struct SyntaxTheme {
|
||||||
pub highlights: Vec<(String, HighlightStyle)>,
|
pub highlights: Vec<(String, HighlightStyle)>,
|
||||||
|
pub inlay_style: HighlightStyle,
|
||||||
|
pub suggestion_style: HighlightStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SyntaxTheme {
|
impl SyntaxTheme {
|
||||||
|
@ -21,6 +23,8 @@ impl SyntaxTheme {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
inlay_style: HighlightStyle::default(),
|
||||||
|
suggestion_style: HighlightStyle::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl Theme {
|
||||||
|
|
||||||
/// Returns the [`SyntaxTheme`] for the theme.
|
/// Returns the [`SyntaxTheme`] for the theme.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn syntax(&self) -> &SyntaxTheme {
|
pub fn syntax(&self) -> &Arc<SyntaxTheme> {
|
||||||
&self.styles.syntax
|
&self.styles.syntax
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,4 +98,25 @@ impl Theme {
|
||||||
pub fn syntax_color(&self, name: &str) -> Hsla {
|
pub fn syntax_color(&self, name: &str) -> Hsla {
|
||||||
self.syntax().color(name)
|
self.syntax().color(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the [`StatusColors`] for the theme.
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn diagnostic_style(&self) -> DiagnosticStyle {
|
||||||
|
DiagnosticStyle {
|
||||||
|
error: self.status().error,
|
||||||
|
warning: self.status().warning,
|
||||||
|
info: self.status().info,
|
||||||
|
hint: self.status().info,
|
||||||
|
ignored: self.status().ignored,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct DiagnosticStyle {
|
||||||
|
pub error: Hsla,
|
||||||
|
pub warning: Hsla,
|
||||||
|
pub info: Hsla,
|
||||||
|
pub hint: Hsla,
|
||||||
|
pub ignored: Hsla,
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ use node_runtime::RealNodeRuntime;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use settings::{
|
use settings::{
|
||||||
default_settings, handle_settings_file_changes, watch_config_file, Settings, SettingsStore,
|
default_settings, handle_keymap_file_changes, handle_settings_file_changes, watch_config_file,
|
||||||
|
Settings, SettingsStore,
|
||||||
};
|
};
|
||||||
use simplelog::ConfigBuilder;
|
use simplelog::ConfigBuilder;
|
||||||
use smol::process::Command;
|
use smol::process::Command;
|
||||||
|
@ -76,7 +77,7 @@ fn main() {
|
||||||
fs.clone(),
|
fs.clone(),
|
||||||
paths::SETTINGS.clone(),
|
paths::SETTINGS.clone(),
|
||||||
);
|
);
|
||||||
let _user_keymap_file_rx = watch_config_file(
|
let user_keymap_file_rx = watch_config_file(
|
||||||
&app.background_executor(),
|
&app.background_executor(),
|
||||||
fs.clone(),
|
fs.clone(),
|
||||||
paths::KEYMAP.clone(),
|
paths::KEYMAP.clone(),
|
||||||
|
@ -116,7 +117,7 @@ fn main() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
cx.set_global(store);
|
cx.set_global(store);
|
||||||
handle_settings_file_changes(user_settings_file_rx, cx);
|
handle_settings_file_changes(user_settings_file_rx, cx);
|
||||||
// handle_keymap_file_changes(user_keymap_file_rx, cx);
|
handle_keymap_file_changes(user_keymap_file_rx, cx);
|
||||||
|
|
||||||
let client = client::Client::new(http.clone(), cx);
|
let client = client::Client::new(http.clone(), cx);
|
||||||
let mut languages = LanguageRegistry::new(login_shell_env_loaded);
|
let mut languages = LanguageRegistry::new(login_shell_env_loaded);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue