Merge branch 'main' into update-workspace-styles
This commit is contained in:
commit
b5f60b7e50
60 changed files with 3153 additions and 1028 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
@ -3235,7 +3235,7 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.11.2",
|
||||||
"regex",
|
"regex",
|
||||||
"rope",
|
"rope2",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -6109,7 +6109,6 @@ dependencies = [
|
||||||
"settings2",
|
"settings2",
|
||||||
"theme2",
|
"theme2",
|
||||||
"util",
|
"util",
|
||||||
"workspace2",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -7251,6 +7250,20 @@ dependencies = [
|
||||||
"util",
|
"util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rope2"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"arrayvec 0.7.4",
|
||||||
|
"bromberg_sl2",
|
||||||
|
"gpui2",
|
||||||
|
"log",
|
||||||
|
"rand 0.8.5",
|
||||||
|
"smallvec",
|
||||||
|
"sum_tree",
|
||||||
|
"util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "roxmltree"
|
name = "roxmltree"
|
||||||
version = "0.14.1"
|
version = "0.14.1"
|
||||||
|
@ -9063,7 +9076,7 @@ dependencies = [
|
||||||
"postage",
|
"postage",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"regex",
|
"regex",
|
||||||
"rope",
|
"rope2",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"sum_tree",
|
"sum_tree",
|
||||||
"util",
|
"util",
|
||||||
|
@ -11352,6 +11365,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"lsp2",
|
"lsp2",
|
||||||
|
"menu2",
|
||||||
"node_runtime",
|
"node_runtime",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.11.2",
|
||||||
|
@ -11359,6 +11373,7 @@ dependencies = [
|
||||||
"project2",
|
"project2",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"regex",
|
"regex",
|
||||||
|
"rope2",
|
||||||
"rpc2",
|
"rpc2",
|
||||||
"rsa 0.4.0",
|
"rsa 0.4.0",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
|
|
|
@ -17,6 +17,7 @@ use gpui::{
|
||||||
};
|
};
|
||||||
use postage::watch;
|
use postage::watch;
|
||||||
use project::Project;
|
use project::Project;
|
||||||
|
use room::Event;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -85,9 +86,7 @@ pub struct ActiveCall {
|
||||||
_subscriptions: Vec<client::Subscription>,
|
_subscriptions: Vec<client::Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for ActiveCall {
|
impl EventEmitter<Event> for ActiveCall {}
|
||||||
type Event = room::Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveCall {
|
impl ActiveCall {
|
||||||
fn new(client: Arc<Client>, user_store: Model<UserStore>, cx: &mut ModelContext<Self>) -> Self {
|
fn new(client: Arc<Client>, user_store: Model<UserStore>, cx: &mut ModelContext<Self>) -> Self {
|
||||||
|
|
|
@ -79,9 +79,7 @@ pub struct Room {
|
||||||
maintain_connection: Option<Task<Option<()>>>,
|
maintain_connection: Option<Task<Option<()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for Room {
|
impl EventEmitter<Event> for Room {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Room {
|
impl Room {
|
||||||
pub fn channel_id(&self) -> Option<u64> {
|
pub fn channel_id(&self) -> Option<u64> {
|
||||||
|
|
|
@ -38,9 +38,7 @@ pub enum ChannelBufferEvent {
|
||||||
ChannelChanged,
|
ChannelChanged,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for ChannelBuffer {
|
impl EventEmitter<ChannelBufferEvent> for ChannelBuffer {}
|
||||||
type Event = ChannelBufferEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ChannelBuffer {
|
impl ChannelBuffer {
|
||||||
pub(crate) async fn new(
|
pub(crate) async fn new(
|
||||||
|
|
|
@ -76,9 +76,7 @@ pub enum ChannelChatEvent {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for ChannelChat {
|
impl EventEmitter<ChannelChatEvent> for ChannelChat {}
|
||||||
type Event = ChannelChatEvent;
|
|
||||||
}
|
|
||||||
pub fn init(client: &Arc<Client>) {
|
pub fn init(client: &Arc<Client>) {
|
||||||
client.add_model_message_handler(ChannelChat::handle_message_sent);
|
client.add_model_message_handler(ChannelChat::handle_message_sent);
|
||||||
client.add_model_message_handler(ChannelChat::handle_message_removed);
|
client.add_model_message_handler(ChannelChat::handle_message_removed);
|
||||||
|
|
|
@ -114,9 +114,7 @@ pub enum ChannelEvent {
|
||||||
ChannelRenamed(ChannelId),
|
ChannelRenamed(ChannelId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for ChannelStore {
|
impl EventEmitter<ChannelEvent> for ChannelStore {}
|
||||||
type Event = ChannelEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum OpenedModelHandle<E> {
|
enum OpenedModelHandle<E> {
|
||||||
Open(WeakModel<E>),
|
Open(WeakModel<E>),
|
||||||
|
|
|
@ -103,9 +103,7 @@ pub enum ContactEventKind {
|
||||||
Cancelled,
|
Cancelled,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for UserStore {
|
impl EventEmitter<Event> for UserStore {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum UpdateContacts {
|
enum UpdateContacts {
|
||||||
Update(proto::UpdateContacts),
|
Update(proto::UpdateContacts),
|
||||||
|
|
|
@ -284,9 +284,7 @@ pub enum Event {
|
||||||
CopilotLanguageServerStarted,
|
CopilotLanguageServerStarted,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for Copilot {
|
impl EventEmitter<Event> for Copilot {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Copilot {
|
impl Copilot {
|
||||||
pub fn global(cx: &AppContext) -> Option<Model<Self>> {
|
pub fn global(cx: &AppContext) -> Option<Model<Self>> {
|
||||||
|
|
|
@ -85,6 +85,10 @@ impl BlinkManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable(&mut self, cx: &mut ModelContext<Self>) {
|
pub fn enable(&mut self, cx: &mut ModelContext<Self>) {
|
||||||
|
if self.enabled {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.enabled = true;
|
self.enabled = true;
|
||||||
// Set cursors as invisible and start blinking: this causes cursors
|
// Set cursors as invisible and start blinking: this causes cursors
|
||||||
// to be visible during the next render.
|
// to be visible during the next render.
|
||||||
|
|
|
@ -572,7 +572,6 @@ impl DisplaySnapshot {
|
||||||
) -> Line {
|
) -> Line {
|
||||||
let mut runs = Vec::new();
|
let mut runs = Vec::new();
|
||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
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) {
|
||||||
|
@ -588,17 +587,18 @@ impl DisplaySnapshot {
|
||||||
} else {
|
} else {
|
||||||
Cow::Borrowed(&editor_style.text)
|
Cow::Borrowed(&editor_style.text)
|
||||||
};
|
};
|
||||||
ended_in_newline = chunk.chunk.ends_with("\n");
|
|
||||||
|
|
||||||
runs.push(text_style.to_run(chunk.chunk.len()))
|
runs.push(text_style.to_run(chunk.chunk.len()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// our pixel positioning logic assumes each line ends in \n,
|
if line.ends_with('\n') {
|
||||||
// this is almost always true except for the last line which
|
line.pop();
|
||||||
// may have no trailing newline.
|
if let Some(last_run) = runs.last_mut() {
|
||||||
if !ended_in_newline && display_row == self.max_point().row() {
|
last_run.len -= 1;
|
||||||
line.push_str("\n");
|
if last_run.len == 0 {
|
||||||
runs.push(editor_style.text.to_run("\n".len()));
|
runs.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let font_size = editor_style.text.font_size.to_pixels(*rem_size);
|
let font_size = editor_style.text.font_size.to_pixels(*rem_size);
|
||||||
|
|
|
@ -39,11 +39,10 @@ use futures::FutureExt;
|
||||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||||
use git::diff_hunk_to_display;
|
use git::diff_hunk_to_display;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
action, actions, div, px, relative, AnyElement, AppContext, BackgroundExecutor, ClipboardItem,
|
action, actions, point, px, relative, rems, size, AnyElement, AppContext, BackgroundExecutor,
|
||||||
Context, DispatchContext, Div, Element, Entity, EventEmitter, FocusHandle, FontStyle,
|
Bounds, ClipboardItem, Context, DispatchContext, EventEmitter, FocusHandle, FontFeatures,
|
||||||
FontWeight, HighlightStyle, Hsla, InputHandler, Model, Pixels, PlatformInputHandler, Render,
|
FontStyle, FontWeight, HighlightStyle, Hsla, InputHandler, Model, Pixels, Render, Subscription,
|
||||||
Styled, Subscription, Task, TextStyle, View, ViewContext, VisualContext, WeakView,
|
Task, TextStyle, View, ViewContext, VisualContext, WeakView, WindowContext,
|
||||||
WindowContext,
|
|
||||||
};
|
};
|
||||||
use highlight_matching_bracket::refresh_matching_bracket_highlights;
|
use highlight_matching_bracket::refresh_matching_bracket_highlights;
|
||||||
use hover_popover::{hide_hover, HoverState};
|
use hover_popover::{hide_hover, HoverState};
|
||||||
|
@ -57,6 +56,7 @@ use language::{
|
||||||
Diagnostic, IndentKind, IndentSize, Language, LanguageRegistry, LanguageServerName,
|
Diagnostic, IndentKind, IndentSize, Language, LanguageRegistry, LanguageServerName,
|
||||||
OffsetRangeExt, Point, Selection, SelectionGoal, TransactionId,
|
OffsetRangeExt, Point, Selection, SelectionGoal, TransactionId,
|
||||||
};
|
};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use link_go_to_definition::{GoToDefinitionLink, InlayHighlight, LinkGoToDefinitionState};
|
use link_go_to_definition::{GoToDefinitionLink, InlayHighlight, LinkGoToDefinitionState};
|
||||||
use lsp::{DiagnosticSeverity, Documentation, LanguageServerId};
|
use lsp::{DiagnosticSeverity, Documentation, LanguageServerId};
|
||||||
use movement::TextLayoutDetails;
|
use movement::TextLayoutDetails;
|
||||||
|
@ -66,7 +66,7 @@ pub use multi_buffer::{
|
||||||
ToPoint,
|
ToPoint,
|
||||||
};
|
};
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::{Mutex, RwLock};
|
||||||
use project::{FormatTrigger, Location, Project};
|
use project::{FormatTrigger, Location, Project};
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use rpc::proto::*;
|
use rpc::proto::*;
|
||||||
|
@ -96,7 +96,9 @@ use theme::{
|
||||||
ActiveTheme, DiagnosticStyle, PlayerColor, SyntaxTheme, Theme, ThemeColors, ThemeSettings,
|
ActiveTheme, DiagnosticStyle, PlayerColor, SyntaxTheme, Theme, ThemeColors, ThemeSettings,
|
||||||
};
|
};
|
||||||
use util::{post_inc, RangeExt, ResultExt, TryFutureExt};
|
use util::{post_inc, RangeExt, ResultExt, TryFutureExt};
|
||||||
use workspace::{ItemNavHistory, SplitDirection, ViewId, Workspace};
|
use workspace::{
|
||||||
|
item::ItemEvent, searchable::SearchEvent, ItemNavHistory, SplitDirection, ViewId, Workspace,
|
||||||
|
};
|
||||||
|
|
||||||
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
|
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
|
||||||
const MAX_LINE_LEN: usize = 1024;
|
const MAX_LINE_LEN: usize = 1024;
|
||||||
|
@ -674,6 +676,7 @@ pub struct Editor {
|
||||||
next_inlay_id: usize,
|
next_inlay_id: usize,
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
pixel_position_of_newest_cursor: Option<gpui::Point<Pixels>>,
|
pixel_position_of_newest_cursor: Option<gpui::Point<Pixels>>,
|
||||||
|
gutter_width: Pixels,
|
||||||
style: Option<EditorStyle>,
|
style: Option<EditorStyle>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1903,7 +1906,8 @@ impl Editor {
|
||||||
if let Some(project) = project.as_ref() {
|
if let Some(project) = project.as_ref() {
|
||||||
if buffer.read(cx).is_singleton() {
|
if buffer.read(cx).is_singleton() {
|
||||||
project_subscriptions.push(cx.observe(project, |_, _, cx| {
|
project_subscriptions.push(cx.observe(project, |_, _, cx| {
|
||||||
cx.emit(Event::TitleChanged);
|
cx.emit(ItemEvent::UpdateTab);
|
||||||
|
cx.emit(ItemEvent::UpdateBreadcrumbs);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
project_subscriptions.push(cx.subscribe(project, |editor, _, event, cx| {
|
project_subscriptions.push(cx.subscribe(project, |editor, _, event, cx| {
|
||||||
|
@ -1920,9 +1924,15 @@ impl Editor {
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let focus_handle = cx.focus_handle();
|
||||||
|
cx.on_focus_in(&focus_handle, Self::handle_focus_in)
|
||||||
|
.detach();
|
||||||
|
cx.on_focus_out(&focus_handle, Self::handle_focus_out)
|
||||||
|
.detach();
|
||||||
|
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
handle: cx.view().downgrade(),
|
handle: cx.view().downgrade(),
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle,
|
||||||
buffer: buffer.clone(),
|
buffer: buffer.clone(),
|
||||||
display_map: display_map.clone(),
|
display_map: display_map.clone(),
|
||||||
selections,
|
selections,
|
||||||
|
@ -1978,6 +1988,7 @@ impl Editor {
|
||||||
inlay_hint_cache: InlayHintCache::new(inlay_hint_settings),
|
inlay_hint_cache: InlayHintCache::new(inlay_hint_settings),
|
||||||
gutter_hovered: false,
|
gutter_hovered: false,
|
||||||
pixel_position_of_newest_cursor: None,
|
pixel_position_of_newest_cursor: None,
|
||||||
|
gutter_width: Default::default(),
|
||||||
style: None,
|
style: None,
|
||||||
_subscriptions: vec![
|
_subscriptions: vec![
|
||||||
cx.observe(&buffer, Self::on_buffer_changed),
|
cx.observe(&buffer, Self::on_buffer_changed),
|
||||||
|
@ -2172,14 +2183,14 @@ impl Editor {
|
||||||
// self.collaboration_hub = Some(hub);
|
// self.collaboration_hub = Some(hub);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// pub fn set_placeholder_text(
|
pub fn set_placeholder_text(
|
||||||
// &mut self,
|
&mut self,
|
||||||
// placeholder_text: impl Into<Arc<str>>,
|
placeholder_text: impl Into<Arc<str>>,
|
||||||
// cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
// ) {
|
) {
|
||||||
// self.placeholder_text = Some(placeholder_text.into());
|
self.placeholder_text = Some(placeholder_text.into());
|
||||||
// cx.notify();
|
cx.notify();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// pub fn set_cursor_shape(&mut self, cursor_shape: CursorShape, cx: &mut ViewContext<Self>) {
|
// pub fn set_cursor_shape(&mut self, cursor_shape: CursorShape, cx: &mut ViewContext<Self>) {
|
||||||
// self.cursor_shape = cursor_shape;
|
// self.cursor_shape = cursor_shape;
|
||||||
|
@ -2355,6 +2366,15 @@ impl Editor {
|
||||||
|
|
||||||
self.blink_manager.update(cx, BlinkManager::pause_blinking);
|
self.blink_manager.update(cx, BlinkManager::pause_blinking);
|
||||||
cx.emit(Event::SelectionsChanged { local });
|
cx.emit(Event::SelectionsChanged { local });
|
||||||
|
|
||||||
|
if self.selections.disjoint_anchors().len() == 1 {
|
||||||
|
cx.emit(SearchEvent::ActiveMatchChanged)
|
||||||
|
}
|
||||||
|
|
||||||
|
if local {
|
||||||
|
cx.emit(ItemEvent::UpdateBreadcrumbs);
|
||||||
|
}
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8754,6 +8774,9 @@ impl Editor {
|
||||||
self.update_visible_copilot_suggestion(cx);
|
self.update_visible_copilot_suggestion(cx);
|
||||||
}
|
}
|
||||||
cx.emit(Event::BufferEdited);
|
cx.emit(Event::BufferEdited);
|
||||||
|
cx.emit(ItemEvent::Edit);
|
||||||
|
cx.emit(ItemEvent::UpdateBreadcrumbs);
|
||||||
|
cx.emit(SearchEvent::MatchesInvalidated);
|
||||||
|
|
||||||
if *sigleton_buffer_edited {
|
if *sigleton_buffer_edited {
|
||||||
if let Some(project) = &self.project {
|
if let Some(project) = &self.project {
|
||||||
|
@ -8800,13 +8823,20 @@ impl Editor {
|
||||||
self.refresh_inlay_hints(InlayHintRefreshReason::ExcerptsRemoved(ids.clone()), cx);
|
self.refresh_inlay_hints(InlayHintRefreshReason::ExcerptsRemoved(ids.clone()), cx);
|
||||||
cx.emit(Event::ExcerptsRemoved { ids: ids.clone() })
|
cx.emit(Event::ExcerptsRemoved { ids: ids.clone() })
|
||||||
}
|
}
|
||||||
multi_buffer::Event::Reparsed => cx.emit(Event::Reparsed),
|
multi_buffer::Event::Reparsed => {
|
||||||
multi_buffer::Event::DirtyChanged => cx.emit(Event::DirtyChanged),
|
cx.emit(ItemEvent::UpdateBreadcrumbs);
|
||||||
multi_buffer::Event::Saved => cx.emit(Event::Saved),
|
}
|
||||||
multi_buffer::Event::FileHandleChanged => cx.emit(Event::TitleChanged),
|
multi_buffer::Event::DirtyChanged => {
|
||||||
multi_buffer::Event::Reloaded => cx.emit(Event::TitleChanged),
|
cx.emit(ItemEvent::UpdateTab);
|
||||||
|
}
|
||||||
|
multi_buffer::Event::Saved
|
||||||
|
| multi_buffer::Event::FileHandleChanged
|
||||||
|
| multi_buffer::Event::Reloaded => {
|
||||||
|
cx.emit(ItemEvent::UpdateTab);
|
||||||
|
cx.emit(ItemEvent::UpdateBreadcrumbs);
|
||||||
|
}
|
||||||
multi_buffer::Event::DiffBaseChanged => cx.emit(Event::DiffBaseChanged),
|
multi_buffer::Event::DiffBaseChanged => cx.emit(Event::DiffBaseChanged),
|
||||||
multi_buffer::Event::Closed => cx.emit(Event::Closed),
|
multi_buffer::Event::Closed => cx.emit(ItemEvent::CloseItem),
|
||||||
multi_buffer::Event::DiagnosticsUpdated => {
|
multi_buffer::Event::DiagnosticsUpdated => {
|
||||||
self.refresh_active_diagnostics(cx);
|
self.refresh_active_diagnostics(cx);
|
||||||
}
|
}
|
||||||
|
@ -9195,6 +9225,45 @@ impl Editor {
|
||||||
pub fn focus(&self, cx: &mut WindowContext) {
|
pub fn focus(&self, cx: &mut WindowContext) {
|
||||||
cx.focus(&self.focus_handle)
|
cx.focus(&self.focus_handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_focus_in(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
if self.focus_handle.is_focused(cx) {
|
||||||
|
// todo!()
|
||||||
|
// let focused_event = EditorFocused(cx.handle());
|
||||||
|
// cx.emit_global(focused_event);
|
||||||
|
cx.emit(Event::Focused);
|
||||||
|
}
|
||||||
|
if let Some(rename) = self.pending_rename.as_ref() {
|
||||||
|
let rename_editor_focus_handle = rename.editor.read(cx).focus_handle.clone();
|
||||||
|
cx.focus(&rename_editor_focus_handle);
|
||||||
|
} else if self.focus_handle.is_focused(cx) {
|
||||||
|
self.blink_manager.update(cx, BlinkManager::enable);
|
||||||
|
self.buffer.update(cx, |buffer, cx| {
|
||||||
|
buffer.finalize_last_transaction(cx);
|
||||||
|
if self.leader_peer_id.is_none() {
|
||||||
|
buffer.set_active_selections(
|
||||||
|
&self.selections.disjoint_anchors(),
|
||||||
|
self.selections.line_mode,
|
||||||
|
self.cursor_shape,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_focus_out(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
// todo!()
|
||||||
|
// let blurred_event = EditorBlurred(cx.handle());
|
||||||
|
// cx.emit_global(blurred_event);
|
||||||
|
self.blink_manager.update(cx, BlinkManager::disable);
|
||||||
|
self.buffer
|
||||||
|
.update(cx, |buffer, cx| buffer.remove_active_selections(cx));
|
||||||
|
self.hide_context_menu(cx);
|
||||||
|
hide_hover(self, cx);
|
||||||
|
cx.emit(Event::Blurred);
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CollaborationHub {
|
pub trait CollaborationHub {
|
||||||
|
@ -9333,12 +9402,8 @@ pub enum Event {
|
||||||
},
|
},
|
||||||
BufferEdited,
|
BufferEdited,
|
||||||
Edited,
|
Edited,
|
||||||
Reparsed,
|
|
||||||
Focused,
|
Focused,
|
||||||
Blurred,
|
Blurred,
|
||||||
DirtyChanged,
|
|
||||||
Saved,
|
|
||||||
TitleChanged,
|
|
||||||
DiffBaseChanged,
|
DiffBaseChanged,
|
||||||
SelectionsChanged {
|
SelectionsChanged {
|
||||||
local: bool,
|
local: bool,
|
||||||
|
@ -9347,7 +9412,6 @@ pub enum Event {
|
||||||
local: bool,
|
local: bool,
|
||||||
autoscroll: bool,
|
autoscroll: bool,
|
||||||
},
|
},
|
||||||
Closed,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EditorFocused(pub View<Editor>);
|
pub struct EditorFocused(pub View<Editor>);
|
||||||
|
@ -9362,16 +9426,30 @@ pub struct EditorReleased(pub WeakView<Editor>);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
impl EventEmitter for Editor {
|
impl EventEmitter<Event> for Editor {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Render for Editor {
|
impl Render for Editor {
|
||||||
type Element = EditorElement;
|
type Element = EditorElement;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
let settings = ThemeSettings::get_global(cx);
|
let settings = ThemeSettings::get_global(cx);
|
||||||
let text_style = TextStyle {
|
let text_style = match self.mode {
|
||||||
|
EditorMode::SingleLine => {
|
||||||
|
TextStyle {
|
||||||
|
color: cx.theme().colors().text,
|
||||||
|
font_family: "Zed Sans".into(), // todo!()
|
||||||
|
font_features: FontFeatures::default(),
|
||||||
|
font_size: rems(1.0).into(),
|
||||||
|
font_weight: FontWeight::NORMAL,
|
||||||
|
font_style: FontStyle::Normal,
|
||||||
|
line_height: relative(1.3).into(), // TODO relative(settings.buffer_line_height.value()),
|
||||||
|
underline: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorMode::AutoHeight { max_lines } => todo!(),
|
||||||
|
|
||||||
|
EditorMode::Full => TextStyle {
|
||||||
color: cx.theme().colors().text,
|
color: cx.theme().colors().text,
|
||||||
font_family: settings.buffer_font.family.clone(),
|
font_family: settings.buffer_font.family.clone(),
|
||||||
font_features: settings.buffer_font.features,
|
font_features: settings.buffer_font.features,
|
||||||
|
@ -9380,9 +9458,17 @@ impl Render for Editor {
|
||||||
font_style: FontStyle::Normal,
|
font_style: FontStyle::Normal,
|
||||||
line_height: relative(settings.buffer_line_height.value()),
|
line_height: relative(settings.buffer_line_height.value()),
|
||||||
underline: None,
|
underline: None,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let background = match self.mode {
|
||||||
|
EditorMode::SingleLine => cx.theme().system().transparent,
|
||||||
|
EditorMode::AutoHeight { max_lines } => cx.theme().system().transparent,
|
||||||
|
EditorMode::Full => cx.theme().colors().editor_background,
|
||||||
|
};
|
||||||
|
|
||||||
EditorElement::new(EditorStyle {
|
EditorElement::new(EditorStyle {
|
||||||
background: cx.theme().colors().editor_background,
|
background,
|
||||||
local_player: cx.theme().players().local(),
|
local_player: cx.theme().players().local(),
|
||||||
text: text_style,
|
text: text_style,
|
||||||
scrollbar_width: px(12.),
|
scrollbar_width: px(12.),
|
||||||
|
@ -9494,7 +9580,7 @@ impl Render for Editor {
|
||||||
|
|
||||||
impl InputHandler for Editor {
|
impl InputHandler for Editor {
|
||||||
fn text_for_range(
|
fn text_for_range(
|
||||||
&self,
|
&mut self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
|
@ -9507,7 +9593,7 @@ impl InputHandler for Editor {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn selected_text_range(&self, cx: &mut ViewContext<Self>) -> Option<Range<usize>> {
|
fn selected_text_range(&mut self, cx: &mut ViewContext<Self>) -> Option<Range<usize>> {
|
||||||
// Prevent the IME menu from appearing when holding down an alphabetic key
|
// Prevent the IME menu from appearing when holding down an alphabetic key
|
||||||
// while input is disabled.
|
// while input is disabled.
|
||||||
if !self.input_enabled {
|
if !self.input_enabled {
|
||||||
|
@ -9705,13 +9791,35 @@ impl InputHandler for Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bounds_for_range(
|
fn bounds_for_range(
|
||||||
&self,
|
&mut self,
|
||||||
range_utf16: Range<usize>,
|
range_utf16: Range<usize>,
|
||||||
|
element_bounds: gpui::Bounds<Pixels>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<gpui::Bounds<f32>> {
|
) -> Option<gpui::Bounds<Pixels>> {
|
||||||
// todo!()
|
let text_layout_details = self.text_layout_details(cx);
|
||||||
// See how we did it before: `rect_for_range`
|
let style = &text_layout_details.editor_style;
|
||||||
None
|
let font_id = cx.text_system().font_id(&style.text.font()).unwrap();
|
||||||
|
let font_size = style.text.font_size.to_pixels(cx.rem_size());
|
||||||
|
let line_height = style.text.line_height_in_pixels(cx.rem_size());
|
||||||
|
let em_width = cx
|
||||||
|
.text_system()
|
||||||
|
.typographic_bounds(font_id, font_size, 'm')
|
||||||
|
.unwrap()
|
||||||
|
.size
|
||||||
|
.width;
|
||||||
|
|
||||||
|
let snapshot = self.snapshot(cx);
|
||||||
|
let scroll_position = snapshot.scroll_position();
|
||||||
|
let scroll_left = scroll_position.x * em_width;
|
||||||
|
|
||||||
|
let start = OffsetUtf16(range_utf16.start).to_display_point(&snapshot);
|
||||||
|
let x = snapshot.x_for_point(start, &text_layout_details) - scroll_left + self.gutter_width;
|
||||||
|
let y = line_height * (start.row() as f32 - scroll_position.y);
|
||||||
|
|
||||||
|
Some(Bounds {
|
||||||
|
origin: element_bounds.origin + point(x, y),
|
||||||
|
size: size(em_width, line_height),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,10 @@ use collections::{BTreeMap, HashMap};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
black, hsla, point, px, relative, size, transparent_black, Action, AnyElement,
|
black, hsla, point, px, relative, size, transparent_black, Action, AnyElement,
|
||||||
BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase,
|
BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase,
|
||||||
Edges, Element, ElementId, Entity, GlobalElementId, Hsla, KeyDownEvent, KeyListener, KeyMatch,
|
Edges, Element, ElementId, ElementInputHandler, Entity, FocusHandle, GlobalElementId, Hsla,
|
||||||
Line, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,
|
InputHandler, KeyDownEvent, KeyListener, KeyMatch, Line, LineLayout, Modifiers, MouseButton,
|
||||||
ScrollWheelEvent, ShapedGlyph, Size, Style, TextRun, TextStyle, TextSystem, ViewContext,
|
MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels, ScrollWheelEvent, ShapedGlyph, Size,
|
||||||
WindowContext,
|
Style, TextRun, TextStyle, TextSystem, ViewContext, WindowContext, WrappedLineLayout,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use language::language_settings::ShowWhitespaceSetting;
|
use language::language_settings::ShowWhitespaceSetting;
|
||||||
|
@ -1467,6 +1467,7 @@ impl EditorElement {
|
||||||
gutter_margin = Pixels::ZERO;
|
gutter_margin = Pixels::ZERO;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
editor.gutter_width = gutter_width;
|
||||||
let text_width = bounds.size.width - gutter_width;
|
let text_width = bounds.size.width - gutter_width;
|
||||||
let overscroll = size(em_width, px(0.));
|
let overscroll = size(em_width, px(0.));
|
||||||
let snapshot = {
|
let snapshot = {
|
||||||
|
@ -2502,10 +2503,6 @@ impl Element<Editor> for EditorElement {
|
||||||
size: layout.text_size,
|
size: layout.text_size,
|
||||||
};
|
};
|
||||||
|
|
||||||
if editor.focus_handle.is_focused(cx) {
|
|
||||||
cx.handle_text_input();
|
|
||||||
}
|
|
||||||
|
|
||||||
cx.with_content_mask(ContentMask { bounds }, |cx| {
|
cx.with_content_mask(ContentMask { bounds }, |cx| {
|
||||||
self.paint_mouse_listeners(
|
self.paint_mouse_listeners(
|
||||||
bounds,
|
bounds,
|
||||||
|
@ -2519,6 +2516,8 @@ impl Element<Editor> for EditorElement {
|
||||||
self.paint_gutter(gutter_bounds, &layout, editor, cx);
|
self.paint_gutter(gutter_bounds, &layout, editor, cx);
|
||||||
}
|
}
|
||||||
self.paint_text(text_bounds, &layout, editor, cx);
|
self.paint_text(text_bounds, &layout, editor, cx);
|
||||||
|
let input_handler = ElementInputHandler::new(bounds, cx);
|
||||||
|
cx.handle_input(&editor.focus_handle, input_handler);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@ use anyhow::{anyhow, Context, Result};
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
use futures::future::try_join_all;
|
use futures::future::try_join_all;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, point, AnyElement, AppContext, AsyncAppContext, Entity, EntityId, FocusHandle, Model,
|
div, point, AnyElement, AppContext, AsyncAppContext, Entity, EntityId, EventEmitter,
|
||||||
ParentElement, Pixels, SharedString, Styled, Subscription, Task, View, ViewContext,
|
FocusHandle, Model, ParentElement, Pixels, SharedString, Styled, Subscription, Task, View,
|
||||||
VisualContext, WeakView,
|
ViewContext, VisualContext, WeakView,
|
||||||
};
|
};
|
||||||
use language::{
|
use language::{
|
||||||
proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, OffsetRangeExt, Point,
|
proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, OffsetRangeExt, Point,
|
||||||
|
@ -29,7 +29,7 @@ use std::{
|
||||||
use text::Selection;
|
use text::Selection;
|
||||||
use theme::{ActiveTheme, Theme};
|
use theme::{ActiveTheme, Theme};
|
||||||
use util::{paths::PathExt, ResultExt, TryFutureExt};
|
use util::{paths::PathExt, ResultExt, TryFutureExt};
|
||||||
use workspace::item::{BreadcrumbText, FollowableItemHandle};
|
use workspace::item::{BreadcrumbText, FollowEvent, FollowableEvents, FollowableItemHandle};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{FollowableItem, Item, ItemEvent, ItemHandle, ProjectItem},
|
item::{FollowableItem, Item, ItemEvent, ItemHandle, ProjectItem},
|
||||||
searchable::{Direction, SearchEvent, SearchableItem, SearchableItemHandle},
|
searchable::{Direction, SearchEvent, SearchableItem, SearchableItemHandle},
|
||||||
|
@ -38,7 +38,26 @@ use workspace::{
|
||||||
|
|
||||||
pub const MAX_TAB_TITLE_LEN: usize = 24;
|
pub const MAX_TAB_TITLE_LEN: usize = 24;
|
||||||
|
|
||||||
|
impl FollowableEvents for Event {
|
||||||
|
fn to_follow_event(&self) -> Option<workspace::item::FollowEvent> {
|
||||||
|
match self {
|
||||||
|
Event::Edited => Some(FollowEvent::Unfollow),
|
||||||
|
Event::SelectionsChanged { local } | Event::ScrollPositionChanged { local, .. } => {
|
||||||
|
if *local {
|
||||||
|
Some(FollowEvent::Unfollow)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<ItemEvent> for Editor {}
|
||||||
|
|
||||||
impl FollowableItem for Editor {
|
impl FollowableItem for Editor {
|
||||||
|
type FollowableEvent = Event;
|
||||||
fn remote_id(&self) -> Option<ViewId> {
|
fn remote_id(&self) -> Option<ViewId> {
|
||||||
self.remote_id
|
self.remote_id
|
||||||
}
|
}
|
||||||
|
@ -217,7 +236,7 @@ impl FollowableItem for Editor {
|
||||||
|
|
||||||
fn add_event_to_update_proto(
|
fn add_event_to_update_proto(
|
||||||
&self,
|
&self,
|
||||||
event: &Self::Event,
|
event: &Self::FollowableEvent,
|
||||||
update: &mut Option<proto::update_view::Variant>,
|
update: &mut Option<proto::update_view::Variant>,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -292,15 +311,6 @@ impl FollowableItem for Editor {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_unfollow_on_event(event: &Self::Event, _: &AppContext) -> bool {
|
|
||||||
match event {
|
|
||||||
Event::Edited => true,
|
|
||||||
Event::SelectionsChanged { local } => *local,
|
|
||||||
Event::ScrollPositionChanged { local, .. } => *local,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_project_item(&self, _cx: &AppContext) -> bool {
|
fn is_project_item(&self, _cx: &AppContext) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -739,32 +749,6 @@ impl Item for Editor {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_item_events(event: &Self::Event) -> SmallVec<[ItemEvent; 2]> {
|
|
||||||
let mut result = SmallVec::new();
|
|
||||||
match event {
|
|
||||||
Event::Closed => result.push(ItemEvent::CloseItem),
|
|
||||||
Event::Saved | Event::TitleChanged => {
|
|
||||||
result.push(ItemEvent::UpdateTab);
|
|
||||||
result.push(ItemEvent::UpdateBreadcrumbs);
|
|
||||||
}
|
|
||||||
Event::Reparsed => {
|
|
||||||
result.push(ItemEvent::UpdateBreadcrumbs);
|
|
||||||
}
|
|
||||||
Event::SelectionsChanged { local } if *local => {
|
|
||||||
result.push(ItemEvent::UpdateBreadcrumbs);
|
|
||||||
}
|
|
||||||
Event::DirtyChanged => {
|
|
||||||
result.push(ItemEvent::UpdateTab);
|
|
||||||
}
|
|
||||||
Event::BufferEdited => {
|
|
||||||
result.push(ItemEvent::Edit);
|
|
||||||
result.push(ItemEvent::UpdateBreadcrumbs);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_searchable(&self, handle: &View<Self>) -> Option<Box<dyn SearchableItemHandle>> {
|
fn as_searchable(&self, handle: &View<Self>) -> Option<Box<dyn SearchableItemHandle>> {
|
||||||
Some(Box::new(handle.clone()))
|
Some(Box::new(handle.clone()))
|
||||||
}
|
}
|
||||||
|
@ -913,28 +897,12 @@ impl ProjectItem for Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<SearchEvent> for Editor {}
|
||||||
|
|
||||||
pub(crate) enum BufferSearchHighlights {}
|
pub(crate) enum BufferSearchHighlights {}
|
||||||
impl SearchableItem for Editor {
|
impl SearchableItem for Editor {
|
||||||
type Match = Range<Anchor>;
|
type Match = Range<Anchor>;
|
||||||
|
|
||||||
fn to_search_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Self::Event,
|
|
||||||
_: &mut ViewContext<Self>,
|
|
||||||
) -> Option<SearchEvent> {
|
|
||||||
match event {
|
|
||||||
Event::BufferEdited => Some(SearchEvent::MatchesInvalidated),
|
|
||||||
Event::SelectionsChanged { .. } => {
|
|
||||||
if self.selections.disjoint_anchors().len() == 1 {
|
|
||||||
Some(SearchEvent::ActiveMatchChanged)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clear_matches(&mut self, cx: &mut ViewContext<Self>) {
|
fn clear_matches(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
todo!()
|
todo!()
|
||||||
// self.clear_background_highlights::<BufferSearchHighlights>(cx);
|
// self.clear_background_highlights::<BufferSearchHighlights>(cx);
|
||||||
|
|
|
@ -9,7 +9,7 @@ path = "src/fs2.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
rope = { path = "../rope" }
|
rope = { package = "rope2", path = "../rope2" }
|
||||||
text = { package = "text2", path = "../text2" }
|
text = { package = "text2", path = "../text2" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
sum_tree = { path = "../sum_tree" }
|
sum_tree = { path = "../sum_tree" }
|
||||||
|
|
|
@ -1,220 +1,187 @@
|
||||||
use gpui::{actions, div, px, red, AppContext, Div, Render, Styled, ViewContext, VisualContext};
|
use editor::{display_map::ToDisplayPoint, scroll::autoscroll::Autoscroll, Editor};
|
||||||
use workspace::ModalRegistry;
|
use gpui::{
|
||||||
|
actions, div, AppContext, Div, EventEmitter, ParentElement, Render, SharedString,
|
||||||
|
StatefulInteractivity, StatelessInteractive, Styled, Subscription, View, ViewContext,
|
||||||
|
VisualContext, WindowContext,
|
||||||
|
};
|
||||||
|
use text::{Bias, Point};
|
||||||
|
use theme::ActiveTheme;
|
||||||
|
use ui::{h_stack, modal, v_stack, Label, LabelColor};
|
||||||
|
use util::paths::FILE_ROW_COLUMN_DELIMITER;
|
||||||
|
use workspace::{ModalEvent, Workspace};
|
||||||
|
|
||||||
actions!(Toggle);
|
actions!(Toggle);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
cx.global_mut::<ModalRegistry>()
|
cx.observe_new_views(
|
||||||
.register_modal(Toggle, |_, cx| {
|
|workspace: &mut Workspace, _: &mut ViewContext<Workspace>| {
|
||||||
// if let Some(editor) = workspace
|
workspace
|
||||||
// .active_item(cx)
|
.modal_layer()
|
||||||
// .and_then(|active_item| active_item.downcast::<Editor>())
|
.register_modal(Toggle, |workspace, cx| {
|
||||||
// {
|
let editor = workspace
|
||||||
// cx.build_view(|cx| GoToLine::new(editor, cx))
|
.active_item(cx)
|
||||||
// }
|
.and_then(|active_item| active_item.downcast::<Editor>())?;
|
||||||
let view = cx.build_view(|_| GoToLine);
|
|
||||||
view
|
|
||||||
});
|
|
||||||
|
|
||||||
// cx.add_action(GoToLine::toggle);
|
Some(cx.build_view(|cx| GoToLine::new(editor, cx)))
|
||||||
// cx.add_action(GoToLine::confirm);
|
});
|
||||||
// cx.add_action(GoToLine::cancel);
|
},
|
||||||
|
)
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GoToLine;
|
pub struct GoToLine {
|
||||||
|
line_editor: View<Editor>,
|
||||||
|
active_editor: View<Editor>,
|
||||||
|
current_text: SharedString,
|
||||||
|
prev_scroll_position: Option<gpui::Point<f32>>,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
impl Render for GoToLine {
|
pub enum Event {
|
||||||
type Element = Div<Self>;
|
Dismissed,
|
||||||
|
}
|
||||||
|
|
||||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
impl EventEmitter<Event> for GoToLine {}
|
||||||
div().bg(red()).w(px(100.0)).h(px(100.0))
|
|
||||||
|
impl EventEmitter<ModalEvent> for GoToLine {}
|
||||||
|
|
||||||
|
impl GoToLine {
|
||||||
|
pub fn new(active_editor: View<Editor>, cx: &mut ViewContext<Self>) -> Self {
|
||||||
|
let line_editor = cx.build_view(|cx| {
|
||||||
|
let editor = Editor::single_line(cx);
|
||||||
|
editor.focus(cx);
|
||||||
|
editor
|
||||||
|
});
|
||||||
|
let line_editor_change = cx.subscribe(&line_editor, Self::on_line_editor_event);
|
||||||
|
|
||||||
|
let editor = active_editor.read(cx);
|
||||||
|
let cursor = editor.selections.last::<Point>(cx).head();
|
||||||
|
let last_line = editor.buffer().read(cx).snapshot(cx).max_point().row;
|
||||||
|
let scroll_position = active_editor.update(cx, |editor, cx| editor.scroll_position(cx));
|
||||||
|
|
||||||
|
let current_text = format!(
|
||||||
|
"line {} of {} (column {})",
|
||||||
|
cursor.row + 1,
|
||||||
|
last_line + 1,
|
||||||
|
cursor.column + 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
line_editor,
|
||||||
|
active_editor,
|
||||||
|
current_text: current_text.into(),
|
||||||
|
prev_scroll_position: Some(scroll_position),
|
||||||
|
_subscriptions: vec![line_editor_change, cx.on_release(Self::release)],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn release(&mut self, cx: &mut WindowContext) {
|
||||||
|
let scroll_position = self.prev_scroll_position.take();
|
||||||
|
self.active_editor.update(cx, |editor, cx| {
|
||||||
|
editor.focus(cx);
|
||||||
|
editor.highlight_rows(None);
|
||||||
|
if let Some(scroll_position) = scroll_position {
|
||||||
|
editor.set_scroll_position(scroll_position, cx);
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_line_editor_event(
|
||||||
|
&mut self,
|
||||||
|
_: View<Editor>,
|
||||||
|
event: &editor::Event,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
|
match event {
|
||||||
|
// todo!() this isn't working...
|
||||||
|
editor::Event::Blurred => cx.emit(Event::Dismissed),
|
||||||
|
editor::Event::BufferEdited { .. } => self.highlight_current_line(cx),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn highlight_current_line(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
if let Some(point) = self.point_from_query(cx) {
|
||||||
|
self.active_editor.update(cx, |active_editor, cx| {
|
||||||
|
let snapshot = active_editor.snapshot(cx).display_snapshot;
|
||||||
|
let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
|
||||||
|
let display_point = point.to_display_point(&snapshot);
|
||||||
|
let row = display_point.row();
|
||||||
|
active_editor.highlight_rows(Some(row..row + 1));
|
||||||
|
active_editor.request_autoscroll(Autoscroll::center(), cx);
|
||||||
|
});
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn point_from_query(&self, cx: &ViewContext<Self>) -> Option<Point> {
|
||||||
|
let line_editor = self.line_editor.read(cx).text(cx);
|
||||||
|
let mut components = line_editor
|
||||||
|
.splitn(2, FILE_ROW_COLUMN_DELIMITER)
|
||||||
|
.map(str::trim)
|
||||||
|
.fuse();
|
||||||
|
let row = components.next().and_then(|row| row.parse::<u32>().ok())?;
|
||||||
|
let column = components.next().and_then(|col| col.parse::<u32>().ok());
|
||||||
|
Some(Point::new(
|
||||||
|
row.saturating_sub(1),
|
||||||
|
column.unwrap_or(0).saturating_sub(1),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
|
||||||
|
cx.emit(Event::Dismissed);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
|
||||||
|
if let Some(point) = self.point_from_query(cx) {
|
||||||
|
self.active_editor.update(cx, |active_editor, cx| {
|
||||||
|
let snapshot = active_editor.snapshot(cx).display_snapshot;
|
||||||
|
let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
|
||||||
|
active_editor.change_selections(Some(Autoscroll::center()), cx, |s| {
|
||||||
|
s.select_ranges([point..point])
|
||||||
|
});
|
||||||
|
});
|
||||||
|
self.prev_scroll_position.take();
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.emit(Event::Dismissed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub struct GoToLine {
|
impl Render for GoToLine {
|
||||||
// //line_editor: View<Editor>,
|
type Element = Div<Self, StatefulInteractivity<Self>>;
|
||||||
// active_editor: View<Editor>,
|
|
||||||
// prev_scroll_position: Option<gpui::Point<Pixels>>,
|
|
||||||
// cursor_point: Point,
|
|
||||||
// max_point: Point,
|
|
||||||
// has_focus: bool,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub enum Event {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
// Dismissed,
|
modal(cx)
|
||||||
// }
|
.id("go to line")
|
||||||
|
.on_action(Self::cancel)
|
||||||
// impl GoToLine {
|
.on_action(Self::confirm)
|
||||||
// pub fn new(active_editor: View<Editor>, cx: &mut ViewContext<Self>) -> Self {
|
.w_96()
|
||||||
// // let line_editor = cx.build_view(|cx| {
|
.child(
|
||||||
// // Editor::single_line(
|
v_stack()
|
||||||
// // Some(Arc::new(|theme| theme.picker.input_editor.clone())),
|
.px_1()
|
||||||
// // cx,
|
.pt_0p5()
|
||||||
// // )
|
.gap_px()
|
||||||
// // });
|
.child(
|
||||||
// // cx.subscribe(&line_editor, Self::on_line_editor_event)
|
v_stack()
|
||||||
// // .detach();
|
.py_0p5()
|
||||||
|
.px_1()
|
||||||
// let (scroll_position, cursor_point, max_point) = active_editor.update(cx, |editor, cx| {
|
.child(div().px_1().py_0p5().child(self.line_editor.clone())),
|
||||||
// let scroll_position = editor.scroll_position(cx);
|
)
|
||||||
// let buffer = editor.buffer().read(cx).snapshot(cx);
|
.child(
|
||||||
// (
|
div()
|
||||||
// Some(scroll_position),
|
.h_px()
|
||||||
// editor.selections.newest(cx).head(),
|
.w_full()
|
||||||
// buffer.max_point(),
|
.bg(cx.theme().colors().element_background),
|
||||||
// )
|
)
|
||||||
// });
|
.child(
|
||||||
|
h_stack()
|
||||||
// cx.on_release(|_, on_release| {}).detach();
|
.justify_between()
|
||||||
|
.px_2()
|
||||||
// Self {
|
.py_1()
|
||||||
// //line_editor,
|
.child(Label::new(self.current_text.clone()).color(LabelColor::Muted)),
|
||||||
// active_editor,
|
),
|
||||||
// prev_scroll_position: scroll_position,
|
)
|
||||||
// cursor_point,
|
}
|
||||||
// max_point,
|
}
|
||||||
// has_focus: false,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
|
|
||||||
// cx.emit(Event::Dismissed);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
|
|
||||||
// self.prev_scroll_position.take();
|
|
||||||
// if let Some(point) = self.point_from_query(cx) {
|
|
||||||
// self.active_editor.update(cx, |active_editor, cx| {
|
|
||||||
// let snapshot = active_editor.snapshot(cx).display_snapshot;
|
|
||||||
// let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
|
|
||||||
// active_editor.change_selections(Some(Autoscroll::center()), cx, |s| {
|
|
||||||
// s.select_ranges([point..point])
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// cx.emit(Event::Dismissed);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn on_line_editor_event(
|
|
||||||
// &mut self,
|
|
||||||
// _: View<Editor>,
|
|
||||||
// event: &editor::Event,
|
|
||||||
// cx: &mut ViewContext<Self>,
|
|
||||||
// ) {
|
|
||||||
// match event {
|
|
||||||
// editor::Event::Blurred => cx.emit(Event::Dismissed),
|
|
||||||
// editor::Event::BufferEdited { .. } => {
|
|
||||||
// if let Some(point) = self.point_from_query(cx) {
|
|
||||||
// // todo!()
|
|
||||||
// // self.active_editor.update(cx, |active_editor, cx| {
|
|
||||||
// // let snapshot = active_editor.snapshot(cx).display_snapshot;
|
|
||||||
// // let point = snapshot.buffer_snapshot.clip_point(point, Bias::Left);
|
|
||||||
// // let display_point = point.to_display_point(&snapshot);
|
|
||||||
// // let row = display_point.row();
|
|
||||||
// // active_editor.highlight_rows(Some(row..row + 1));
|
|
||||||
// // active_editor.request_autoscroll(Autoscroll::center(), cx);
|
|
||||||
// // });
|
|
||||||
// cx.notify();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// _ => {}
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn point_from_query(&self, cx: &ViewContext<Self>) -> Option<Point> {
|
|
||||||
// return None;
|
|
||||||
// // todo!()
|
|
||||||
// // let line_editor = self.line_editor.read(cx).text(cx);
|
|
||||||
// // let mut components = line_editor
|
|
||||||
// // .splitn(2, FILE_ROW_COLUMN_DELIMITER)
|
|
||||||
// // .map(str::trim)
|
|
||||||
// // .fuse();
|
|
||||||
// // let row = components.next().and_then(|row| row.parse::<u32>().ok())?;
|
|
||||||
// // let column = components.next().and_then(|col| col.parse::<u32>().ok());
|
|
||||||
// // Some(Point::new(
|
|
||||||
// // row.saturating_sub(1),
|
|
||||||
// // column.unwrap_or(0).saturating_sub(1),
|
|
||||||
// // ))
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl EventEmitter for GoToLine {
|
|
||||||
// type Event = Event;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl Entity for GoToLine {
|
|
||||||
// fn release(&mut self, cx: &mut AppContext) {
|
|
||||||
// let scroll_position = self.prev_scroll_position.take();
|
|
||||||
// self.active_editor.window().update(cx, |cx| {
|
|
||||||
// self.active_editor.update(cx, |editor, cx| {
|
|
||||||
// editor.highlight_rows(None);
|
|
||||||
// if let Some(scroll_position) = scroll_position {
|
|
||||||
// editor.set_scroll_position(scroll_position, cx);
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl Render for GoToLine {
|
|
||||||
// type Element = Div<Self>;
|
|
||||||
|
|
||||||
// fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
|
||||||
// // todo!()
|
|
||||||
// div()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl View for GoToLine {
|
|
||||||
// fn ui_name() -> &'static str {
|
|
||||||
// "GoToLine"
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
|
||||||
// let theme = &theme::current(cx).picker;
|
|
||||||
|
|
||||||
// let label = format!(
|
|
||||||
// "{}{FILE_ROW_COLUMN_DELIMITER}{} of {} lines",
|
|
||||||
// self.cursor_point.row + 1,
|
|
||||||
// self.cursor_point.column + 1,
|
|
||||||
// self.max_point.row + 1
|
|
||||||
// );
|
|
||||||
|
|
||||||
// Flex::new(Axis::Vertical)
|
|
||||||
// .with_child(
|
|
||||||
// ChildView::new(&self.line_editor, cx)
|
|
||||||
// .contained()
|
|
||||||
// .with_style(theme.input_editor.container),
|
|
||||||
// )
|
|
||||||
// .with_child(
|
|
||||||
// Label::new(label, theme.no_matches.label.clone())
|
|
||||||
// .contained()
|
|
||||||
// .with_style(theme.no_matches.container),
|
|
||||||
// )
|
|
||||||
// .contained()
|
|
||||||
// .with_style(theme.container)
|
|
||||||
// .constrained()
|
|
||||||
// .with_max_width(500.0)
|
|
||||||
// .into_any_named("go to line")
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn focus_in(&mut self, _: AnyView, cx: &mut ViewContext<Self>) {
|
|
||||||
// self.has_focus = true;
|
|
||||||
// cx.focus(&self.line_editor);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn focus_out(&mut self, _: AnyView, _: &mut ViewContext<Self>) {
|
|
||||||
// self.has_focus = false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl Modal for GoToLine {
|
|
||||||
// fn has_focus(&self) -> bool {
|
|
||||||
// self.has_focus
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn dismiss_on_event(event: &Self::Event) -> bool {
|
|
||||||
// matches!(event, Event::Dismissed)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
|
@ -123,6 +123,7 @@ pub fn register_action<A: Action>() {
|
||||||
/// Construct an action based on its name and optional JSON parameters sourced from the keymap.
|
/// Construct an action based on its name and optional JSON parameters sourced from the keymap.
|
||||||
pub fn build_action(name: &str, params: Option<serde_json::Value>) -> Result<Box<dyn Action>> {
|
pub fn build_action(name: &str, params: Option<serde_json::Value>) -> Result<Box<dyn Action>> {
|
||||||
let lock = ACTION_REGISTRY.read();
|
let lock = ACTION_REGISTRY.read();
|
||||||
|
|
||||||
let build_action = lock
|
let build_action = lock
|
||||||
.builders_by_name
|
.builders_by_name
|
||||||
.get(name)
|
.get(name)
|
||||||
|
|
|
@ -18,8 +18,8 @@ use crate::{
|
||||||
AppMetadata, AssetSource, BackgroundExecutor, ClipboardItem, Context, DispatchPhase, DisplayId,
|
AppMetadata, AssetSource, BackgroundExecutor, ClipboardItem, Context, DispatchPhase, DisplayId,
|
||||||
Entity, EventEmitter, FocusEvent, FocusHandle, FocusId, ForegroundExecutor, KeyBinding, Keymap,
|
Entity, EventEmitter, FocusEvent, FocusHandle, FocusId, ForegroundExecutor, KeyBinding, Keymap,
|
||||||
LayoutId, PathPromptOptions, Pixels, Platform, PlatformDisplay, Point, Render, SubscriberSet,
|
LayoutId, PathPromptOptions, Pixels, Platform, PlatformDisplay, Point, Render, SubscriberSet,
|
||||||
Subscription, SvgRenderer, Task, TextStyle, TextStyleRefinement, TextSystem, View, Window,
|
Subscription, SvgRenderer, Task, TextStyle, TextStyleRefinement, TextSystem, View, ViewContext,
|
||||||
WindowContext, WindowHandle, WindowId,
|
Window, WindowContext, WindowHandle, WindowId,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use collections::{HashMap, HashSet, VecDeque};
|
use collections::{HashMap, HashSet, VecDeque};
|
||||||
|
@ -167,6 +167,7 @@ type Handler = Box<dyn FnMut(&mut AppContext) -> bool + 'static>;
|
||||||
type Listener = Box<dyn FnMut(&dyn Any, &mut AppContext) -> bool + 'static>;
|
type Listener = Box<dyn FnMut(&dyn Any, &mut AppContext) -> bool + 'static>;
|
||||||
type QuitHandler = Box<dyn FnOnce(&mut AppContext) -> LocalBoxFuture<'static, ()> + 'static>;
|
type QuitHandler = Box<dyn FnOnce(&mut AppContext) -> LocalBoxFuture<'static, ()> + 'static>;
|
||||||
type ReleaseListener = Box<dyn FnOnce(&mut dyn Any, &mut AppContext) + 'static>;
|
type ReleaseListener = Box<dyn FnOnce(&mut dyn Any, &mut AppContext) + 'static>;
|
||||||
|
type NewViewListener = Box<dyn FnMut(AnyView, &mut WindowContext) + 'static>;
|
||||||
|
|
||||||
// struct FrameConsumer {
|
// struct FrameConsumer {
|
||||||
// next_frame_callbacks: Vec<FrameCallback>,
|
// next_frame_callbacks: Vec<FrameCallback>,
|
||||||
|
@ -193,6 +194,7 @@ pub struct AppContext {
|
||||||
pub(crate) text_style_stack: Vec<TextStyleRefinement>,
|
pub(crate) text_style_stack: Vec<TextStyleRefinement>,
|
||||||
pub(crate) globals_by_type: HashMap<TypeId, AnyBox>,
|
pub(crate) globals_by_type: HashMap<TypeId, AnyBox>,
|
||||||
pub(crate) entities: EntityMap,
|
pub(crate) entities: EntityMap,
|
||||||
|
pub(crate) new_view_observers: SubscriberSet<TypeId, NewViewListener>,
|
||||||
pub(crate) windows: SlotMap<WindowId, Option<Window>>,
|
pub(crate) windows: SlotMap<WindowId, Option<Window>>,
|
||||||
pub(crate) keymap: Arc<Mutex<Keymap>>,
|
pub(crate) keymap: Arc<Mutex<Keymap>>,
|
||||||
pub(crate) global_action_listeners:
|
pub(crate) global_action_listeners:
|
||||||
|
@ -201,7 +203,8 @@ pub struct AppContext {
|
||||||
pub(crate) pending_notifications: HashSet<EntityId>,
|
pub(crate) pending_notifications: HashSet<EntityId>,
|
||||||
pub(crate) pending_global_notifications: HashSet<TypeId>,
|
pub(crate) pending_global_notifications: HashSet<TypeId>,
|
||||||
pub(crate) observers: SubscriberSet<EntityId, Handler>,
|
pub(crate) observers: SubscriberSet<EntityId, Handler>,
|
||||||
pub(crate) event_listeners: SubscriberSet<EntityId, Listener>,
|
// TypeId is the type of the event that the listener callback expects
|
||||||
|
pub(crate) event_listeners: SubscriberSet<EntityId, (TypeId, Listener)>,
|
||||||
pub(crate) release_listeners: SubscriberSet<EntityId, ReleaseListener>,
|
pub(crate) release_listeners: SubscriberSet<EntityId, ReleaseListener>,
|
||||||
pub(crate) global_observers: SubscriberSet<TypeId, Handler>,
|
pub(crate) global_observers: SubscriberSet<TypeId, Handler>,
|
||||||
pub(crate) quit_observers: SubscriberSet<(), QuitHandler>,
|
pub(crate) quit_observers: SubscriberSet<(), QuitHandler>,
|
||||||
|
@ -251,6 +254,7 @@ impl AppContext {
|
||||||
text_style_stack: Vec::new(),
|
text_style_stack: Vec::new(),
|
||||||
globals_by_type: HashMap::default(),
|
globals_by_type: HashMap::default(),
|
||||||
entities,
|
entities,
|
||||||
|
new_view_observers: SubscriberSet::new(),
|
||||||
windows: SlotMap::with_key(),
|
windows: SlotMap::with_key(),
|
||||||
keymap: Arc::new(Mutex::new(Keymap::default())),
|
keymap: Arc::new(Mutex::new(Keymap::default())),
|
||||||
global_action_listeners: HashMap::default(),
|
global_action_listeners: HashMap::default(),
|
||||||
|
@ -351,14 +355,15 @@ impl AppContext {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscribe<T, E>(
|
pub fn subscribe<T, E, Evt>(
|
||||||
&mut self,
|
&mut self,
|
||||||
entity: &E,
|
entity: &E,
|
||||||
mut on_event: impl FnMut(E, &T::Event, &mut AppContext) + 'static,
|
mut on_event: impl FnMut(E, &Evt, &mut AppContext) + 'static,
|
||||||
) -> Subscription
|
) -> Subscription
|
||||||
where
|
where
|
||||||
T: 'static + EventEmitter,
|
T: 'static + EventEmitter<Evt>,
|
||||||
E: Entity<T>,
|
E: Entity<T>,
|
||||||
|
Evt: 'static,
|
||||||
{
|
{
|
||||||
self.subscribe_internal(entity, move |entity, event, cx| {
|
self.subscribe_internal(entity, move |entity, event, cx| {
|
||||||
on_event(entity, event, cx);
|
on_event(entity, event, cx);
|
||||||
|
@ -366,27 +371,32 @@ impl AppContext {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn subscribe_internal<T, E>(
|
pub(crate) fn subscribe_internal<T, E, Evt>(
|
||||||
&mut self,
|
&mut self,
|
||||||
entity: &E,
|
entity: &E,
|
||||||
mut on_event: impl FnMut(E, &T::Event, &mut AppContext) -> bool + 'static,
|
mut on_event: impl FnMut(E, &Evt, &mut AppContext) -> bool + 'static,
|
||||||
) -> Subscription
|
) -> Subscription
|
||||||
where
|
where
|
||||||
T: 'static + EventEmitter,
|
T: 'static + EventEmitter<Evt>,
|
||||||
E: Entity<T>,
|
E: Entity<T>,
|
||||||
|
Evt: 'static,
|
||||||
{
|
{
|
||||||
let entity_id = entity.entity_id();
|
let entity_id = entity.entity_id();
|
||||||
let entity = entity.downgrade();
|
let entity = entity.downgrade();
|
||||||
|
|
||||||
self.event_listeners.insert(
|
self.event_listeners.insert(
|
||||||
entity_id,
|
entity_id,
|
||||||
|
(
|
||||||
|
TypeId::of::<Evt>(),
|
||||||
Box::new(move |event, cx| {
|
Box::new(move |event, cx| {
|
||||||
let event: &T::Event = event.downcast_ref().expect("invalid event type");
|
let event: &Evt = event.downcast_ref().expect("invalid event type");
|
||||||
if let Some(handle) = E::upgrade_from(&entity) {
|
if let Some(handle) = E::upgrade_from(&entity) {
|
||||||
on_event(handle, event, cx)
|
on_event(handle, event, cx)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,7 +519,11 @@ impl AppContext {
|
||||||
Effect::Notify { emitter } => {
|
Effect::Notify { emitter } => {
|
||||||
self.apply_notify_effect(emitter);
|
self.apply_notify_effect(emitter);
|
||||||
}
|
}
|
||||||
Effect::Emit { emitter, event } => self.apply_emit_effect(emitter, event),
|
Effect::Emit {
|
||||||
|
emitter,
|
||||||
|
event_type,
|
||||||
|
event,
|
||||||
|
} => self.apply_emit_effect(emitter, event_type, event),
|
||||||
Effect::FocusChanged {
|
Effect::FocusChanged {
|
||||||
window_handle,
|
window_handle,
|
||||||
focused,
|
focused,
|
||||||
|
@ -599,15 +613,22 @@ impl AppContext {
|
||||||
|
|
||||||
fn apply_notify_effect(&mut self, emitter: EntityId) {
|
fn apply_notify_effect(&mut self, emitter: EntityId) {
|
||||||
self.pending_notifications.remove(&emitter);
|
self.pending_notifications.remove(&emitter);
|
||||||
|
|
||||||
self.observers
|
self.observers
|
||||||
.clone()
|
.clone()
|
||||||
.retain(&emitter, |handler| handler(self));
|
.retain(&emitter, |handler| handler(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_emit_effect(&mut self, emitter: EntityId, event: Box<dyn Any>) {
|
fn apply_emit_effect(&mut self, emitter: EntityId, event_type: TypeId, event: Box<dyn Any>) {
|
||||||
self.event_listeners
|
self.event_listeners
|
||||||
.clone()
|
.clone()
|
||||||
.retain(&emitter, |handler| handler(event.as_ref(), self));
|
.retain(&emitter, |(stored_type, handler)| {
|
||||||
|
if *stored_type == event_type {
|
||||||
|
handler(event.as_ref(), self)
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_focus_changed_effect(
|
fn apply_focus_changed_effect(
|
||||||
|
@ -617,8 +638,9 @@ impl AppContext {
|
||||||
) {
|
) {
|
||||||
window_handle
|
window_handle
|
||||||
.update(self, |_, cx| {
|
.update(self, |_, cx| {
|
||||||
|
// The window might change focus multiple times in an effect cycle.
|
||||||
|
// We only honor effects for the most recently focused handle.
|
||||||
if cx.window.focus == focused {
|
if cx.window.focus == focused {
|
||||||
let mut listeners = mem::take(&mut cx.window.current_frame.focus_listeners);
|
|
||||||
let focused = focused
|
let focused = focused
|
||||||
.map(|id| FocusHandle::for_id(id, &cx.window.focus_handles).unwrap());
|
.map(|id| FocusHandle::for_id(id, &cx.window.focus_handles).unwrap());
|
||||||
let blurred = cx
|
let blurred = cx
|
||||||
|
@ -627,15 +649,24 @@ impl AppContext {
|
||||||
.take()
|
.take()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.and_then(|id| FocusHandle::for_id(id, &cx.window.focus_handles));
|
.and_then(|id| FocusHandle::for_id(id, &cx.window.focus_handles));
|
||||||
if focused.is_some() || blurred.is_some() {
|
let focus_changed = focused.is_some() || blurred.is_some();
|
||||||
let event = FocusEvent { focused, blurred };
|
let event = FocusEvent { focused, blurred };
|
||||||
for listener in &listeners {
|
|
||||||
|
let mut listeners = mem::take(&mut cx.window.current_frame.focus_listeners);
|
||||||
|
if focus_changed {
|
||||||
|
for listener in &mut listeners {
|
||||||
listener(&event, cx);
|
listener(&event, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listeners.extend(cx.window.current_frame.focus_listeners.drain(..));
|
listeners.extend(cx.window.current_frame.focus_listeners.drain(..));
|
||||||
cx.window.current_frame.focus_listeners = listeners;
|
cx.window.current_frame.focus_listeners = listeners;
|
||||||
|
|
||||||
|
if focus_changed {
|
||||||
|
cx.window
|
||||||
|
.focus_listeners
|
||||||
|
.clone()
|
||||||
|
.retain(&(), |listener| listener(&event, cx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
@ -828,6 +859,23 @@ impl AppContext {
|
||||||
self.globals_by_type.insert(global_type, lease.global);
|
self.globals_by_type.insert(global_type, lease.global);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn observe_new_views<V: 'static>(
|
||||||
|
&mut self,
|
||||||
|
on_new: impl 'static + Fn(&mut V, &mut ViewContext<V>),
|
||||||
|
) -> Subscription {
|
||||||
|
self.new_view_observers.insert(
|
||||||
|
TypeId::of::<V>(),
|
||||||
|
Box::new(move |any_view: AnyView, cx: &mut WindowContext| {
|
||||||
|
any_view
|
||||||
|
.downcast::<V>()
|
||||||
|
.unwrap()
|
||||||
|
.update(cx, |view_state, cx| {
|
||||||
|
on_new(view_state, cx);
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn observe_release<E, T>(
|
pub fn observe_release<E, T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &E,
|
handle: &E,
|
||||||
|
@ -968,6 +1016,7 @@ pub(crate) enum Effect {
|
||||||
},
|
},
|
||||||
Emit {
|
Emit {
|
||||||
emitter: EntityId,
|
emitter: EntityId,
|
||||||
|
event_type: TypeId,
|
||||||
event: Box<dyn Any>,
|
event: Box<dyn Any>,
|
||||||
},
|
},
|
||||||
FocusChanged {
|
FocusChanged {
|
||||||
|
|
|
@ -258,7 +258,7 @@ impl VisualContext for AsyncWindowContext {
|
||||||
build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
||||||
) -> Self::Result<View<V>>
|
) -> Self::Result<View<V>>
|
||||||
where
|
where
|
||||||
V: 'static,
|
V: 'static + Render,
|
||||||
{
|
{
|
||||||
self.window
|
self.window
|
||||||
.update(self, |_, cx| cx.build_view(build_view_state))
|
.update(self, |_, cx| cx.build_view(build_view_state))
|
||||||
|
|
|
@ -59,15 +59,16 @@ impl<'a, T: 'static> ModelContext<'a, T> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscribe<T2, E>(
|
pub fn subscribe<T2, E, Evt>(
|
||||||
&mut self,
|
&mut self,
|
||||||
entity: &E,
|
entity: &E,
|
||||||
mut on_event: impl FnMut(&mut T, E, &T2::Event, &mut ModelContext<'_, T>) + 'static,
|
mut on_event: impl FnMut(&mut T, E, &Evt, &mut ModelContext<'_, T>) + 'static,
|
||||||
) -> Subscription
|
) -> Subscription
|
||||||
where
|
where
|
||||||
T: 'static,
|
T: 'static,
|
||||||
T2: 'static + EventEmitter,
|
T2: 'static + EventEmitter<Evt>,
|
||||||
E: Entity<T2>,
|
E: Entity<T2>,
|
||||||
|
Evt: 'static,
|
||||||
{
|
{
|
||||||
let this = self.weak_model();
|
let this = self.weak_model();
|
||||||
self.app.subscribe_internal(entity, move |e, event, cx| {
|
self.app.subscribe_internal(entity, move |e, event, cx| {
|
||||||
|
@ -189,13 +190,15 @@ impl<'a, T: 'static> ModelContext<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> ModelContext<'a, T>
|
impl<'a, T> ModelContext<'a, T> {
|
||||||
where
|
pub fn emit<Evt>(&mut self, event: Evt)
|
||||||
T: EventEmitter,
|
where
|
||||||
{
|
T: EventEmitter<Evt>,
|
||||||
pub fn emit(&mut self, event: T::Event) {
|
Evt: 'static,
|
||||||
|
{
|
||||||
self.app.pending_effects.push_back(Effect::Emit {
|
self.app.pending_effects.push_back(Effect::Emit {
|
||||||
emitter: self.model_state.entity_id,
|
emitter: self.model_state.entity_id,
|
||||||
|
event_type: TypeId::of::<Evt>(),
|
||||||
event: Box::new(event),
|
event: Box::new(event),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,12 +197,12 @@ impl TestAppContext {
|
||||||
rx
|
rx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn events<T: 'static + EventEmitter>(
|
pub fn events<Evt, T: 'static + EventEmitter<Evt>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
entity: &Model<T>,
|
entity: &Model<T>,
|
||||||
) -> futures::channel::mpsc::UnboundedReceiver<T::Event>
|
) -> futures::channel::mpsc::UnboundedReceiver<Evt>
|
||||||
where
|
where
|
||||||
T::Event: 'static + Clone,
|
Evt: 'static + Clone,
|
||||||
{
|
{
|
||||||
let (tx, rx) = futures::channel::mpsc::unbounded();
|
let (tx, rx) = futures::channel::mpsc::unbounded();
|
||||||
entity
|
entity
|
||||||
|
@ -240,10 +240,11 @@ impl TestAppContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Send + EventEmitter> Model<T> {
|
impl<T: Send> Model<T> {
|
||||||
pub fn next_event(&self, cx: &mut TestAppContext) -> T::Event
|
pub fn next_event<Evt>(&self, cx: &mut TestAppContext) -> Evt
|
||||||
where
|
where
|
||||||
T::Event: Send + Clone,
|
Evt: Send + Clone + 'static,
|
||||||
|
T: EventEmitter<Evt>,
|
||||||
{
|
{
|
||||||
let (tx, mut rx) = futures::channel::mpsc::unbounded();
|
let (tx, mut rx) = futures::channel::mpsc::unbounded();
|
||||||
let _subscription = self.update(cx, |_, cx| {
|
let _subscription = self.update(cx, |_, cx| {
|
||||||
|
|
|
@ -9,6 +9,7 @@ mod executor;
|
||||||
mod focusable;
|
mod focusable;
|
||||||
mod geometry;
|
mod geometry;
|
||||||
mod image_cache;
|
mod image_cache;
|
||||||
|
mod input;
|
||||||
mod interactive;
|
mod interactive;
|
||||||
mod keymap;
|
mod keymap;
|
||||||
mod platform;
|
mod platform;
|
||||||
|
@ -24,7 +25,6 @@ mod text_system;
|
||||||
mod util;
|
mod util;
|
||||||
mod view;
|
mod view;
|
||||||
mod window;
|
mod window;
|
||||||
mod window_input_handler;
|
|
||||||
|
|
||||||
mod private {
|
mod private {
|
||||||
/// A mechanism for restricting implementations of a trait to only those in GPUI.
|
/// A mechanism for restricting implementations of a trait to only those in GPUI.
|
||||||
|
@ -45,6 +45,7 @@ pub use focusable::*;
|
||||||
pub use geometry::*;
|
pub use geometry::*;
|
||||||
pub use gpui2_macros::*;
|
pub use gpui2_macros::*;
|
||||||
pub use image_cache::*;
|
pub use image_cache::*;
|
||||||
|
pub use input::*;
|
||||||
pub use interactive::*;
|
pub use interactive::*;
|
||||||
pub use keymap::*;
|
pub use keymap::*;
|
||||||
pub use platform::*;
|
pub use platform::*;
|
||||||
|
@ -66,7 +67,6 @@ pub use text_system::*;
|
||||||
pub use util::arc_cow::ArcCow;
|
pub use util::arc_cow::ArcCow;
|
||||||
pub use view::*;
|
pub use view::*;
|
||||||
pub use window::*;
|
pub use window::*;
|
||||||
pub use window_input_handler::*;
|
|
||||||
|
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -112,7 +112,7 @@ pub trait VisualContext: Context {
|
||||||
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
||||||
) -> Self::Result<View<V>>
|
) -> Self::Result<View<V>>
|
||||||
where
|
where
|
||||||
V: 'static;
|
V: 'static + Render;
|
||||||
|
|
||||||
fn update_view<V: 'static, R>(
|
fn update_view<V: 'static, R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -138,6 +138,8 @@ pub trait Entity<T>: Sealed {
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait EventEmitter<E: Any>: 'static {}
|
||||||
|
|
||||||
pub enum GlobalKey {
|
pub enum GlobalKey {
|
||||||
Numeric(usize),
|
Numeric(usize),
|
||||||
View(EntityId),
|
View(EntityId),
|
||||||
|
@ -171,10 +173,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait EventEmitter: 'static {
|
|
||||||
type Event: Any;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Flatten<T> {
|
pub trait Flatten<T> {
|
||||||
fn flatten(self) -> Result<T>;
|
fn flatten(self) -> Result<T>;
|
||||||
}
|
}
|
||||||
|
|
114
crates/gpui2/src/input.rs
Normal file
114
crates/gpui2/src/input.rs
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
use crate::{AsyncWindowContext, Bounds, Pixels, PlatformInputHandler, View, ViewContext};
|
||||||
|
use std::ops::Range;
|
||||||
|
|
||||||
|
/// Implement this trait to allow views to handle textual input when implementing an editor, field, etc.
|
||||||
|
///
|
||||||
|
/// Once your view `V` implements this trait, you can use it to construct an [ElementInputHandler<V>].
|
||||||
|
/// This input handler can then be assigned during paint by calling [WindowContext::handle_input].
|
||||||
|
pub trait InputHandler: 'static + Sized {
|
||||||
|
fn text_for_range(&mut self, range: Range<usize>, cx: &mut ViewContext<Self>)
|
||||||
|
-> Option<String>;
|
||||||
|
fn selected_text_range(&mut self, cx: &mut ViewContext<Self>) -> Option<Range<usize>>;
|
||||||
|
fn marked_text_range(&self, cx: &mut ViewContext<Self>) -> Option<Range<usize>>;
|
||||||
|
fn unmark_text(&mut self, cx: &mut ViewContext<Self>);
|
||||||
|
fn replace_text_in_range(
|
||||||
|
&mut self,
|
||||||
|
range: Option<Range<usize>>,
|
||||||
|
text: &str,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
);
|
||||||
|
fn replace_and_mark_text_in_range(
|
||||||
|
&mut self,
|
||||||
|
range: Option<Range<usize>>,
|
||||||
|
new_text: &str,
|
||||||
|
new_selected_range: Option<Range<usize>>,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
);
|
||||||
|
fn bounds_for_range(
|
||||||
|
&mut self,
|
||||||
|
range_utf16: Range<usize>,
|
||||||
|
element_bounds: Bounds<Pixels>,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) -> Option<Bounds<Pixels>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The canonical implementation of `PlatformInputHandler`. Call `WindowContext::handle_input`
|
||||||
|
/// with an instance during your element's paint.
|
||||||
|
pub struct ElementInputHandler<V> {
|
||||||
|
view: View<V>,
|
||||||
|
element_bounds: Bounds<Pixels>,
|
||||||
|
cx: AsyncWindowContext,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<V: 'static> ElementInputHandler<V> {
|
||||||
|
/// Used in [Element::paint] with the element's bounds and a view context for its
|
||||||
|
/// containing view.
|
||||||
|
pub fn new(element_bounds: Bounds<Pixels>, cx: &mut ViewContext<V>) -> Self {
|
||||||
|
ElementInputHandler {
|
||||||
|
view: cx.view(),
|
||||||
|
element_bounds,
|
||||||
|
cx: cx.to_async(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<V: InputHandler> PlatformInputHandler for ElementInputHandler<V> {
|
||||||
|
fn selected_text_range(&mut self) -> Option<Range<usize>> {
|
||||||
|
self.view
|
||||||
|
.update(&mut self.cx, |view, cx| view.selected_text_range(cx))
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn marked_text_range(&mut self) -> Option<Range<usize>> {
|
||||||
|
self.view
|
||||||
|
.update(&mut self.cx, |view, cx| view.marked_text_range(cx))
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn text_for_range(&mut self, range_utf16: Range<usize>) -> Option<String> {
|
||||||
|
self.view
|
||||||
|
.update(&mut self.cx, |view, cx| {
|
||||||
|
view.text_for_range(range_utf16, cx)
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn replace_text_in_range(&mut self, replacement_range: Option<Range<usize>>, text: &str) {
|
||||||
|
self.view
|
||||||
|
.update(&mut self.cx, |view, cx| {
|
||||||
|
view.replace_text_in_range(replacement_range, text, cx)
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn replace_and_mark_text_in_range(
|
||||||
|
&mut self,
|
||||||
|
range_utf16: Option<Range<usize>>,
|
||||||
|
new_text: &str,
|
||||||
|
new_selected_range: Option<Range<usize>>,
|
||||||
|
) {
|
||||||
|
self.view
|
||||||
|
.update(&mut self.cx, |view, cx| {
|
||||||
|
view.replace_and_mark_text_in_range(range_utf16, new_text, new_selected_range, cx)
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unmark_text(&mut self) {
|
||||||
|
self.view
|
||||||
|
.update(&mut self.cx, |view, cx| view.unmark_text(cx))
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bounds_for_range(&mut self, range_utf16: Range<usize>) -> Option<Bounds<Pixels>> {
|
||||||
|
self.view
|
||||||
|
.update(&mut self.cx, |view, cx| {
|
||||||
|
view.bounds_for_range(range_utf16, self.element_bounds, cx)
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
}
|
||||||
|
}
|
|
@ -293,10 +293,10 @@ impl From<TileId> for etagere::AllocId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PlatformInputHandler {
|
pub trait PlatformInputHandler: 'static {
|
||||||
fn selected_text_range(&self) -> Option<Range<usize>>;
|
fn selected_text_range(&mut self) -> Option<Range<usize>>;
|
||||||
fn marked_text_range(&self) -> Option<Range<usize>>;
|
fn marked_text_range(&mut self) -> Option<Range<usize>>;
|
||||||
fn text_for_range(&self, range_utf16: Range<usize>) -> Option<String>;
|
fn text_for_range(&mut self, range_utf16: Range<usize>) -> Option<String>;
|
||||||
fn replace_text_in_range(&mut self, replacement_range: Option<Range<usize>>, text: &str);
|
fn replace_text_in_range(&mut self, replacement_range: Option<Range<usize>>, text: &str);
|
||||||
fn replace_and_mark_text_in_range(
|
fn replace_and_mark_text_in_range(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -305,7 +305,7 @@ pub trait PlatformInputHandler {
|
||||||
new_selected_range: Option<Range<usize>>,
|
new_selected_range: Option<Range<usize>>,
|
||||||
);
|
);
|
||||||
fn unmark_text(&mut self);
|
fn unmark_text(&mut self);
|
||||||
fn bounds_for_range(&self, range_utf16: Range<usize>) -> Option<Bounds<f32>>;
|
fn bounds_for_range(&mut self, range_utf16: Range<usize>) -> Option<Bounds<Pixels>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -1484,10 +1484,12 @@ extern "C" fn first_rect_for_character_range(
|
||||||
|bounds| {
|
|bounds| {
|
||||||
NSRect::new(
|
NSRect::new(
|
||||||
NSPoint::new(
|
NSPoint::new(
|
||||||
frame.origin.x + bounds.origin.x as f64,
|
frame.origin.x + bounds.origin.x.0 as f64,
|
||||||
frame.origin.y + frame.size.height - bounds.origin.y as f64,
|
frame.origin.y + frame.size.height
|
||||||
|
- bounds.origin.y.0 as f64
|
||||||
|
- bounds.size.height.0 as f64,
|
||||||
),
|
),
|
||||||
NSSize::new(bounds.size.width as f64, bounds.size.height as f64),
|
NSSize::new(bounds.size.width.0 as f64, bounds.size.height.0 as f64),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use crate::{BoxShadow, TextStyleRefinement};
|
use crate::{BoxShadow, TextStyleRefinement};
|
||||||
use refineable::Refineable;
|
use refineable::Refineable;
|
||||||
use smallvec::smallvec;
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
|
||||||
pub trait Styled {
|
pub trait Styled {
|
||||||
fn style(&mut self) -> &mut StyleRefinement;
|
fn style(&mut self) -> &mut StyleRefinement;
|
||||||
|
@ -295,24 +295,11 @@ pub trait Styled {
|
||||||
|
|
||||||
/// Sets the box shadow of the element.
|
/// Sets the box shadow of the element.
|
||||||
/// [Docs](https://tailwindcss.com/docs/box-shadow)
|
/// [Docs](https://tailwindcss.com/docs/box-shadow)
|
||||||
fn shadow(mut self) -> Self
|
fn shadow(mut self, shadows: SmallVec<[BoxShadow; 2]>) -> Self
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
self.style().box_shadow = Some(smallvec![
|
self.style().box_shadow = Some(shadows);
|
||||||
BoxShadow {
|
|
||||||
color: hsla(0., 0., 0., 0.1),
|
|
||||||
offset: point(px(0.), px(1.)),
|
|
||||||
blur_radius: px(3.),
|
|
||||||
spread_radius: px(0.),
|
|
||||||
},
|
|
||||||
BoxShadow {
|
|
||||||
color: hsla(0., 0., 0., 0.1),
|
|
||||||
offset: point(px(0.), px(1.)),
|
|
||||||
blur_radius: px(2.),
|
|
||||||
spread_radius: px(-1.),
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,8 @@ where
|
||||||
.flatten()
|
.flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Call the given callback for each subscriber to the given emitter.
|
||||||
|
/// If the callback returns false, the subscriber is removed.
|
||||||
pub fn retain<F>(&self, emitter: &EmitterKey, mut f: F)
|
pub fn retain<F>(&self, emitter: &EmitterKey, mut f: F)
|
||||||
where
|
where
|
||||||
F: FnMut(&mut Callback) -> bool,
|
F: FnMut(&mut Callback) -> bool,
|
||||||
|
|
|
@ -2,14 +2,13 @@ use crate::{
|
||||||
px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace,
|
px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace,
|
||||||
Bounds, BoxShadow, Context, Corners, CursorStyle, DevicePixels, DispatchContext, DisplayId,
|
Bounds, BoxShadow, Context, Corners, CursorStyle, DevicePixels, DispatchContext, DisplayId,
|
||||||
Edges, Effect, Entity, EntityId, EventEmitter, FileDropEvent, FocusEvent, FontId,
|
Edges, Effect, Entity, EntityId, EventEmitter, FileDropEvent, FocusEvent, FontId,
|
||||||
GlobalElementId, GlyphId, Hsla, ImageData, InputEvent, InputHandler, IsZero, KeyListener,
|
GlobalElementId, GlyphId, Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch,
|
||||||
KeyMatch, KeyMatcher, Keystroke, LayoutId, Model, ModelContext, Modifiers, MonochromeSprite,
|
KeyMatcher, Keystroke, LayoutId, Model, ModelContext, Modifiers, MonochromeSprite, MouseButton,
|
||||||
MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas,
|
MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay,
|
||||||
PlatformDisplay, PlatformInputHandler, PlatformWindow, Point, PolychromeSprite, PromptLevel,
|
PlatformInputHandler, PlatformWindow, Point, PolychromeSprite, PromptLevel, Quad, Render,
|
||||||
Quad, Render, RenderGlyphParams, RenderImageParams, RenderSvgParams, ScaledPixels,
|
RenderGlyphParams, RenderImageParams, RenderSvgParams, ScaledPixels, SceneBuilder, Shadow,
|
||||||
SceneBuilder, Shadow, SharedString, Size, Style, SubscriberSet, Subscription,
|
SharedString, Size, Style, SubscriberSet, Subscription, TaffyLayoutEngine, Task, Underline,
|
||||||
TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, VisualContext, WeakView,
|
UnderlineStyle, View, VisualContext, WeakView, WindowBounds, WindowOptions, SUBPIXEL_VARIANTS,
|
||||||
WindowBounds, WindowInputHandler, WindowOptions, SUBPIXEL_VARIANTS,
|
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
|
@ -60,7 +59,7 @@ pub enum DispatchPhase {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AnyObserver = Box<dyn FnMut(&mut WindowContext) -> bool + 'static>;
|
type AnyObserver = Box<dyn FnMut(&mut WindowContext) -> bool + 'static>;
|
||||||
type AnyListener = Box<dyn Fn(&dyn Any, DispatchPhase, &mut WindowContext) + 'static>;
|
type AnyListener = Box<dyn FnMut(&dyn Any, DispatchPhase, &mut WindowContext) + 'static>;
|
||||||
type AnyKeyListener = Box<
|
type AnyKeyListener = Box<
|
||||||
dyn Fn(
|
dyn Fn(
|
||||||
&dyn Any,
|
&dyn Any,
|
||||||
|
@ -71,9 +70,49 @@ type AnyKeyListener = Box<
|
||||||
+ 'static,
|
+ 'static,
|
||||||
>;
|
>;
|
||||||
type AnyFocusListener = Box<dyn Fn(&FocusEvent, &mut WindowContext) + 'static>;
|
type AnyFocusListener = Box<dyn Fn(&FocusEvent, &mut WindowContext) + 'static>;
|
||||||
|
type AnyWindowFocusListener = Box<dyn FnMut(&FocusEvent, &mut WindowContext) -> bool + 'static>;
|
||||||
|
|
||||||
slotmap::new_key_type! { pub struct FocusId; }
|
slotmap::new_key_type! { pub struct FocusId; }
|
||||||
|
|
||||||
|
impl FocusId {
|
||||||
|
/// Obtains whether the element associated with this handle is currently focused.
|
||||||
|
pub fn is_focused(&self, cx: &WindowContext) -> bool {
|
||||||
|
cx.window.focus == Some(*self)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Obtains whether the element associated with this handle contains the focused
|
||||||
|
/// element or is itself focused.
|
||||||
|
pub fn contains_focused(&self, cx: &WindowContext) -> bool {
|
||||||
|
cx.focused()
|
||||||
|
.map_or(false, |focused| self.contains(focused.id, cx))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Obtains whether the element associated with this handle is contained within the
|
||||||
|
/// focused element or is itself focused.
|
||||||
|
pub fn within_focused(&self, cx: &WindowContext) -> bool {
|
||||||
|
let focused = cx.focused();
|
||||||
|
focused.map_or(false, |focused| focused.id.contains(*self, cx))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Obtains whether this handle contains the given handle in the most recently rendered frame.
|
||||||
|
pub(crate) fn contains(&self, other: Self, cx: &WindowContext) -> bool {
|
||||||
|
let mut ancestor = Some(other);
|
||||||
|
while let Some(ancestor_id) = ancestor {
|
||||||
|
if *self == ancestor_id {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
ancestor = cx
|
||||||
|
.window
|
||||||
|
.current_frame
|
||||||
|
.focus_parents_by_child
|
||||||
|
.get(&ancestor_id)
|
||||||
|
.copied();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A handle which can be used to track and manipulate the focused element in a window.
|
/// A handle which can be used to track and manipulate the focused element in a window.
|
||||||
pub struct FocusHandle {
|
pub struct FocusHandle {
|
||||||
pub(crate) id: FocusId,
|
pub(crate) id: FocusId,
|
||||||
|
@ -108,39 +147,24 @@ impl FocusHandle {
|
||||||
|
|
||||||
/// Obtains whether the element associated with this handle is currently focused.
|
/// Obtains whether the element associated with this handle is currently focused.
|
||||||
pub fn is_focused(&self, cx: &WindowContext) -> bool {
|
pub fn is_focused(&self, cx: &WindowContext) -> bool {
|
||||||
cx.window.focus == Some(self.id)
|
self.id.is_focused(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtains whether the element associated with this handle contains the focused
|
/// Obtains whether the element associated with this handle contains the focused
|
||||||
/// element or is itself focused.
|
/// element or is itself focused.
|
||||||
pub fn contains_focused(&self, cx: &WindowContext) -> bool {
|
pub fn contains_focused(&self, cx: &WindowContext) -> bool {
|
||||||
cx.focused()
|
self.id.contains_focused(cx)
|
||||||
.map_or(false, |focused| self.contains(&focused, cx))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtains whether the element associated with this handle is contained within the
|
/// Obtains whether the element associated with this handle is contained within the
|
||||||
/// focused element or is itself focused.
|
/// focused element or is itself focused.
|
||||||
pub fn within_focused(&self, cx: &WindowContext) -> bool {
|
pub fn within_focused(&self, cx: &WindowContext) -> bool {
|
||||||
let focused = cx.focused();
|
self.id.within_focused(cx)
|
||||||
focused.map_or(false, |focused| focused.contains(self, cx))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtains whether this handle contains the given handle in the most recently rendered frame.
|
/// Obtains whether this handle contains the given handle in the most recently rendered frame.
|
||||||
pub(crate) fn contains(&self, other: &Self, cx: &WindowContext) -> bool {
|
pub(crate) fn contains(&self, other: &Self, cx: &WindowContext) -> bool {
|
||||||
let mut ancestor = Some(other.id);
|
self.id.contains(other.id, cx)
|
||||||
while let Some(ancestor_id) = ancestor {
|
|
||||||
if self.id == ancestor_id {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
ancestor = cx
|
|
||||||
.window
|
|
||||||
.current_frame
|
|
||||||
.focus_parents_by_child
|
|
||||||
.get(&ancestor_id)
|
|
||||||
.copied();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,10 +207,10 @@ pub struct Window {
|
||||||
pub(crate) previous_frame: Frame,
|
pub(crate) previous_frame: Frame,
|
||||||
pub(crate) current_frame: Frame,
|
pub(crate) current_frame: Frame,
|
||||||
pub(crate) focus_handles: Arc<RwLock<SlotMap<FocusId, AtomicUsize>>>,
|
pub(crate) focus_handles: Arc<RwLock<SlotMap<FocusId, AtomicUsize>>>,
|
||||||
|
pub(crate) focus_listeners: SubscriberSet<(), AnyWindowFocusListener>,
|
||||||
default_prevented: bool,
|
default_prevented: bool,
|
||||||
mouse_position: Point<Pixels>,
|
mouse_position: Point<Pixels>,
|
||||||
requested_cursor_style: Option<CursorStyle>,
|
requested_cursor_style: Option<CursorStyle>,
|
||||||
requested_input_handler: Option<Box<dyn PlatformInputHandler>>,
|
|
||||||
scale_factor: f32,
|
scale_factor: f32,
|
||||||
bounds: WindowBounds,
|
bounds: WindowBounds,
|
||||||
bounds_observers: SubscriberSet<(), AnyObserver>,
|
bounds_observers: SubscriberSet<(), AnyObserver>,
|
||||||
|
@ -282,10 +306,10 @@ impl Window {
|
||||||
previous_frame: Frame::default(),
|
previous_frame: Frame::default(),
|
||||||
current_frame: Frame::default(),
|
current_frame: Frame::default(),
|
||||||
focus_handles: Arc::new(RwLock::new(SlotMap::with_key())),
|
focus_handles: Arc::new(RwLock::new(SlotMap::with_key())),
|
||||||
|
focus_listeners: SubscriberSet::new(),
|
||||||
default_prevented: true,
|
default_prevented: true,
|
||||||
mouse_position,
|
mouse_position,
|
||||||
requested_cursor_style: None,
|
requested_cursor_style: None,
|
||||||
requested_input_handler: None,
|
|
||||||
scale_factor,
|
scale_factor,
|
||||||
bounds,
|
bounds,
|
||||||
bounds_observers: SubscriberSet::new(),
|
bounds_observers: SubscriberSet::new(),
|
||||||
|
@ -412,20 +436,23 @@ impl<'a> WindowContext<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscribe<Emitter, E>(
|
pub fn subscribe<Emitter, E, Evt>(
|
||||||
&mut self,
|
&mut self,
|
||||||
entity: &E,
|
entity: &E,
|
||||||
mut on_event: impl FnMut(E, &Emitter::Event, &mut WindowContext<'_>) + 'static,
|
mut on_event: impl FnMut(E, &Evt, &mut WindowContext<'_>) + 'static,
|
||||||
) -> Subscription
|
) -> Subscription
|
||||||
where
|
where
|
||||||
Emitter: EventEmitter,
|
Emitter: EventEmitter<Evt>,
|
||||||
E: Entity<Emitter>,
|
E: Entity<Emitter>,
|
||||||
|
Evt: 'static,
|
||||||
{
|
{
|
||||||
let entity_id = entity.entity_id();
|
let entity_id = entity.entity_id();
|
||||||
let entity = entity.downgrade();
|
let entity = entity.downgrade();
|
||||||
let window_handle = self.window.handle;
|
let window_handle = self.window.handle;
|
||||||
self.app.event_listeners.insert(
|
self.app.event_listeners.insert(
|
||||||
entity_id,
|
entity_id,
|
||||||
|
(
|
||||||
|
TypeId::of::<Evt>(),
|
||||||
Box::new(move |event, cx| {
|
Box::new(move |event, cx| {
|
||||||
window_handle
|
window_handle
|
||||||
.update(cx, |_, cx| {
|
.update(cx, |_, cx| {
|
||||||
|
@ -439,6 +466,7 @@ impl<'a> WindowContext<'a> {
|
||||||
})
|
})
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1022,9 +1050,6 @@ impl<'a> WindowContext<'a> {
|
||||||
.take()
|
.take()
|
||||||
.unwrap_or(CursorStyle::Arrow);
|
.unwrap_or(CursorStyle::Arrow);
|
||||||
self.platform.set_cursor_style(cursor_style);
|
self.platform.set_cursor_style(cursor_style);
|
||||||
if let Some(handler) = self.window.requested_input_handler.take() {
|
|
||||||
self.window.platform_window.set_input_handler(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.window.dirty = false;
|
self.window.dirty = false;
|
||||||
}
|
}
|
||||||
|
@ -1116,7 +1141,7 @@ impl<'a> WindowContext<'a> {
|
||||||
|
|
||||||
// Capture phase, events bubble from back to front. Handlers for this phase are used for
|
// Capture phase, events bubble from back to front. Handlers for this phase are used for
|
||||||
// special purposes, such as detecting events outside of a given Bounds.
|
// special purposes, such as detecting events outside of a given Bounds.
|
||||||
for (_, handler) in &handlers {
|
for (_, handler) in &mut handlers {
|
||||||
handler(any_mouse_event, DispatchPhase::Capture, self);
|
handler(any_mouse_event, DispatchPhase::Capture, self);
|
||||||
if !self.app.propagate_event {
|
if !self.app.propagate_event {
|
||||||
break;
|
break;
|
||||||
|
@ -1125,7 +1150,7 @@ impl<'a> WindowContext<'a> {
|
||||||
|
|
||||||
// Bubble phase, where most normal handlers do their work.
|
// Bubble phase, where most normal handlers do their work.
|
||||||
if self.app.propagate_event {
|
if self.app.propagate_event {
|
||||||
for (_, handler) in handlers.iter().rev() {
|
for (_, handler) in handlers.iter_mut().rev() {
|
||||||
handler(any_mouse_event, DispatchPhase::Bubble, self);
|
handler(any_mouse_event, DispatchPhase::Bubble, self);
|
||||||
if !self.app.propagate_event {
|
if !self.app.propagate_event {
|
||||||
break;
|
break;
|
||||||
|
@ -1411,7 +1436,7 @@ impl VisualContext for WindowContext<'_> {
|
||||||
build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
||||||
) -> Self::Result<View<V>>
|
) -> Self::Result<View<V>>
|
||||||
where
|
where
|
||||||
V: 'static,
|
V: 'static + Render,
|
||||||
{
|
{
|
||||||
let slot = self.app.entities.reserve();
|
let slot = self.app.entities.reserve();
|
||||||
let view = View {
|
let view = View {
|
||||||
|
@ -1419,7 +1444,16 @@ impl VisualContext for WindowContext<'_> {
|
||||||
};
|
};
|
||||||
let mut cx = ViewContext::new(&mut *self.app, &mut *self.window, &view);
|
let mut cx = ViewContext::new(&mut *self.app, &mut *self.window, &view);
|
||||||
let entity = build_view_state(&mut cx);
|
let entity = build_view_state(&mut cx);
|
||||||
self.entities.insert(slot, entity);
|
cx.entities.insert(slot, entity);
|
||||||
|
|
||||||
|
cx.new_view_observers
|
||||||
|
.clone()
|
||||||
|
.retain(&TypeId::of::<V>(), |observer| {
|
||||||
|
let any_view = AnyView::from(view.clone());
|
||||||
|
(observer)(any_view, self);
|
||||||
|
true
|
||||||
|
});
|
||||||
|
|
||||||
view
|
view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1782,14 +1816,15 @@ impl<'a, V: 'static> ViewContext<'a, V> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscribe<V2, E>(
|
pub fn subscribe<V2, E, Evt>(
|
||||||
&mut self,
|
&mut self,
|
||||||
entity: &E,
|
entity: &E,
|
||||||
mut on_event: impl FnMut(&mut V, E, &V2::Event, &mut ViewContext<'_, V>) + 'static,
|
mut on_event: impl FnMut(&mut V, E, &Evt, &mut ViewContext<'_, V>) + 'static,
|
||||||
) -> Subscription
|
) -> Subscription
|
||||||
where
|
where
|
||||||
V2: EventEmitter,
|
V2: EventEmitter<Evt>,
|
||||||
E: Entity<V2>,
|
E: Entity<V2>,
|
||||||
|
Evt: 'static,
|
||||||
{
|
{
|
||||||
let view = self.view().downgrade();
|
let view = self.view().downgrade();
|
||||||
let entity_id = entity.entity_id();
|
let entity_id = entity.entity_id();
|
||||||
|
@ -1797,6 +1832,8 @@ impl<'a, V: 'static> ViewContext<'a, V> {
|
||||||
let window_handle = self.window.handle;
|
let window_handle = self.window.handle;
|
||||||
self.app.event_listeners.insert(
|
self.app.event_listeners.insert(
|
||||||
entity_id,
|
entity_id,
|
||||||
|
(
|
||||||
|
TypeId::of::<Evt>(),
|
||||||
Box::new(move |event, cx| {
|
Box::new(move |event, cx| {
|
||||||
window_handle
|
window_handle
|
||||||
.update(cx, |_, cx| {
|
.update(cx, |_, cx| {
|
||||||
|
@ -1810,6 +1847,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
|
||||||
})
|
})
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1880,6 +1918,110 @@ impl<'a, V: 'static> ViewContext<'a, V> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Register a listener to be called when the given focus handle receives focus.
|
||||||
|
/// Unlike [on_focus_changed], returns a subscription and persists until the subscription
|
||||||
|
/// is dropped.
|
||||||
|
pub fn on_focus(
|
||||||
|
&mut self,
|
||||||
|
handle: &FocusHandle,
|
||||||
|
mut listener: impl FnMut(&mut V, &mut ViewContext<V>) + 'static,
|
||||||
|
) -> Subscription {
|
||||||
|
let view = self.view.downgrade();
|
||||||
|
let focus_id = handle.id;
|
||||||
|
self.window.focus_listeners.insert(
|
||||||
|
(),
|
||||||
|
Box::new(move |event, cx| {
|
||||||
|
view.update(cx, |view, cx| {
|
||||||
|
if event.focused.as_ref().map(|focused| focused.id) == Some(focus_id) {
|
||||||
|
listener(view, cx)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.is_ok()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Register a listener to be called when the given focus handle or one of its descendants receives focus.
|
||||||
|
/// Unlike [on_focus_changed], returns a subscription and persists until the subscription
|
||||||
|
/// is dropped.
|
||||||
|
pub fn on_focus_in(
|
||||||
|
&mut self,
|
||||||
|
handle: &FocusHandle,
|
||||||
|
mut listener: impl FnMut(&mut V, &mut ViewContext<V>) + 'static,
|
||||||
|
) -> Subscription {
|
||||||
|
let view = self.view.downgrade();
|
||||||
|
let focus_id = handle.id;
|
||||||
|
self.window.focus_listeners.insert(
|
||||||
|
(),
|
||||||
|
Box::new(move |event, cx| {
|
||||||
|
view.update(cx, |view, cx| {
|
||||||
|
if event
|
||||||
|
.focused
|
||||||
|
.as_ref()
|
||||||
|
.map_or(false, |focused| focus_id.contains(focused.id, cx))
|
||||||
|
{
|
||||||
|
listener(view, cx)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.is_ok()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Register a listener to be called when the given focus handle loses focus.
|
||||||
|
/// Unlike [on_focus_changed], returns a subscription and persists until the subscription
|
||||||
|
/// is dropped.
|
||||||
|
pub fn on_blur(
|
||||||
|
&mut self,
|
||||||
|
handle: &FocusHandle,
|
||||||
|
mut listener: impl FnMut(&mut V, &mut ViewContext<V>) + 'static,
|
||||||
|
) -> Subscription {
|
||||||
|
let view = self.view.downgrade();
|
||||||
|
let focus_id = handle.id;
|
||||||
|
self.window.focus_listeners.insert(
|
||||||
|
(),
|
||||||
|
Box::new(move |event, cx| {
|
||||||
|
view.update(cx, |view, cx| {
|
||||||
|
if event.blurred.as_ref().map(|blurred| blurred.id) == Some(focus_id) {
|
||||||
|
listener(view, cx)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.is_ok()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Register a listener to be called when the given focus handle or one of its descendants loses focus.
|
||||||
|
/// Unlike [on_focus_changed], returns a subscription and persists until the subscription
|
||||||
|
/// is dropped.
|
||||||
|
pub fn on_focus_out(
|
||||||
|
&mut self,
|
||||||
|
handle: &FocusHandle,
|
||||||
|
mut listener: impl FnMut(&mut V, &mut ViewContext<V>) + 'static,
|
||||||
|
) -> Subscription {
|
||||||
|
let view = self.view.downgrade();
|
||||||
|
let focus_id = handle.id;
|
||||||
|
self.window.focus_listeners.insert(
|
||||||
|
(),
|
||||||
|
Box::new(move |event, cx| {
|
||||||
|
view.update(cx, |view, cx| {
|
||||||
|
if event
|
||||||
|
.blurred
|
||||||
|
.as_ref()
|
||||||
|
.map_or(false, |blurred| focus_id.contains(blurred.id, cx))
|
||||||
|
{
|
||||||
|
listener(view, cx)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.is_ok()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Register a focus listener for the current frame only. It will be cleared
|
||||||
|
/// on the next frame render. You should use this method only from within elements,
|
||||||
|
/// and we may want to enforce that better via a different context type.
|
||||||
|
// todo!() Move this to `FrameContext` to emphasize its individuality?
|
||||||
pub fn on_focus_changed(
|
pub fn on_focus_changed(
|
||||||
&mut self,
|
&mut self,
|
||||||
listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext<V>) + 'static,
|
listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext<V>) + 'static,
|
||||||
|
@ -2035,30 +2177,33 @@ impl<'a, V: 'static> ViewContext<'a, V> {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<V> ViewContext<'_, V>
|
/// Set an input handler, such as [ElementInputHandler], which interfaces with the
|
||||||
where
|
/// platform to receive textual input with proper integration with concerns such
|
||||||
V: InputHandler + 'static,
|
/// as IME interactions.
|
||||||
{
|
pub fn handle_input(
|
||||||
pub fn handle_text_input(&mut self) {
|
&mut self,
|
||||||
self.window.requested_input_handler = Some(Box::new(WindowInputHandler {
|
focus_handle: &FocusHandle,
|
||||||
cx: self.app.this.clone(),
|
input_handler: impl PlatformInputHandler,
|
||||||
window: self.window_handle(),
|
) {
|
||||||
handler: self.view().downgrade(),
|
if focus_handle.is_focused(self) {
|
||||||
}));
|
self.window
|
||||||
|
.platform_window
|
||||||
|
.set_input_handler(Box::new(input_handler));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V> ViewContext<'_, V>
|
impl<V> ViewContext<'_, V> {
|
||||||
where
|
pub fn emit<Evt>(&mut self, event: Evt)
|
||||||
V: EventEmitter,
|
where
|
||||||
V::Event: 'static,
|
Evt: 'static,
|
||||||
{
|
V: EventEmitter<Evt>,
|
||||||
pub fn emit(&mut self, event: V::Event) {
|
{
|
||||||
let emitter = self.view.model.entity_id;
|
let emitter = self.view.model.entity_id;
|
||||||
self.app.push_effect(Effect::Emit {
|
self.app.push_effect(Effect::Emit {
|
||||||
emitter,
|
emitter,
|
||||||
|
event_type: TypeId::of::<Evt>(),
|
||||||
event: Box::new(event),
|
event: Box::new(event),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2102,7 +2247,7 @@ impl<V> Context for ViewContext<'_, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: 'static> VisualContext for ViewContext<'_, V> {
|
impl<V: 'static> VisualContext for ViewContext<'_, V> {
|
||||||
fn build_view<W: 'static>(
|
fn build_view<W: Render + 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
build_view_state: impl FnOnce(&mut ViewContext<'_, W>) -> W,
|
build_view_state: impl FnOnce(&mut ViewContext<'_, W>) -> W,
|
||||||
) -> Self::Result<View<W>> {
|
) -> Self::Result<View<W>> {
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
use crate::{AnyWindowHandle, AppCell, Context, PlatformInputHandler, ViewContext, WeakView};
|
|
||||||
use std::{ops::Range, rc::Weak};
|
|
||||||
|
|
||||||
pub struct WindowInputHandler<V>
|
|
||||||
where
|
|
||||||
V: InputHandler,
|
|
||||||
{
|
|
||||||
pub cx: Weak<AppCell>,
|
|
||||||
pub window: AnyWindowHandle,
|
|
||||||
pub handler: WeakView<V>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<V: InputHandler + 'static> PlatformInputHandler for WindowInputHandler<V> {
|
|
||||||
fn selected_text_range(&self) -> Option<std::ops::Range<usize>> {
|
|
||||||
self.update(|view, cx| view.selected_text_range(cx))
|
|
||||||
.flatten()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn marked_text_range(&self) -> Option<std::ops::Range<usize>> {
|
|
||||||
self.update(|view, cx| view.marked_text_range(cx)).flatten()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn text_for_range(&self, range_utf16: std::ops::Range<usize>) -> Option<String> {
|
|
||||||
self.update(|view, cx| view.text_for_range(range_utf16, cx))
|
|
||||||
.flatten()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn replace_text_in_range(
|
|
||||||
&mut self,
|
|
||||||
replacement_range: Option<std::ops::Range<usize>>,
|
|
||||||
text: &str,
|
|
||||||
) {
|
|
||||||
self.update(|view, cx| view.replace_text_in_range(replacement_range, text, cx));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn replace_and_mark_text_in_range(
|
|
||||||
&mut self,
|
|
||||||
range_utf16: Option<std::ops::Range<usize>>,
|
|
||||||
new_text: &str,
|
|
||||||
new_selected_range: Option<std::ops::Range<usize>>,
|
|
||||||
) {
|
|
||||||
self.update(|view, cx| {
|
|
||||||
view.replace_and_mark_text_in_range(range_utf16, new_text, new_selected_range, cx)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unmark_text(&mut self) {
|
|
||||||
self.update(|view, cx| view.unmark_text(cx));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bounds_for_range(&self, range_utf16: std::ops::Range<usize>) -> Option<crate::Bounds<f32>> {
|
|
||||||
self.update(|view, cx| view.bounds_for_range(range_utf16, cx))
|
|
||||||
.flatten()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<V: InputHandler + 'static> WindowInputHandler<V> {
|
|
||||||
fn update<T>(&self, f: impl FnOnce(&mut V, &mut ViewContext<V>) -> T) -> Option<T> {
|
|
||||||
let cx = self.cx.upgrade()?;
|
|
||||||
let mut cx = cx.borrow_mut();
|
|
||||||
cx.update_window(self.window, |_, cx| self.handler.update(cx, f).ok())
|
|
||||||
.ok()?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait InputHandler: Sized {
|
|
||||||
fn text_for_range(&self, range: Range<usize>, cx: &mut ViewContext<Self>) -> Option<String>;
|
|
||||||
fn selected_text_range(&self, cx: &mut ViewContext<Self>) -> Option<Range<usize>>;
|
|
||||||
fn marked_text_range(&self, cx: &mut ViewContext<Self>) -> Option<Range<usize>>;
|
|
||||||
fn unmark_text(&mut self, cx: &mut ViewContext<Self>);
|
|
||||||
fn replace_text_in_range(
|
|
||||||
&mut self,
|
|
||||||
range: Option<Range<usize>>,
|
|
||||||
text: &str,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
);
|
|
||||||
fn replace_and_mark_text_in_range(
|
|
||||||
&mut self,
|
|
||||||
range: Option<Range<usize>>,
|
|
||||||
new_text: &str,
|
|
||||||
new_selected_range: Option<Range<usize>>,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
);
|
|
||||||
fn bounds_for_range(
|
|
||||||
&self,
|
|
||||||
range_utf16: std::ops::Range<usize>,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
) -> Option<crate::Bounds<f32>>;
|
|
||||||
}
|
|
|
@ -1815,9 +1815,7 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for Buffer {
|
impl EventEmitter<Event> for Buffer {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Buffer {
|
impl Deref for Buffer {
|
||||||
type Target = TextBuffer;
|
type Target = TextBuffer;
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
use gpui::actions;
|
use gpui::actions;
|
||||||
|
|
||||||
|
// todo!(remove this)
|
||||||
|
// https://github.com/rust-lang/rust/issues/47384
|
||||||
|
// https://github.com/mmastrac/rust-ctor/issues/280
|
||||||
|
pub fn unused() {}
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
Cancel,
|
Cancel,
|
||||||
Confirm,
|
Confirm,
|
||||||
|
|
|
@ -1872,9 +1872,7 @@ impl MultiBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for MultiBuffer {
|
impl EventEmitter<Event> for MultiBuffer {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MultiBufferSnapshot {
|
impl MultiBufferSnapshot {
|
||||||
pub fn text(&self) -> String {
|
pub fn text(&self) -> String {
|
||||||
|
|
|
@ -15,7 +15,6 @@ menu = { package = "menu2", path = "../menu2" }
|
||||||
settings = { package = "settings2", path = "../settings2" }
|
settings = { package = "settings2", path = "../settings2" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
theme = { package = "theme2", path = "../theme2" }
|
theme = { package = "theme2", path = "../theme2" }
|
||||||
workspace = { package = "workspace2", path = "../workspace2" }
|
|
||||||
|
|
||||||
parking_lot.workspace = true
|
parking_lot.workspace = true
|
||||||
|
|
||||||
|
@ -23,6 +22,5 @@ parking_lot.workspace = true
|
||||||
editor = { package = "editor2", path = "../editor2", features = ["test-support"] }
|
editor = { package = "editor2", path = "../editor2", features = ["test-support"] }
|
||||||
gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] }
|
gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] }
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
workspace = { package = "workspace2", path = "../workspace2", features = ["test-support"] }
|
|
||||||
ctor.workspace = true
|
ctor.workspace = true
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
|
|
|
@ -9062,9 +9062,7 @@ impl<'a> Iterator for PathMatchCandidateSetIter<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for Project {
|
impl EventEmitter<Event> for Project {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: AsRef<Path>> From<(WorktreeId, P)> for ProjectPath {
|
impl<P: AsRef<Path>> From<(WorktreeId, P)> for ProjectPath {
|
||||||
fn from((worktree_id, path): (WorktreeId, P)) -> Self {
|
fn from((worktree_id, path): (WorktreeId, P)) -> Self {
|
||||||
|
|
|
@ -281,9 +281,7 @@ pub enum Event {
|
||||||
UpdatedGitRepositories(UpdatedGitRepositoriesSet),
|
UpdatedGitRepositories(UpdatedGitRepositoriesSet),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for Worktree {
|
impl EventEmitter<Event> for Worktree {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Worktree {
|
impl Worktree {
|
||||||
pub async fn local(
|
pub async fn local(
|
||||||
|
|
21
crates/rope2/Cargo.toml
Normal file
21
crates/rope2/Cargo.toml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
[package]
|
||||||
|
name = "rope2"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/rope2.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bromberg_sl2 = { git = "https://github.com/zed-industries/bromberg_sl2", rev = "950bc5482c216c395049ae33ae4501e08975f17f" }
|
||||||
|
smallvec.workspace = true
|
||||||
|
sum_tree = { path = "../sum_tree" }
|
||||||
|
arrayvec = "0.7.1"
|
||||||
|
log.workspace = true
|
||||||
|
util = { path = "../util" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
rand.workspace = true
|
||||||
|
util = { path = "../util", features = ["test-support"] }
|
||||||
|
gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] }
|
50
crates/rope2/src/offset_utf16.rs
Normal file
50
crates/rope2/src/offset_utf16.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
use std::ops::{Add, AddAssign, Sub};
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
|
pub struct OffsetUtf16(pub usize);
|
||||||
|
|
||||||
|
impl<'a> Add<&'a Self> for OffsetUtf16 {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn add(self, other: &'a Self) -> Self::Output {
|
||||||
|
Self(self.0 + other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Add for OffsetUtf16 {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn add(self, other: Self) -> Self::Output {
|
||||||
|
Self(self.0 + other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Sub<&'a Self> for OffsetUtf16 {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn sub(self, other: &'a Self) -> Self::Output {
|
||||||
|
debug_assert!(*other <= self);
|
||||||
|
Self(self.0 - other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub for OffsetUtf16 {
|
||||||
|
type Output = OffsetUtf16;
|
||||||
|
|
||||||
|
fn sub(self, other: Self) -> Self::Output {
|
||||||
|
debug_assert!(other <= self);
|
||||||
|
Self(self.0 - other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AddAssign<&'a Self> for OffsetUtf16 {
|
||||||
|
fn add_assign(&mut self, other: &'a Self) {
|
||||||
|
self.0 += other.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AddAssign<Self> for OffsetUtf16 {
|
||||||
|
fn add_assign(&mut self, other: Self) {
|
||||||
|
self.0 += other.0;
|
||||||
|
}
|
||||||
|
}
|
128
crates/rope2/src/point.rs
Normal file
128
crates/rope2/src/point.rs
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
use std::{
|
||||||
|
cmp::Ordering,
|
||||||
|
ops::{Add, AddAssign, Sub},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash)]
|
||||||
|
pub struct Point {
|
||||||
|
pub row: u32,
|
||||||
|
pub column: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Point {
|
||||||
|
pub const MAX: Self = Self {
|
||||||
|
row: u32::MAX,
|
||||||
|
column: u32::MAX,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn new(row: u32, column: u32) -> Self {
|
||||||
|
Point { row, column }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn zero() -> Self {
|
||||||
|
Point::new(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_str(s: &str) -> Self {
|
||||||
|
let mut point = Self::zero();
|
||||||
|
for (row, line) in s.split('\n').enumerate() {
|
||||||
|
point.row = row as u32;
|
||||||
|
point.column = line.len() as u32;
|
||||||
|
}
|
||||||
|
point
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_zero(&self) -> bool {
|
||||||
|
self.row == 0 && self.column == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn saturating_sub(self, other: Self) -> Self {
|
||||||
|
if self < other {
|
||||||
|
Self::zero()
|
||||||
|
} else {
|
||||||
|
self - other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Add<&'a Self> for Point {
|
||||||
|
type Output = Point;
|
||||||
|
|
||||||
|
fn add(self, other: &'a Self) -> Self::Output {
|
||||||
|
self + *other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Add for Point {
|
||||||
|
type Output = Point;
|
||||||
|
|
||||||
|
fn add(self, other: Self) -> Self::Output {
|
||||||
|
if other.row == 0 {
|
||||||
|
Point::new(self.row, self.column + other.column)
|
||||||
|
} else {
|
||||||
|
Point::new(self.row + other.row, other.column)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Sub<&'a Self> for Point {
|
||||||
|
type Output = Point;
|
||||||
|
|
||||||
|
fn sub(self, other: &'a Self) -> Self::Output {
|
||||||
|
self - *other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub for Point {
|
||||||
|
type Output = Point;
|
||||||
|
|
||||||
|
fn sub(self, other: Self) -> Self::Output {
|
||||||
|
debug_assert!(other <= self);
|
||||||
|
|
||||||
|
if self.row == other.row {
|
||||||
|
Point::new(0, self.column - other.column)
|
||||||
|
} else {
|
||||||
|
Point::new(self.row - other.row, self.column)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AddAssign<&'a Self> for Point {
|
||||||
|
fn add_assign(&mut self, other: &'a Self) {
|
||||||
|
*self += *other;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AddAssign<Self> for Point {
|
||||||
|
fn add_assign(&mut self, other: Self) {
|
||||||
|
if other.row == 0 {
|
||||||
|
self.column += other.column;
|
||||||
|
} else {
|
||||||
|
self.row += other.row;
|
||||||
|
self.column = other.column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for Point {
|
||||||
|
fn partial_cmp(&self, other: &Point) -> Option<Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for Point {
|
||||||
|
#[cfg(target_pointer_width = "64")]
|
||||||
|
fn cmp(&self, other: &Point) -> Ordering {
|
||||||
|
let a = (self.row as usize) << 32 | self.column as usize;
|
||||||
|
let b = (other.row as usize) << 32 | other.column as usize;
|
||||||
|
a.cmp(&b)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_pointer_width = "32")]
|
||||||
|
fn cmp(&self, other: &Point) -> Ordering {
|
||||||
|
match self.row.cmp(&other.row) {
|
||||||
|
Ordering::Equal => self.column.cmp(&other.column),
|
||||||
|
comparison @ _ => comparison,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
119
crates/rope2/src/point_utf16.rs
Normal file
119
crates/rope2/src/point_utf16.rs
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
use std::{
|
||||||
|
cmp::Ordering,
|
||||||
|
ops::{Add, AddAssign, Sub},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash)]
|
||||||
|
pub struct PointUtf16 {
|
||||||
|
pub row: u32,
|
||||||
|
pub column: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PointUtf16 {
|
||||||
|
pub const MAX: Self = Self {
|
||||||
|
row: u32::MAX,
|
||||||
|
column: u32::MAX,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn new(row: u32, column: u32) -> Self {
|
||||||
|
PointUtf16 { row, column }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn zero() -> Self {
|
||||||
|
PointUtf16::new(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_zero(&self) -> bool {
|
||||||
|
self.row == 0 && self.column == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn saturating_sub(self, other: Self) -> Self {
|
||||||
|
if self < other {
|
||||||
|
Self::zero()
|
||||||
|
} else {
|
||||||
|
self - other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Add<&'a Self> for PointUtf16 {
|
||||||
|
type Output = PointUtf16;
|
||||||
|
|
||||||
|
fn add(self, other: &'a Self) -> Self::Output {
|
||||||
|
self + *other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Add for PointUtf16 {
|
||||||
|
type Output = PointUtf16;
|
||||||
|
|
||||||
|
fn add(self, other: Self) -> Self::Output {
|
||||||
|
if other.row == 0 {
|
||||||
|
PointUtf16::new(self.row, self.column + other.column)
|
||||||
|
} else {
|
||||||
|
PointUtf16::new(self.row + other.row, other.column)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Sub<&'a Self> for PointUtf16 {
|
||||||
|
type Output = PointUtf16;
|
||||||
|
|
||||||
|
fn sub(self, other: &'a Self) -> Self::Output {
|
||||||
|
self - *other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub for PointUtf16 {
|
||||||
|
type Output = PointUtf16;
|
||||||
|
|
||||||
|
fn sub(self, other: Self) -> Self::Output {
|
||||||
|
debug_assert!(other <= self);
|
||||||
|
|
||||||
|
if self.row == other.row {
|
||||||
|
PointUtf16::new(0, self.column - other.column)
|
||||||
|
} else {
|
||||||
|
PointUtf16::new(self.row - other.row, self.column)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AddAssign<&'a Self> for PointUtf16 {
|
||||||
|
fn add_assign(&mut self, other: &'a Self) {
|
||||||
|
*self += *other;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AddAssign<Self> for PointUtf16 {
|
||||||
|
fn add_assign(&mut self, other: Self) {
|
||||||
|
if other.row == 0 {
|
||||||
|
self.column += other.column;
|
||||||
|
} else {
|
||||||
|
self.row += other.row;
|
||||||
|
self.column = other.column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for PointUtf16 {
|
||||||
|
fn partial_cmp(&self, other: &PointUtf16) -> Option<Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for PointUtf16 {
|
||||||
|
#[cfg(target_pointer_width = "64")]
|
||||||
|
fn cmp(&self, other: &PointUtf16) -> Ordering {
|
||||||
|
let a = (self.row as usize) << 32 | self.column as usize;
|
||||||
|
let b = (other.row as usize) << 32 | other.column as usize;
|
||||||
|
a.cmp(&b)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_pointer_width = "32")]
|
||||||
|
fn cmp(&self, other: &PointUtf16) -> Ordering {
|
||||||
|
match self.row.cmp(&other.row) {
|
||||||
|
Ordering::Equal => self.column.cmp(&other.column),
|
||||||
|
comparison @ _ => comparison,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1433
crates/rope2/src/rope2.rs
Normal file
1433
crates/rope2/src/rope2.rs
Normal file
File diff suppressed because it is too large
Load diff
57
crates/rope2/src/unclipped.rs
Normal file
57
crates/rope2/src/unclipped.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
use crate::{ChunkSummary, TextDimension, TextSummary};
|
||||||
|
use std::ops::{Add, AddAssign, Sub, SubAssign};
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
pub struct Unclipped<T>(pub T);
|
||||||
|
|
||||||
|
impl<T> From<T> for Unclipped<T> {
|
||||||
|
fn from(value: T) -> Self {
|
||||||
|
Unclipped(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T: sum_tree::Dimension<'a, ChunkSummary>> sum_tree::Dimension<'a, ChunkSummary>
|
||||||
|
for Unclipped<T>
|
||||||
|
{
|
||||||
|
fn add_summary(&mut self, summary: &'a ChunkSummary, _: &()) {
|
||||||
|
self.0.add_summary(summary, &());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: TextDimension> TextDimension for Unclipped<T> {
|
||||||
|
fn from_text_summary(summary: &TextSummary) -> Self {
|
||||||
|
Unclipped(T::from_text_summary(summary))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_assign(&mut self, other: &Self) {
|
||||||
|
TextDimension::add_assign(&mut self.0, &other.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Add<T, Output = T>> Add<Unclipped<T>> for Unclipped<T> {
|
||||||
|
type Output = Unclipped<T>;
|
||||||
|
|
||||||
|
fn add(self, rhs: Unclipped<T>) -> Self::Output {
|
||||||
|
Unclipped(self.0 + rhs.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Sub<T, Output = T>> Sub<Unclipped<T>> for Unclipped<T> {
|
||||||
|
type Output = Unclipped<T>;
|
||||||
|
|
||||||
|
fn sub(self, rhs: Unclipped<T>) -> Self::Output {
|
||||||
|
Unclipped(self.0 - rhs.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: AddAssign<T>> AddAssign<Unclipped<T>> for Unclipped<T> {
|
||||||
|
fn add_assign(&mut self, rhs: Unclipped<T>) {
|
||||||
|
self.0 += rhs.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: SubAssign<T>> SubAssign<Unclipped<T>> for Unclipped<T> {
|
||||||
|
fn sub_assign(&mut self, rhs: Unclipped<T>) {
|
||||||
|
self.0 -= rhs.0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1351,9 +1351,7 @@ impl Drop for Terminal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for Terminal {
|
impl EventEmitter<Event> for Terminal {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Based on alacritty/src/display/hint.rs > regex_match_at
|
/// Based on alacritty/src/display/hint.rs > regex_match_at
|
||||||
/// Retrieve the match, if the specified point is inside the content matching the regex.
|
/// Retrieve the match, if the specified point is inside the content matching the regex.
|
||||||
|
|
|
@ -14,7 +14,7 @@ test-support = ["rand"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clock = { path = "../clock" }
|
clock = { path = "../clock" }
|
||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
rope = { path = "../rope" }
|
rope = { package = "rope2", path = "../rope2" }
|
||||||
sum_tree = { path = "../sum_tree" }
|
sum_tree = { path = "../sum_tree" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl Theme {
|
||||||
&self.styles.system
|
&self.styles.system
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the [`ThemeColors`] for the theme.
|
/// Returns the [`PlayerColors`] for the theme.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn players(&self) -> &PlayerColors {
|
pub fn players(&self) -> &PlayerColors {
|
||||||
&self.styles.player
|
&self.styles.player
|
||||||
|
|
|
@ -3,6 +3,7 @@ mod button;
|
||||||
mod checkbox;
|
mod checkbox;
|
||||||
mod context_menu;
|
mod context_menu;
|
||||||
mod details;
|
mod details;
|
||||||
|
mod elevated_surface;
|
||||||
mod facepile;
|
mod facepile;
|
||||||
mod icon;
|
mod icon;
|
||||||
mod icon_button;
|
mod icon_button;
|
||||||
|
@ -30,6 +31,7 @@ pub use button::*;
|
||||||
pub use checkbox::*;
|
pub use checkbox::*;
|
||||||
pub use context_menu::*;
|
pub use context_menu::*;
|
||||||
pub use details::*;
|
pub use details::*;
|
||||||
|
pub use elevated_surface::*;
|
||||||
pub use facepile::*;
|
pub use facepile::*;
|
||||||
pub use icon::*;
|
pub use icon::*;
|
||||||
pub use icon_button::*;
|
pub use icon_button::*;
|
||||||
|
|
28
crates/ui2/src/components/elevated_surface.rs
Normal file
28
crates/ui2/src/components/elevated_surface.rs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
use gpui::Div;
|
||||||
|
|
||||||
|
use crate::{prelude::*, v_stack};
|
||||||
|
|
||||||
|
/// Create an elevated surface.
|
||||||
|
///
|
||||||
|
/// Must be used inside of a relative parent element
|
||||||
|
pub fn elevated_surface<V: 'static>(level: ElevationIndex, cx: &mut ViewContext<V>) -> Div<V> {
|
||||||
|
let colors = cx.theme().colors();
|
||||||
|
|
||||||
|
// let shadow = BoxShadow {
|
||||||
|
// color: hsla(0., 0., 0., 0.1),
|
||||||
|
// offset: point(px(0.), px(1.)),
|
||||||
|
// blur_radius: px(3.),
|
||||||
|
// spread_radius: px(0.),
|
||||||
|
// };
|
||||||
|
|
||||||
|
v_stack()
|
||||||
|
.rounded_lg()
|
||||||
|
.bg(colors.elevated_surface_background)
|
||||||
|
.border()
|
||||||
|
.border_color(colors.border)
|
||||||
|
.shadow(level.shadow())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn modal<V>(cx: &mut ViewContext<V>) -> Div<V> {
|
||||||
|
elevated_surface(ElevationIndex::ModalSurfaces, cx)
|
||||||
|
}
|
|
@ -1,3 +1,6 @@
|
||||||
|
use gpui::{hsla, point, px, BoxShadow};
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
|
||||||
#[doc = include_str!("elevation.md")]
|
#[doc = include_str!("elevation.md")]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Elevation {
|
pub enum Elevation {
|
||||||
|
@ -17,8 +20,8 @@ pub enum ElevationIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ElevationIndex {
|
impl ElevationIndex {
|
||||||
pub fn usize(&self) -> usize {
|
pub fn z_index(self) -> u32 {
|
||||||
match *self {
|
match self {
|
||||||
ElevationIndex::AppBackground => 0,
|
ElevationIndex::AppBackground => 0,
|
||||||
ElevationIndex::UISurface => 100,
|
ElevationIndex::UISurface => 100,
|
||||||
ElevationIndex::ElevatedSurface => 200,
|
ElevationIndex::ElevatedSurface => 200,
|
||||||
|
@ -27,6 +30,26 @@ impl ElevationIndex {
|
||||||
ElevationIndex::DraggedElement => 900,
|
ElevationIndex::DraggedElement => 900,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn shadow(self) -> SmallVec<[BoxShadow; 2]> {
|
||||||
|
match self {
|
||||||
|
ElevationIndex::AppBackground => smallvec![],
|
||||||
|
|
||||||
|
ElevationIndex::UISurface => smallvec![BoxShadow {
|
||||||
|
color: hsla(0., 0., 0., 0.12),
|
||||||
|
offset: point(px(0.), px(1.)),
|
||||||
|
blur_radius: px(3.),
|
||||||
|
spread_radius: px(0.),
|
||||||
|
}],
|
||||||
|
|
||||||
|
_ => smallvec![BoxShadow {
|
||||||
|
color: hsla(0., 0., 0., 0.32),
|
||||||
|
offset: point(px(1.), px(3.)),
|
||||||
|
blur_radius: px(12.),
|
||||||
|
spread_radius: px(0.),
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
|
|
@ -7,7 +7,16 @@ use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub trait Panel: Render + EventEmitter {
|
pub enum PanelEvent {
|
||||||
|
ChangePosition,
|
||||||
|
ZoomIn,
|
||||||
|
ZoomOut,
|
||||||
|
Activate,
|
||||||
|
Close,
|
||||||
|
Focus,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Panel: Render + EventEmitter<PanelEvent> {
|
||||||
fn persistent_name(&self) -> &'static str;
|
fn persistent_name(&self) -> &'static str;
|
||||||
fn position(&self, cx: &WindowContext) -> DockPosition;
|
fn position(&self, cx: &WindowContext) -> DockPosition;
|
||||||
fn position_is_valid(&self, position: DockPosition) -> bool;
|
fn position_is_valid(&self, position: DockPosition) -> bool;
|
||||||
|
@ -19,26 +28,12 @@ pub trait Panel: Render + EventEmitter {
|
||||||
fn icon_label(&self, _: &WindowContext) -> Option<String> {
|
fn icon_label(&self, _: &WindowContext) -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn should_change_position_on_event(_: &Self::Event) -> bool;
|
|
||||||
fn should_zoom_in_on_event(_: &Self::Event) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
fn should_zoom_out_on_event(_: &Self::Event) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
fn is_zoomed(&self, _cx: &WindowContext) -> bool {
|
fn is_zoomed(&self, _cx: &WindowContext) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {}
|
fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {}
|
||||||
fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {}
|
fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {}
|
||||||
fn should_activate_on_event(_: &Self::Event) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
fn should_close_on_event(_: &Self::Event) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
fn has_focus(&self, cx: &WindowContext) -> bool;
|
fn has_focus(&self, cx: &WindowContext) -> bool;
|
||||||
fn is_focus_event(_: &Self::Event) -> bool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PanelHandle: Send + Sync {
|
pub trait PanelHandle: Send + Sync {
|
||||||
|
@ -268,7 +263,20 @@ impl Dock {
|
||||||
let subscriptions = [
|
let subscriptions = [
|
||||||
cx.observe(&panel, |_, _, cx| cx.notify()),
|
cx.observe(&panel, |_, _, cx| cx.notify()),
|
||||||
cx.subscribe(&panel, |this, panel, event, cx| {
|
cx.subscribe(&panel, |this, panel, event, cx| {
|
||||||
if T::should_activate_on_event(event) {
|
match event {
|
||||||
|
PanelEvent::ChangePosition => {
|
||||||
|
//todo!()
|
||||||
|
// see: Workspace::add_panel_with_extra_event_handler
|
||||||
|
}
|
||||||
|
PanelEvent::ZoomIn => {
|
||||||
|
//todo!()
|
||||||
|
// see: Workspace::add_panel_with_extra_event_handler
|
||||||
|
}
|
||||||
|
PanelEvent::ZoomOut => {
|
||||||
|
// todo!()
|
||||||
|
// // see: Workspace::add_panel_with_extra_event_handler
|
||||||
|
}
|
||||||
|
PanelEvent::Activate => {
|
||||||
if let Some(ix) = this
|
if let Some(ix) = this
|
||||||
.panel_entries
|
.panel_entries
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -276,14 +284,17 @@ impl Dock {
|
||||||
{
|
{
|
||||||
this.set_open(true, cx);
|
this.set_open(true, cx);
|
||||||
this.activate_panel(ix, cx);
|
this.activate_panel(ix, cx);
|
||||||
// todo!()
|
//` todo!()
|
||||||
// cx.focus(&panel);
|
// cx.focus(&panel);
|
||||||
}
|
}
|
||||||
} else if T::should_close_on_event(event)
|
}
|
||||||
&& this.visible_panel().map_or(false, |p| p.id() == panel.id())
|
PanelEvent::Close => {
|
||||||
{
|
if this.visible_panel().map_or(false, |p| p.id() == panel.id()) {
|
||||||
this.set_open(false, cx);
|
this.set_open(false, cx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
PanelEvent::Focus => todo!(),
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -407,6 +418,14 @@ impl Dock {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Render for Dock {
|
||||||
|
type Element = Div<Self>;
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// todo!()
|
// todo!()
|
||||||
// impl View for Dock {
|
// impl View for Dock {
|
||||||
// fn ui_name() -> &'static str {
|
// fn ui_name() -> &'static str {
|
||||||
|
@ -452,10 +471,6 @@ impl PanelButtons {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for PanelButtons {
|
|
||||||
type Event = ();
|
|
||||||
}
|
|
||||||
|
|
||||||
// impl Render for PanelButtons {
|
// impl Render for PanelButtons {
|
||||||
// type Element = ();
|
// type Element = ();
|
||||||
|
|
||||||
|
@ -625,7 +640,7 @@ impl StatusItemView for PanelButtons {
|
||||||
_active_pane_item: Option<&dyn crate::ItemHandle>,
|
_active_pane_item: Option<&dyn crate::ItemHandle>,
|
||||||
_cx: &mut ViewContext<Self>,
|
_cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
// todo!(This is empty in the old `workspace::dock`)
|
// Nothing to do, panel buttons don't depend on the active center item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,16 +649,6 @@ pub mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use gpui::{div, Div, ViewContext, WindowContext};
|
use gpui::{div, Div, ViewContext, WindowContext};
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum TestPanelEvent {
|
|
||||||
PositionChanged,
|
|
||||||
Activated,
|
|
||||||
Closed,
|
|
||||||
ZoomIn,
|
|
||||||
ZoomOut,
|
|
||||||
Focus,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TestPanel {
|
pub struct TestPanel {
|
||||||
pub position: DockPosition,
|
pub position: DockPosition,
|
||||||
pub zoomed: bool,
|
pub zoomed: bool,
|
||||||
|
@ -652,9 +657,7 @@ pub mod test {
|
||||||
pub size: f32,
|
pub size: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for TestPanel {
|
impl EventEmitter<PanelEvent> for TestPanel {}
|
||||||
type Event = TestPanelEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TestPanel {
|
impl TestPanel {
|
||||||
pub fn new(position: DockPosition) -> Self {
|
pub fn new(position: DockPosition) -> Self {
|
||||||
|
@ -691,7 +694,7 @@ pub mod test {
|
||||||
|
|
||||||
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
|
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
|
||||||
self.position = position;
|
self.position = position;
|
||||||
cx.emit(TestPanelEvent::PositionChanged);
|
cx.emit(PanelEvent::ChangePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size(&self, _: &WindowContext) -> f32 {
|
fn size(&self, _: &WindowContext) -> f32 {
|
||||||
|
@ -710,18 +713,6 @@ pub mod test {
|
||||||
("Test Panel".into(), None)
|
("Test Panel".into(), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_change_position_on_event(event: &Self::Event) -> bool {
|
|
||||||
matches!(event, TestPanelEvent::PositionChanged)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn should_zoom_in_on_event(event: &Self::Event) -> bool {
|
|
||||||
matches!(event, TestPanelEvent::ZoomIn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn should_zoom_out_on_event(event: &Self::Event) -> bool {
|
|
||||||
matches!(event, TestPanelEvent::ZoomOut)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_zoomed(&self, _: &WindowContext) -> bool {
|
fn is_zoomed(&self, _: &WindowContext) -> bool {
|
||||||
self.zoomed
|
self.zoomed
|
||||||
}
|
}
|
||||||
|
@ -734,20 +725,8 @@ pub mod test {
|
||||||
self.active = active;
|
self.active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_activate_on_event(event: &Self::Event) -> bool {
|
|
||||||
matches!(event, TestPanelEvent::Activated)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn should_close_on_event(event: &Self::Event) -> bool {
|
|
||||||
matches!(event, TestPanelEvent::Closed)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn has_focus(&self, _cx: &WindowContext) -> bool {
|
fn has_focus(&self, _cx: &WindowContext) -> bool {
|
||||||
self.has_focus
|
self.has_focus
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_focus_event(event: &Self::Event) -> bool {
|
|
||||||
matches!(event, TestPanelEvent::Focus)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ pub struct BreadcrumbText {
|
||||||
pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
|
pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Item: Render + EventEmitter {
|
pub trait Item: Render + EventEmitter<ItemEvent> {
|
||||||
fn focus_handle(&self) -> FocusHandle;
|
fn focus_handle(&self) -> FocusHandle;
|
||||||
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
||||||
fn workspace_deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
fn workspace_deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
||||||
|
@ -106,12 +106,13 @@ pub trait Item: Render + EventEmitter {
|
||||||
}
|
}
|
||||||
fn tab_content<V: 'static>(&self, detail: Option<usize>, cx: &AppContext) -> AnyElement<V>;
|
fn tab_content<V: 'static>(&self, detail: Option<usize>, cx: &AppContext) -> AnyElement<V>;
|
||||||
|
|
||||||
|
/// (model id, Item)
|
||||||
fn for_each_project_item(
|
fn for_each_project_item(
|
||||||
&self,
|
&self,
|
||||||
_: &AppContext,
|
_: &AppContext,
|
||||||
_: &mut dyn FnMut(EntityId, &dyn project2::Item),
|
_: &mut dyn FnMut(EntityId, &dyn project2::Item),
|
||||||
) {
|
) {
|
||||||
} // (model id, Item)
|
}
|
||||||
fn is_singleton(&self, _cx: &AppContext) -> bool {
|
fn is_singleton(&self, _cx: &AppContext) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -153,15 +154,6 @@ pub trait Item: Render + EventEmitter {
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
unimplemented!("reload() must be implemented if can_save() returns true")
|
unimplemented!("reload() must be implemented if can_save() returns true")
|
||||||
}
|
}
|
||||||
fn to_item_events(_event: &Self::Event) -> SmallVec<[ItemEvent; 2]> {
|
|
||||||
SmallVec::new()
|
|
||||||
}
|
|
||||||
fn should_close_item_on_event(_: &Self::Event) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
fn should_update_tab_on_event(_: &Self::Event) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn act_as_type<'a>(
|
fn act_as_type<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
|
@ -218,7 +210,7 @@ pub trait ItemHandle: 'static + Send {
|
||||||
fn subscribe_to_item_events(
|
fn subscribe_to_item_events(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
handler: Box<dyn Fn(ItemEvent, &mut WindowContext) + Send>,
|
handler: Box<dyn Fn(&ItemEvent, &mut WindowContext) + Send>,
|
||||||
) -> gpui::Subscription;
|
) -> gpui::Subscription;
|
||||||
fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString>;
|
fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString>;
|
||||||
fn tab_description(&self, detail: usize, cx: &AppContext) -> Option<SharedString>;
|
fn tab_description(&self, detail: usize, cx: &AppContext) -> Option<SharedString>;
|
||||||
|
@ -300,12 +292,10 @@ impl<T: Item> ItemHandle for View<T> {
|
||||||
fn subscribe_to_item_events(
|
fn subscribe_to_item_events(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
handler: Box<dyn Fn(ItemEvent, &mut WindowContext) + Send>,
|
handler: Box<dyn Fn(&ItemEvent, &mut WindowContext) + Send>,
|
||||||
) -> gpui::Subscription {
|
) -> gpui::Subscription {
|
||||||
cx.subscribe(self, move |_, event, cx| {
|
cx.subscribe(self, move |_, event, cx| {
|
||||||
for item_event in T::to_item_events(event) {
|
handler(event, cx);
|
||||||
handler(item_event, cx)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,7 +423,10 @@ impl<T: Item> ItemHandle for View<T> {
|
||||||
let is_project_item = item.is_project_item(cx);
|
let is_project_item = item.is_project_item(cx);
|
||||||
let leader_id = workspace.leader_for_pane(&pane);
|
let leader_id = workspace.leader_for_pane(&pane);
|
||||||
|
|
||||||
if leader_id.is_some() && item.should_unfollow_on_event(event, cx) {
|
let follow_event = item.to_follow_event(event);
|
||||||
|
if leader_id.is_some()
|
||||||
|
&& matches!(follow_event, Some(FollowEvent::Unfollow))
|
||||||
|
{
|
||||||
workspace.unfollow(&pane, cx);
|
workspace.unfollow(&pane, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,8 +460,7 @@ impl<T: Item> ItemHandle for View<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for item_event in T::to_item_events(event).into_iter() {
|
match event {
|
||||||
match item_event {
|
|
||||||
ItemEvent::CloseItem => {
|
ItemEvent::CloseItem => {
|
||||||
pane.update(cx, |pane, cx| {
|
pane.update(cx, |pane, cx| {
|
||||||
pane.close_item_by_id(item.id(), crate::SaveIntent::Close, cx)
|
pane.close_item_by_id(item.id(), crate::SaveIntent::Close, cx)
|
||||||
|
@ -497,7 +489,6 @@ impl<T: Item> ItemHandle for View<T> {
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// todo!()
|
// todo!()
|
||||||
|
@ -660,7 +651,16 @@ pub trait ProjectItem: Item {
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum FollowEvent {
|
||||||
|
Unfollow,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FollowableEvents {
|
||||||
|
fn to_follow_event(&self) -> Option<FollowEvent>;
|
||||||
|
}
|
||||||
|
|
||||||
pub trait FollowableItem: Item {
|
pub trait FollowableItem: Item {
|
||||||
|
type FollowableEvent: FollowableEvents;
|
||||||
fn remote_id(&self) -> Option<ViewId>;
|
fn remote_id(&self) -> Option<ViewId>;
|
||||||
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
|
fn to_state_proto(&self, cx: &AppContext) -> Option<proto::view::Variant>;
|
||||||
fn from_state_proto(
|
fn from_state_proto(
|
||||||
|
@ -672,7 +672,7 @@ pub trait FollowableItem: Item {
|
||||||
) -> Option<Task<Result<View<Self>>>>;
|
) -> Option<Task<Result<View<Self>>>>;
|
||||||
fn add_event_to_update_proto(
|
fn add_event_to_update_proto(
|
||||||
&self,
|
&self,
|
||||||
event: &Self::Event,
|
event: &Self::FollowableEvent,
|
||||||
update: &mut Option<proto::update_view::Variant>,
|
update: &mut Option<proto::update_view::Variant>,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
@ -685,7 +685,6 @@ pub trait FollowableItem: Item {
|
||||||
fn is_project_item(&self, cx: &AppContext) -> bool;
|
fn is_project_item(&self, cx: &AppContext) -> bool;
|
||||||
|
|
||||||
fn set_leader_peer_id(&mut self, leader_peer_id: Option<PeerId>, cx: &mut ViewContext<Self>);
|
fn set_leader_peer_id(&mut self, leader_peer_id: Option<PeerId>, cx: &mut ViewContext<Self>);
|
||||||
fn should_unfollow_on_event(event: &Self::Event, cx: &AppContext) -> bool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FollowableItemHandle: ItemHandle {
|
pub trait FollowableItemHandle: ItemHandle {
|
||||||
|
@ -698,13 +697,13 @@ pub trait FollowableItemHandle: ItemHandle {
|
||||||
update: &mut Option<proto::update_view::Variant>,
|
update: &mut Option<proto::update_view::Variant>,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
fn to_follow_event(&self, event: &dyn Any) -> Option<FollowEvent>;
|
||||||
fn apply_update_proto(
|
fn apply_update_proto(
|
||||||
&self,
|
&self,
|
||||||
project: &Model<Project>,
|
project: &Model<Project>,
|
||||||
message: proto::update_view::Variant,
|
message: proto::update_view::Variant,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
) -> Task<Result<()>>;
|
) -> Task<Result<()>>;
|
||||||
fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool;
|
|
||||||
fn is_project_item(&self, cx: &AppContext) -> bool;
|
fn is_project_item(&self, cx: &AppContext) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -739,6 +738,13 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_follow_event(&self, event: &dyn Any) -> Option<FollowEvent> {
|
||||||
|
event
|
||||||
|
.downcast_ref()
|
||||||
|
.map(T::FollowableEvent::to_follow_event)
|
||||||
|
.flatten()
|
||||||
|
}
|
||||||
|
|
||||||
fn apply_update_proto(
|
fn apply_update_proto(
|
||||||
&self,
|
&self,
|
||||||
project: &Model<Project>,
|
project: &Model<Project>,
|
||||||
|
@ -748,14 +754,6 @@ impl<T: FollowableItem> FollowableItemHandle for View<T> {
|
||||||
self.update(cx, |this, cx| this.apply_update_proto(project, message, cx))
|
self.update(cx, |this, cx| this.apply_update_proto(project, message, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_unfollow_on_event(&self, event: &dyn Any, cx: &AppContext) -> bool {
|
|
||||||
if let Some(event) = event.downcast_ref() {
|
|
||||||
T::should_unfollow_on_event(event, cx)
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_project_item(&self, cx: &AppContext) -> bool {
|
fn is_project_item(&self, cx: &AppContext) -> bool {
|
||||||
self.read(cx).is_project_item(cx)
|
self.read(cx).is_project_item(cx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +1,34 @@
|
||||||
use crate::Workspace;
|
use crate::Workspace;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, AnyView, AppContext, Div, ParentElement, Render, StatelessInteractive, View, ViewContext,
|
div, px, AnyView, Component, Div, EventEmitter, ParentElement, Render, StatelessInteractive,
|
||||||
|
Styled, Subscription, View, ViewContext,
|
||||||
};
|
};
|
||||||
use std::{any::TypeId, sync::Arc};
|
use std::{any::TypeId, sync::Arc};
|
||||||
|
use ui::v_stack;
|
||||||
|
|
||||||
pub struct ModalRegistry {
|
pub struct ModalLayer {
|
||||||
|
open_modal: Option<AnyView>,
|
||||||
|
subscription: Option<Subscription>,
|
||||||
registered_modals: Vec<(TypeId, Box<dyn Fn(Div<Workspace>) -> Div<Workspace>>)>,
|
registered_modals: Vec<(TypeId, Box<dyn Fn(Div<Workspace>) -> Div<Workspace>>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Modal {}
|
pub enum ModalEvent {
|
||||||
|
Dismissed,
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ModalLayer {
|
|
||||||
open_modal: Option<AnyView>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_modal_registry(cx: &mut AppContext) {
|
impl ModalLayer {
|
||||||
cx.set_global(ModalRegistry {
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
open_modal: None,
|
||||||
|
subscription: None,
|
||||||
registered_modals: Vec::new(),
|
registered_modals: Vec::new(),
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ToggleModal {
|
|
||||||
name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ModalRegistry {
|
|
||||||
pub fn register_modal<A: 'static, V, B>(&mut self, action: A, build_view: B)
|
pub fn register_modal<A: 'static, V, B>(&mut self, action: A, build_view: B)
|
||||||
where
|
where
|
||||||
V: Render,
|
V: EventEmitter<ModalEvent> + Render,
|
||||||
B: Fn(&Workspace, &mut ViewContext<Workspace>) -> View<V> + 'static,
|
B: Fn(&mut Workspace, &mut ViewContext<Workspace>) -> Option<View<V>> + 'static,
|
||||||
{
|
{
|
||||||
let build_view = Arc::new(build_view);
|
let build_view = Arc::new(build_view);
|
||||||
|
|
||||||
|
@ -38,42 +37,56 @@ impl ModalRegistry {
|
||||||
Box::new(move |mut div| {
|
Box::new(move |mut div| {
|
||||||
let build_view = build_view.clone();
|
let build_view = build_view.clone();
|
||||||
|
|
||||||
div.on_action(
|
div.on_action(move |workspace, event: &A, cx| {
|
||||||
move |workspace: &mut Workspace, event: &A, cx: &mut ViewContext<Workspace>| {
|
let Some(new_modal) = (build_view)(workspace, cx) else {
|
||||||
let new_modal = (build_view)(workspace, cx);
|
return;
|
||||||
workspace.modal_layer.update(cx, |modal_layer, _| {
|
};
|
||||||
modal_layer.open_modal = Some(new_modal.into());
|
workspace.modal_layer().show_modal(new_modal, cx);
|
||||||
});
|
})
|
||||||
|
|
||||||
cx.notify();
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl ModalLayer {
|
pub fn show_modal<V>(&mut self, new_modal: View<V>, cx: &mut ViewContext<Workspace>)
|
||||||
pub fn new() -> Self {
|
where
|
||||||
Self { open_modal: None }
|
V: EventEmitter<ModalEvent> + Render,
|
||||||
|
{
|
||||||
|
self.subscription = Some(cx.subscribe(&new_modal, |this, modal, e, cx| match e {
|
||||||
|
ModalEvent::Dismissed => this.modal_layer().hide_modal(cx),
|
||||||
|
}));
|
||||||
|
self.open_modal = Some(new_modal.into());
|
||||||
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&self, workspace: &Workspace, cx: &ViewContext<Workspace>) -> Div<Workspace> {
|
pub fn hide_modal(&mut self, cx: &mut ViewContext<Workspace>) {
|
||||||
let mut div = div();
|
self.open_modal.take();
|
||||||
|
self.subscription.take();
|
||||||
// div, c workspace.toggle_modal()div.on_action()) {
|
cx.notify();
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
// for (type_id, action) in cx.global::<ModalRegistry>().registered_modals.iter() {
|
|
||||||
// div = div.useful_on_action(*type_id, action)
|
|
||||||
// }
|
|
||||||
|
|
||||||
for (_, action) in cx.global::<ModalRegistry>().registered_modals.iter() {
|
|
||||||
div = (action)(div);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
div.children(self.open_modal.clone())
|
pub fn wrapper_element(&self, cx: &ViewContext<Workspace>) -> Div<Workspace> {
|
||||||
|
let mut parent = div().relative().size_full();
|
||||||
|
|
||||||
|
for (_, action) in self.registered_modals.iter() {
|
||||||
|
parent = (action)(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
parent.when_some(self.open_modal.as_ref(), |parent, open_modal| {
|
||||||
|
let container1 = div()
|
||||||
|
.absolute()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.items_center()
|
||||||
|
.size_full()
|
||||||
|
.top_0()
|
||||||
|
.left_0()
|
||||||
|
.z_index(400);
|
||||||
|
|
||||||
|
// transparent layer
|
||||||
|
let container2 = v_stack().h(px(0.0)).relative().top_20();
|
||||||
|
|
||||||
|
parent.child(container1.child(container2.child(open_modal.clone())))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,12 @@ pub fn init(cx: &mut AppContext) {
|
||||||
// simple_message_notification::init(cx);
|
// simple_message_notification::init(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Notification: EventEmitter + Render {
|
pub enum NotificationEvent {
|
||||||
fn should_dismiss_notification_on_event(&self, event: &Self::Event) -> bool;
|
Dismiss,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Notification: EventEmitter<NotificationEvent> + Render {}
|
||||||
|
|
||||||
pub trait NotificationHandle: Send {
|
pub trait NotificationHandle: Send {
|
||||||
fn id(&self) -> EntityId;
|
fn id(&self) -> EntityId;
|
||||||
fn to_any(&self) -> AnyView;
|
fn to_any(&self) -> AnyView;
|
||||||
|
@ -101,11 +103,14 @@ impl Workspace {
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
let notification = build_notification(cx);
|
let notification = build_notification(cx);
|
||||||
cx.subscribe(¬ification, move |this, handle, event, cx| {
|
cx.subscribe(
|
||||||
if handle.read(cx).should_dismiss_notification_on_event(event) {
|
¬ification,
|
||||||
|
move |this, handle, event: &NotificationEvent, cx| match event {
|
||||||
|
NotificationEvent::Dismiss => {
|
||||||
this.dismiss_notification_internal(type_id, id, cx);
|
this.dismiss_notification_internal(type_id, id, cx);
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
|
)
|
||||||
.detach();
|
.detach();
|
||||||
self.notifications
|
self.notifications
|
||||||
.push((type_id, id, Box::new(notification)));
|
.push((type_id, id, Box::new(notification)));
|
||||||
|
@ -159,7 +164,7 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod simple_message_notification {
|
pub mod simple_message_notification {
|
||||||
use super::Notification;
|
use super::{Notification, NotificationEvent};
|
||||||
use gpui::{AnyElement, AppContext, Div, EventEmitter, Render, TextStyle, ViewContext};
|
use gpui::{AnyElement, AppContext, Div, EventEmitter, Render, TextStyle, ViewContext};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{borrow::Cow, sync::Arc};
|
use std::{borrow::Cow, sync::Arc};
|
||||||
|
@ -200,13 +205,7 @@ pub mod simple_message_notification {
|
||||||
click_message: Option<Cow<'static, str>>,
|
click_message: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum MessageNotificationEvent {
|
impl EventEmitter<NotificationMessage> for MessageNotification {}
|
||||||
Dismiss,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventEmitter for MessageNotification {
|
|
||||||
type Event = MessageNotificationEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MessageNotification {
|
impl MessageNotification {
|
||||||
pub fn new<S>(message: S) -> MessageNotification
|
pub fn new<S>(message: S) -> MessageNotification
|
||||||
|
@ -359,13 +358,8 @@ pub mod simple_message_notification {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
impl Notification for MessageNotification {
|
impl EventEmitter<NotificationEvent> for MessageNotification {}
|
||||||
fn should_dismiss_notification_on_event(&self, event: &Self::Event) -> bool {
|
impl Notification for MessageNotification {}
|
||||||
match event {
|
|
||||||
MessageNotificationEvent::Dismiss => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait NotifyResultExt {
|
pub trait NotifyResultExt {
|
||||||
|
|
|
@ -9,8 +9,9 @@ use crate::{
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use collections::{HashMap, HashSet, VecDeque};
|
use collections::{HashMap, HashSet, VecDeque};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AppContext, AsyncWindowContext, Component, Div, EntityId, EventEmitter, FocusHandle, Model,
|
actions, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId,
|
||||||
PromptLevel, Render, Task, View, ViewContext, VisualContext, WeakView, WindowContext,
|
EventEmitter, FocusHandle, Model, PromptLevel, Render, Task, View, ViewContext, VisualContext,
|
||||||
|
WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
use project2::{Project, ProjectEntryId, ProjectPath};
|
||||||
|
@ -48,8 +49,10 @@ pub enum SaveIntent {
|
||||||
Skip,
|
Skip,
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[derive(Clone, Deserialize, PartialEq)]
|
//todo!("Do we need the default bound on actions? Decide soon")
|
||||||
// pub struct ActivateItem(pub usize);
|
// #[register_action]
|
||||||
|
#[derive(Clone, Deserialize, PartialEq, Debug)]
|
||||||
|
pub struct ActivateItem(pub usize);
|
||||||
|
|
||||||
// #[derive(Clone, PartialEq)]
|
// #[derive(Clone, PartialEq)]
|
||||||
// pub struct CloseItemById {
|
// pub struct CloseItemById {
|
||||||
|
@ -69,40 +72,37 @@ pub enum SaveIntent {
|
||||||
// pub pane: WeakView<Pane>,
|
// pub pane: WeakView<Pane>,
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// #[derive(Clone, PartialEq, Debug, Deserialize, Default)]
|
#[register_action]
|
||||||
// #[serde(rename_all = "camelCase")]
|
#[derive(Clone, PartialEq, Debug, Deserialize, Default)]
|
||||||
// pub struct CloseActiveItem {
|
#[serde(rename_all = "camelCase")]
|
||||||
// pub save_intent: Option<SaveIntent>,
|
pub struct CloseActiveItem {
|
||||||
// }
|
pub save_intent: Option<SaveIntent>,
|
||||||
|
}
|
||||||
|
|
||||||
// #[derive(Clone, PartialEq, Debug, Deserialize)]
|
#[register_action]
|
||||||
// #[serde(rename_all = "camelCase")]
|
#[derive(Clone, PartialEq, Debug, Deserialize, Default)]
|
||||||
// pub struct CloseAllItems {
|
#[serde(rename_all = "camelCase")]
|
||||||
// pub save_intent: Option<SaveIntent>,
|
pub struct CloseAllItems {
|
||||||
// }
|
pub save_intent: Option<SaveIntent>,
|
||||||
|
}
|
||||||
|
|
||||||
// todo!()
|
// todo!(These used to be under pane::{Action}. Are they now workspace::pane::{Action}?)
|
||||||
// actions!(
|
actions!(
|
||||||
// pane,
|
ActivatePrevItem,
|
||||||
// [
|
ActivateNextItem,
|
||||||
// ActivatePrevItem,
|
ActivateLastItem,
|
||||||
// ActivateNextItem,
|
CloseInactiveItems,
|
||||||
// ActivateLastItem,
|
CloseCleanItems,
|
||||||
// CloseInactiveItems,
|
CloseItemsToTheLeft,
|
||||||
// CloseCleanItems,
|
CloseItemsToTheRight,
|
||||||
// CloseItemsToTheLeft,
|
GoBack,
|
||||||
// CloseItemsToTheRight,
|
GoForward,
|
||||||
// GoBack,
|
ReopenClosedItem,
|
||||||
// GoForward,
|
SplitLeft,
|
||||||
// ReopenClosedItem,
|
SplitUp,
|
||||||
// SplitLeft,
|
SplitRight,
|
||||||
// SplitUp,
|
SplitDown,
|
||||||
// SplitRight,
|
);
|
||||||
// SplitDown,
|
|
||||||
// ]
|
|
||||||
// );
|
|
||||||
|
|
||||||
// impl_actions!(pane, [ActivateItem, CloseActiveItem, CloseAllItems]);
|
|
||||||
|
|
||||||
const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
|
const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
|
||||||
|
|
||||||
|
@ -310,9 +310,7 @@ pub struct NavigationEntry {
|
||||||
// .into_any_named("nav button")
|
// .into_any_named("nav button")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
impl EventEmitter for Pane {
|
impl EventEmitter<Event> for Pane {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Pane {
|
impl Pane {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use std::{any::Any, sync::Arc};
|
use std::{any::Any, sync::Arc};
|
||||||
|
|
||||||
use gpui::{AnyView, AppContext, Subscription, Task, View, ViewContext, WindowContext};
|
use gpui::{
|
||||||
|
AnyView, AppContext, EventEmitter, Subscription, Task, View, ViewContext, WindowContext,
|
||||||
|
};
|
||||||
use project2::search::SearchQuery;
|
use project2::search::SearchQuery;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -29,7 +31,7 @@ pub struct SearchOptions {
|
||||||
pub replacement: bool,
|
pub replacement: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SearchableItem: Item {
|
pub trait SearchableItem: Item + EventEmitter<SearchEvent> {
|
||||||
type Match: Any + Sync + Send + Clone;
|
type Match: Any + Sync + Send + Clone;
|
||||||
|
|
||||||
fn supported_options() -> SearchOptions {
|
fn supported_options() -> SearchOptions {
|
||||||
|
@ -40,11 +42,7 @@ pub trait SearchableItem: Item {
|
||||||
replacement: true,
|
replacement: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn to_search_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Self::Event,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
) -> Option<SearchEvent>;
|
|
||||||
fn clear_matches(&mut self, cx: &mut ViewContext<Self>);
|
fn clear_matches(&mut self, cx: &mut ViewContext<Self>);
|
||||||
fn update_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>);
|
fn update_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>);
|
||||||
fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String;
|
fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String;
|
||||||
|
@ -95,7 +93,7 @@ pub trait SearchableItemHandle: ItemHandle {
|
||||||
fn subscribe_to_search_events(
|
fn subscribe_to_search_events(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
handler: Box<dyn Fn(SearchEvent, &mut WindowContext) + Send>,
|
handler: Box<dyn Fn(&SearchEvent, &mut WindowContext) + Send>,
|
||||||
) -> Subscription;
|
) -> Subscription;
|
||||||
fn clear_matches(&self, cx: &mut WindowContext);
|
fn clear_matches(&self, cx: &mut WindowContext);
|
||||||
fn update_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut WindowContext);
|
fn update_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut WindowContext);
|
||||||
|
@ -146,14 +144,9 @@ impl<T: SearchableItem> SearchableItemHandle for View<T> {
|
||||||
fn subscribe_to_search_events(
|
fn subscribe_to_search_events(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
handler: Box<dyn Fn(SearchEvent, &mut WindowContext) + Send>,
|
handler: Box<dyn Fn(&SearchEvent, &mut WindowContext) + Send>,
|
||||||
) -> Subscription {
|
) -> Subscription {
|
||||||
cx.subscribe(self, move |handle, event, cx| {
|
cx.subscribe(self, move |_, event: &SearchEvent, cx| handler(event, cx))
|
||||||
let search_event = handle.update(cx, |handle, cx| handle.to_search_event(event, cx));
|
|
||||||
if let Some(search_event) = search_event {
|
|
||||||
handler(search_event, cx)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_matches(&self, cx: &mut WindowContext) {
|
fn clear_matches(&self, cx: &mut WindowContext) {
|
||||||
|
|
|
@ -1,24 +1,19 @@
|
||||||
use crate::ItemHandle;
|
use crate::ItemHandle;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyView, AppContext, Entity, EntityId, EventEmitter, Render, View, ViewContext, WindowContext,
|
AnyView, Div, Entity, EntityId, EventEmitter, Render, View, ViewContext, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait ToolbarItemView: Render + EventEmitter {
|
pub enum ToolbarItemEvent {
|
||||||
|
ChangeLocation(ToolbarItemLocation),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait ToolbarItemView: Render + EventEmitter<ToolbarItemEvent> {
|
||||||
fn set_active_pane_item(
|
fn set_active_pane_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
active_pane_item: Option<&dyn crate::ItemHandle>,
|
active_pane_item: Option<&dyn crate::ItemHandle>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> ToolbarItemLocation;
|
) -> ToolbarItemLocation;
|
||||||
|
|
||||||
fn location_for_event(
|
|
||||||
&self,
|
|
||||||
_event: &Self::Event,
|
|
||||||
current_location: ToolbarItemLocation,
|
|
||||||
_cx: &AppContext,
|
|
||||||
) -> ToolbarItemLocation {
|
|
||||||
current_location
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pane_focus_update(&mut self, _pane_focused: bool, _cx: &mut ViewContext<Self>) {}
|
fn pane_focus_update(&mut self, _pane_focused: bool, _cx: &mut ViewContext<Self>) {}
|
||||||
|
|
||||||
/// Number of times toolbar's height will be repeated to get the effective height.
|
/// Number of times toolbar's height will be repeated to get the effective height.
|
||||||
|
@ -56,6 +51,14 @@ pub struct Toolbar {
|
||||||
items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>,
|
items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Render for Toolbar {
|
||||||
|
type Element = Div<Self>;
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// todo!()
|
// todo!()
|
||||||
// impl View for Toolbar {
|
// impl View for Toolbar {
|
||||||
// fn ui_name() -> &'static str {
|
// fn ui_name() -> &'static str {
|
||||||
|
@ -132,61 +135,6 @@ pub struct Toolbar {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// <<<<<<< HEAD
|
|
||||||
// =======
|
|
||||||
// #[allow(clippy::too_many_arguments)]
|
|
||||||
// fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>)>(
|
|
||||||
// svg_path: &'static str,
|
|
||||||
// style: theme::Interactive<theme::IconButton>,
|
|
||||||
// nav_button_height: f32,
|
|
||||||
// tooltip_style: TooltipStyle,
|
|
||||||
// enabled: bool,
|
|
||||||
// spacing: f32,
|
|
||||||
// on_click: F,
|
|
||||||
// tooltip_action: A,
|
|
||||||
// action_name: &'static str,
|
|
||||||
// cx: &mut ViewContext<Toolbar>,
|
|
||||||
// ) -> AnyElement<Toolbar> {
|
|
||||||
// MouseEventHandler::new::<A, _>(0, cx, |state, _| {
|
|
||||||
// let style = if enabled {
|
|
||||||
// style.style_for(state)
|
|
||||||
// } else {
|
|
||||||
// style.disabled_style()
|
|
||||||
// };
|
|
||||||
// Svg::new(svg_path)
|
|
||||||
// .with_color(style.color)
|
|
||||||
// .constrained()
|
|
||||||
// .with_width(style.icon_width)
|
|
||||||
// .aligned()
|
|
||||||
// .contained()
|
|
||||||
// .with_style(style.container)
|
|
||||||
// .constrained()
|
|
||||||
// .with_width(style.button_width)
|
|
||||||
// .with_height(nav_button_height)
|
|
||||||
// .aligned()
|
|
||||||
// .top()
|
|
||||||
// })
|
|
||||||
// .with_cursor_style(if enabled {
|
|
||||||
// CursorStyle::PointingHand
|
|
||||||
// } else {
|
|
||||||
// CursorStyle::default()
|
|
||||||
// })
|
|
||||||
// .on_click(MouseButton::Left, move |_, toolbar, cx| {
|
|
||||||
// on_click(toolbar, cx)
|
|
||||||
// })
|
|
||||||
// .with_tooltip::<A>(
|
|
||||||
// 0,
|
|
||||||
// action_name,
|
|
||||||
// Some(Box::new(tooltip_action)),
|
|
||||||
// tooltip_style,
|
|
||||||
// cx,
|
|
||||||
// )
|
|
||||||
// .contained()
|
|
||||||
// .with_margin_right(spacing)
|
|
||||||
// .into_any_named("nav button")
|
|
||||||
// }
|
|
||||||
|
|
||||||
// >>>>>>> 139cbbfd3aebd0863a7d51b0c12d748764cf0b2e
|
|
||||||
impl Toolbar {
|
impl Toolbar {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -211,14 +159,15 @@ impl Toolbar {
|
||||||
if let Some((_, current_location)) =
|
if let Some((_, current_location)) =
|
||||||
this.items.iter_mut().find(|(i, _)| i.id() == item.id())
|
this.items.iter_mut().find(|(i, _)| i.id() == item.id())
|
||||||
{
|
{
|
||||||
let new_location = item
|
match event {
|
||||||
.read(cx)
|
ToolbarItemEvent::ChangeLocation(new_location) => {
|
||||||
.location_for_event(event, *current_location, cx);
|
if new_location != current_location {
|
||||||
if new_location != *current_location {
|
*current_location = *new_location;
|
||||||
*current_location = new_location;
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
self.items.push((Box::new(item), location));
|
self.items.push((Box::new(item), location));
|
||||||
|
|
|
@ -36,7 +36,7 @@ use futures::{
|
||||||
Future, FutureExt, StreamExt,
|
Future, FutureExt, StreamExt,
|
||||||
};
|
};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, point, rems, size, AnyModel, AnyView, AnyWeakView, AppContext, AsyncAppContext,
|
actions, div, point, rems, size, AnyModel, AnyView, AnyWeakView, AppContext, AsyncAppContext,
|
||||||
AsyncWindowContext, Bounds, Component, Div, Entity, EntityId, EventEmitter, FocusHandle,
|
AsyncWindowContext, Bounds, Component, Div, Entity, EntityId, EventEmitter, FocusHandle,
|
||||||
GlobalPixels, Model, ModelContext, ParentElement, Point, Render, Size, StatefulInteractive,
|
GlobalPixels, Model, ModelContext, ParentElement, Point, Render, Size, StatefulInteractive,
|
||||||
Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowBounds,
|
Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowBounds,
|
||||||
|
@ -46,8 +46,7 @@ use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings,
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use language2::LanguageRegistry;
|
use language2::LanguageRegistry;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
pub use modal_layer::ModalRegistry;
|
pub use modal_layer::*;
|
||||||
use modal_layer::{init_modal_registry, ModalLayer};
|
|
||||||
use node_runtime::NodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use notifications::{simple_message_notification::MessageNotification, NotificationHandle};
|
use notifications::{simple_message_notification::MessageNotification, NotificationHandle};
|
||||||
pub use pane::*;
|
pub use pane::*;
|
||||||
|
@ -88,35 +87,32 @@ lazy_static! {
|
||||||
// #[derive(Clone, PartialEq)]
|
// #[derive(Clone, PartialEq)]
|
||||||
// pub struct RemoveWorktreeFromProject(pub WorktreeId);
|
// pub struct RemoveWorktreeFromProject(pub WorktreeId);
|
||||||
|
|
||||||
// actions!(
|
actions!(
|
||||||
// workspace,
|
Open,
|
||||||
// [
|
NewFile,
|
||||||
// Open,
|
NewWindow,
|
||||||
// NewFile,
|
CloseWindow,
|
||||||
// NewWindow,
|
CloseInactiveTabsAndPanes,
|
||||||
// CloseWindow,
|
AddFolderToProject,
|
||||||
// CloseInactiveTabsAndPanes,
|
Unfollow,
|
||||||
// AddFolderToProject,
|
SaveAs,
|
||||||
// Unfollow,
|
ReloadActiveItem,
|
||||||
// SaveAs,
|
ActivatePreviousPane,
|
||||||
// ReloadActiveItem,
|
ActivateNextPane,
|
||||||
// ActivatePreviousPane,
|
FollowNextCollaborator,
|
||||||
// ActivateNextPane,
|
NewTerminal,
|
||||||
// FollowNextCollaborator,
|
NewCenterTerminal,
|
||||||
// NewTerminal,
|
ToggleTerminalFocus,
|
||||||
// NewCenterTerminal,
|
NewSearch,
|
||||||
// ToggleTerminalFocus,
|
Feedback,
|
||||||
// NewSearch,
|
Restart,
|
||||||
// Feedback,
|
Welcome,
|
||||||
// Restart,
|
ToggleZoom,
|
||||||
// Welcome,
|
ToggleLeftDock,
|
||||||
// ToggleZoom,
|
ToggleRightDock,
|
||||||
// ToggleLeftDock,
|
ToggleBottomDock,
|
||||||
// ToggleRightDock,
|
CloseAllDocks,
|
||||||
// ToggleBottomDock,
|
);
|
||||||
// CloseAllDocks,
|
|
||||||
// ]
|
|
||||||
// );
|
|
||||||
|
|
||||||
// #[derive(Clone, PartialEq)]
|
// #[derive(Clone, PartialEq)]
|
||||||
// pub struct OpenPaths {
|
// pub struct OpenPaths {
|
||||||
|
@ -227,7 +223,6 @@ pub fn init_settings(cx: &mut AppContext) {
|
||||||
|
|
||||||
pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
|
pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||||
init_settings(cx);
|
init_settings(cx);
|
||||||
init_modal_registry(cx);
|
|
||||||
pane::init(cx);
|
pane::init(cx);
|
||||||
notifications::init(cx);
|
notifications::init(cx);
|
||||||
|
|
||||||
|
@ -547,7 +542,7 @@ pub struct Workspace {
|
||||||
last_active_center_pane: Option<WeakView<Pane>>,
|
last_active_center_pane: Option<WeakView<Pane>>,
|
||||||
last_active_view_id: Option<proto::ViewId>,
|
last_active_view_id: Option<proto::ViewId>,
|
||||||
status_bar: View<StatusBar>,
|
status_bar: View<StatusBar>,
|
||||||
modal_layer: View<ModalLayer>,
|
modal_layer: ModalLayer,
|
||||||
// titlebar_item: Option<AnyViewHandle>,
|
// titlebar_item: Option<AnyViewHandle>,
|
||||||
notifications: Vec<(TypeId, usize, Box<dyn NotificationHandle>)>,
|
notifications: Vec<(TypeId, usize, Box<dyn NotificationHandle>)>,
|
||||||
project: Model<Project>,
|
project: Model<Project>,
|
||||||
|
@ -698,7 +693,8 @@ impl Workspace {
|
||||||
status_bar
|
status_bar
|
||||||
});
|
});
|
||||||
|
|
||||||
let modal_layer = cx.build_view(|cx| ModalLayer::new());
|
let workspace_handle = cx.view().downgrade();
|
||||||
|
let modal_layer = ModalLayer::new();
|
||||||
|
|
||||||
// todo!()
|
// todo!()
|
||||||
// cx.update_default_global::<DragAndDrop<Workspace>, _, _>(|drag_and_drop, _| {
|
// cx.update_default_global::<DragAndDrop<Workspace>, _, _>(|drag_and_drop, _| {
|
||||||
|
@ -782,6 +778,10 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn modal_layer(&mut self) -> &mut ModalLayer {
|
||||||
|
&mut self.modal_layer
|
||||||
|
}
|
||||||
|
|
||||||
fn new_local(
|
fn new_local(
|
||||||
abs_paths: Vec<PathBuf>,
|
abs_paths: Vec<PathBuf>,
|
||||||
app_state: Arc<AppState>,
|
app_state: Arc<AppState>,
|
||||||
|
@ -964,6 +964,9 @@ impl Workspace {
|
||||||
// let mut prev_position = panel.position(cx);
|
// let mut prev_position = panel.position(cx);
|
||||||
// move |this, panel, event, cx| {
|
// move |this, panel, event, cx| {
|
||||||
// if T::should_change_position_on_event(event) {
|
// if T::should_change_position_on_event(event) {
|
||||||
|
// THIS HAS BEEN MOVED TO NORMAL EVENT EMISSION
|
||||||
|
// See: Dock::add_panel
|
||||||
|
//
|
||||||
// let new_position = panel.read(cx).position(cx);
|
// let new_position = panel.read(cx).position(cx);
|
||||||
// let mut was_visible = false;
|
// let mut was_visible = false;
|
||||||
// dock.update(cx, |dock, cx| {
|
// dock.update(cx, |dock, cx| {
|
||||||
|
@ -994,6 +997,9 @@ impl Workspace {
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
// } else if T::should_zoom_in_on_event(event) {
|
// } else if T::should_zoom_in_on_event(event) {
|
||||||
|
// THIS HAS BEEN MOVED TO NORMAL EVENT EMISSION
|
||||||
|
// See: Dock::add_panel
|
||||||
|
//
|
||||||
// dock.update(cx, |dock, cx| dock.set_panel_zoomed(&panel, true, cx));
|
// dock.update(cx, |dock, cx| dock.set_panel_zoomed(&panel, true, cx));
|
||||||
// if !panel.has_focus(cx) {
|
// if !panel.has_focus(cx) {
|
||||||
// cx.focus(&panel);
|
// cx.focus(&panel);
|
||||||
|
@ -1001,6 +1007,9 @@ impl Workspace {
|
||||||
// this.zoomed = Some(panel.downgrade().into_any());
|
// this.zoomed = Some(panel.downgrade().into_any());
|
||||||
// this.zoomed_position = Some(panel.read(cx).position(cx));
|
// this.zoomed_position = Some(panel.read(cx).position(cx));
|
||||||
// } else if T::should_zoom_out_on_event(event) {
|
// } else if T::should_zoom_out_on_event(event) {
|
||||||
|
// THIS HAS BEEN MOVED TO NORMAL EVENT EMISSION
|
||||||
|
// See: Dock::add_panel
|
||||||
|
//
|
||||||
// dock.update(cx, |dock, cx| dock.set_panel_zoomed(&panel, false, cx));
|
// dock.update(cx, |dock, cx| dock.set_panel_zoomed(&panel, false, cx));
|
||||||
// if this.zoomed_position == Some(prev_position) {
|
// if this.zoomed_position == Some(prev_position) {
|
||||||
// this.zoomed = None;
|
// this.zoomed = None;
|
||||||
|
@ -1008,6 +1017,9 @@ impl Workspace {
|
||||||
// }
|
// }
|
||||||
// cx.notify();
|
// cx.notify();
|
||||||
// } else if T::is_focus_event(event) {
|
// } else if T::is_focus_event(event) {
|
||||||
|
// THIS HAS BEEN MOVED TO NORMAL EVENT EMISSION
|
||||||
|
// See: Dock::add_panel
|
||||||
|
//
|
||||||
// let position = panel.read(cx).position(cx);
|
// let position = panel.read(cx).position(cx);
|
||||||
// this.dismiss_zoomed_items_to_reveal(Some(position), cx);
|
// this.dismiss_zoomed_items_to_reveal(Some(position), cx);
|
||||||
// if panel.is_zoomed(cx) {
|
// if panel.is_zoomed(cx) {
|
||||||
|
@ -3691,9 +3703,7 @@ fn notify_if_database_failed(workspace: WindowHandle<Workspace>, cx: &mut AsyncA
|
||||||
.log_err();
|
.log_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for Workspace {
|
impl EventEmitter<Event> for Workspace {}
|
||||||
type Event = Event;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Render for Workspace {
|
impl Render for Workspace {
|
||||||
type Element = Div<Self>;
|
type Element = Div<Self>;
|
||||||
|
@ -3712,13 +3722,13 @@ impl Render for Workspace {
|
||||||
.bg(cx.theme().colors().background)
|
.bg(cx.theme().colors().background)
|
||||||
.child(self.render_titlebar(cx))
|
.child(self.render_titlebar(cx))
|
||||||
.child(
|
.child(
|
||||||
|
// todo! should this be a component a view?
|
||||||
self.modal_layer
|
self.modal_layer
|
||||||
.read(cx)
|
.wrapper_element(cx)
|
||||||
.render(self, cx)
|
.relative()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.w_full()
|
.w_full()
|
||||||
.flex()
|
.flex()
|
||||||
.flex_row()
|
|
||||||
.overflow_hidden()
|
.overflow_hidden()
|
||||||
.border_t()
|
.border_t()
|
||||||
.border_b()
|
.border_b()
|
||||||
|
@ -4135,10 +4145,6 @@ impl WorkspaceStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter for WorkspaceStore {
|
|
||||||
type Event = ();
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ViewId {
|
impl ViewId {
|
||||||
pub(crate) fn from_proto(message: proto::ViewId) -> Result<Self> {
|
pub(crate) fn from_proto(message: proto::ViewId) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
|
@ -48,6 +48,7 @@ journal = { package = "journal2", path = "../journal2" }
|
||||||
language = { package = "language2", path = "../language2" }
|
language = { package = "language2", path = "../language2" }
|
||||||
# language_selector = { path = "../language_selector" }
|
# language_selector = { path = "../language_selector" }
|
||||||
lsp = { package = "lsp2", path = "../lsp2" }
|
lsp = { package = "lsp2", path = "../lsp2" }
|
||||||
|
menu = { package = "menu2", path = "../menu2" }
|
||||||
language_tools = { path = "../language_tools" }
|
language_tools = { path = "../language_tools" }
|
||||||
node_runtime = { path = "../node_runtime" }
|
node_runtime = { path = "../node_runtime" }
|
||||||
# assistant = { path = "../assistant" }
|
# assistant = { path = "../assistant" }
|
||||||
|
@ -58,6 +59,7 @@ project = { package = "project2", path = "../project2" }
|
||||||
# project_symbols = { path = "../project_symbols" }
|
# project_symbols = { path = "../project_symbols" }
|
||||||
# quick_action_bar = { path = "../quick_action_bar" }
|
# quick_action_bar = { path = "../quick_action_bar" }
|
||||||
# recent_projects = { path = "../recent_projects" }
|
# recent_projects = { path = "../recent_projects" }
|
||||||
|
rope = { package = "rope2", path = "../rope2"}
|
||||||
rpc = { package = "rpc2", path = "../rpc2" }
|
rpc = { package = "rpc2", path = "../rpc2" }
|
||||||
settings = { package = "settings2", path = "../settings2" }
|
settings = { package = "settings2", path = "../settings2" }
|
||||||
feature_flags = { package = "feature_flags2", path = "../feature_flags2" }
|
feature_flags = { package = "feature_flags2", path = "../feature_flags2" }
|
||||||
|
|
|
@ -56,6 +56,10 @@ use zed2::{
|
||||||
mod open_listener;
|
mod open_listener;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
//TODO!(figure out what the linker issues are here)
|
||||||
|
// https://github.com/rust-lang/rust/issues/47384
|
||||||
|
// https://github.com/mmastrac/rust-ctor/issues/280
|
||||||
|
menu::unused();
|
||||||
let http = http::client();
|
let http = http::client();
|
||||||
init_paths();
|
init_paths();
|
||||||
init_logger();
|
init_logger();
|
||||||
|
|
|
@ -23,7 +23,7 @@ export default function assistant(): any {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
|
|
||||||
const interactive_role = (
|
const interactive_role = (
|
||||||
color: StyleSets
|
color: StyleSets,
|
||||||
): Interactive<RoleCycleButton> => {
|
): Interactive<RoleCycleButton> => {
|
||||||
return interactive({
|
return interactive({
|
||||||
base: {
|
base: {
|
||||||
|
@ -94,7 +94,7 @@ export default function assistant(): any {
|
||||||
margin: { left: 8, right: 18 },
|
margin: { left: 8, right: 18 },
|
||||||
color: foreground(theme.highest, "positive"),
|
color: foreground(theme.highest, "positive"),
|
||||||
width: 12,
|
width: 12,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
retrieve_context: toggleable({
|
retrieve_context: toggleable({
|
||||||
base: interactive({
|
base: interactive({
|
||||||
|
@ -106,7 +106,8 @@ export default function assistant(): any {
|
||||||
background: background(theme.highest, "on"),
|
background: background(theme.highest, "on"),
|
||||||
corner_radius: 2,
|
corner_radius: 2,
|
||||||
border: {
|
border: {
|
||||||
width: 1., color: background(theme.highest, "on")
|
width: 1,
|
||||||
|
color: background(theme.highest, "on"),
|
||||||
},
|
},
|
||||||
margin: { left: 2 },
|
margin: { left: 2 },
|
||||||
padding: {
|
padding: {
|
||||||
|
@ -118,17 +119,45 @@ export default function assistant(): any {
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
hovered: {
|
hovered: {
|
||||||
...text(theme.highest, "mono", "variant", "hovered"),
|
...text(
|
||||||
background: background(theme.highest, "on", "hovered"),
|
theme.highest,
|
||||||
|
"mono",
|
||||||
|
"variant",
|
||||||
|
"hovered",
|
||||||
|
),
|
||||||
|
background: background(
|
||||||
|
theme.highest,
|
||||||
|
"on",
|
||||||
|
"hovered",
|
||||||
|
),
|
||||||
border: {
|
border: {
|
||||||
width: 1., color: background(theme.highest, "on", "hovered")
|
width: 1,
|
||||||
|
color: background(
|
||||||
|
theme.highest,
|
||||||
|
"on",
|
||||||
|
"hovered",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
clicked: {
|
clicked: {
|
||||||
...text(theme.highest, "mono", "variant", "pressed"),
|
...text(
|
||||||
background: background(theme.highest, "on", "pressed"),
|
theme.highest,
|
||||||
|
"mono",
|
||||||
|
"variant",
|
||||||
|
"pressed",
|
||||||
|
),
|
||||||
|
background: background(
|
||||||
|
theme.highest,
|
||||||
|
"on",
|
||||||
|
"pressed",
|
||||||
|
),
|
||||||
border: {
|
border: {
|
||||||
width: 1., color: background(theme.highest, "on", "pressed")
|
width: 1,
|
||||||
|
color: background(
|
||||||
|
theme.highest,
|
||||||
|
"on",
|
||||||
|
"pressed",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -143,11 +172,19 @@ export default function assistant(): any {
|
||||||
border: border(theme.highest, "accent"),
|
border: border(theme.highest, "accent"),
|
||||||
},
|
},
|
||||||
hovered: {
|
hovered: {
|
||||||
background: background(theme.highest, "accent", "hovered"),
|
background: background(
|
||||||
|
theme.highest,
|
||||||
|
"accent",
|
||||||
|
"hovered",
|
||||||
|
),
|
||||||
border: border(theme.highest, "accent", "hovered"),
|
border: border(theme.highest, "accent", "hovered"),
|
||||||
},
|
},
|
||||||
clicked: {
|
clicked: {
|
||||||
background: background(theme.highest, "accent", "pressed"),
|
background: background(
|
||||||
|
theme.highest,
|
||||||
|
"accent",
|
||||||
|
"pressed",
|
||||||
|
),
|
||||||
border: border(theme.highest, "accent", "pressed"),
|
border: border(theme.highest, "accent", "pressed"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -163,7 +200,8 @@ export default function assistant(): any {
|
||||||
background: background(theme.highest, "on"),
|
background: background(theme.highest, "on"),
|
||||||
corner_radius: 2,
|
corner_radius: 2,
|
||||||
border: {
|
border: {
|
||||||
width: 1., color: background(theme.highest, "on")
|
width: 1,
|
||||||
|
color: background(theme.highest, "on"),
|
||||||
},
|
},
|
||||||
padding: {
|
padding: {
|
||||||
left: 4,
|
left: 4,
|
||||||
|
@ -174,17 +212,45 @@ export default function assistant(): any {
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
hovered: {
|
hovered: {
|
||||||
...text(theme.highest, "mono", "variant", "hovered"),
|
...text(
|
||||||
background: background(theme.highest, "on", "hovered"),
|
theme.highest,
|
||||||
|
"mono",
|
||||||
|
"variant",
|
||||||
|
"hovered",
|
||||||
|
),
|
||||||
|
background: background(
|
||||||
|
theme.highest,
|
||||||
|
"on",
|
||||||
|
"hovered",
|
||||||
|
),
|
||||||
border: {
|
border: {
|
||||||
width: 1., color: background(theme.highest, "on", "hovered")
|
width: 1,
|
||||||
|
color: background(
|
||||||
|
theme.highest,
|
||||||
|
"on",
|
||||||
|
"hovered",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
clicked: {
|
clicked: {
|
||||||
...text(theme.highest, "mono", "variant", "pressed"),
|
...text(
|
||||||
background: background(theme.highest, "on", "pressed"),
|
theme.highest,
|
||||||
|
"mono",
|
||||||
|
"variant",
|
||||||
|
"pressed",
|
||||||
|
),
|
||||||
|
background: background(
|
||||||
|
theme.highest,
|
||||||
|
"on",
|
||||||
|
"pressed",
|
||||||
|
),
|
||||||
border: {
|
border: {
|
||||||
width: 1., color: background(theme.highest, "on", "pressed")
|
width: 1,
|
||||||
|
color: background(
|
||||||
|
theme.highest,
|
||||||
|
"on",
|
||||||
|
"pressed",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -199,11 +265,19 @@ export default function assistant(): any {
|
||||||
border: border(theme.highest, "accent"),
|
border: border(theme.highest, "accent"),
|
||||||
},
|
},
|
||||||
hovered: {
|
hovered: {
|
||||||
background: background(theme.highest, "accent", "hovered"),
|
background: background(
|
||||||
|
theme.highest,
|
||||||
|
"accent",
|
||||||
|
"hovered",
|
||||||
|
),
|
||||||
border: border(theme.highest, "accent", "hovered"),
|
border: border(theme.highest, "accent", "hovered"),
|
||||||
},
|
},
|
||||||
clicked: {
|
clicked: {
|
||||||
background: background(theme.highest, "accent", "pressed"),
|
background: background(
|
||||||
|
theme.highest,
|
||||||
|
"accent",
|
||||||
|
"pressed",
|
||||||
|
),
|
||||||
border: border(theme.highest, "accent", "pressed"),
|
border: border(theme.highest, "accent", "pressed"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -78,33 +78,33 @@ export default function status_bar(): any {
|
||||||
padding: { top: 2, bottom: 2, left: 6, right: 6 },
|
padding: { top: 2, bottom: 2, left: 6, right: 6 },
|
||||||
},
|
},
|
||||||
container_warning: diagnostic_status_container,
|
container_warning: diagnostic_status_container,
|
||||||
container_error: diagnostic_status_container
|
container_error: diagnostic_status_container,
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
hovered: {
|
hovered: {
|
||||||
icon_color_ok: foreground(layer, "on"),
|
icon_color_ok: foreground(layer, "on"),
|
||||||
container_ok: {
|
container_ok: {
|
||||||
background: background(layer, "hovered")
|
background: background(layer, "hovered"),
|
||||||
},
|
},
|
||||||
container_warning: {
|
container_warning: {
|
||||||
background: background(layer, "hovered")
|
background: background(layer, "hovered"),
|
||||||
},
|
},
|
||||||
container_error: {
|
container_error: {
|
||||||
background: background(layer, "hovered")
|
background: background(layer, "hovered"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
clicked: {
|
clicked: {
|
||||||
icon_color_ok: foreground(layer, "on"),
|
icon_color_ok: foreground(layer, "on"),
|
||||||
container_ok: {
|
container_ok: {
|
||||||
background: background(layer, "pressed")
|
background: background(layer, "pressed"),
|
||||||
},
|
},
|
||||||
container_warning: {
|
container_warning: {
|
||||||
background: background(layer, "pressed")
|
background: background(layer, "pressed"),
|
||||||
},
|
},
|
||||||
container_error: {
|
container_error: {
|
||||||
background: background(layer, "pressed")
|
background: background(layer, "pressed"),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
panel_buttons: {
|
panel_buttons: {
|
||||||
|
|
|
@ -31,7 +31,7 @@ export const theme: ThemeConfig = {
|
||||||
color.muted,
|
color.muted,
|
||||||
color.subtle,
|
color.subtle,
|
||||||
color.text,
|
color.text,
|
||||||
].reverse()
|
].reverse(),
|
||||||
)
|
)
|
||||||
.domain([0, 0.35, 0.45, 0.65, 0.7, 0.8, 0.9, 1]),
|
.domain([0, 0.35, 0.45, 0.65, 0.7, 0.8, 0.9, 1]),
|
||||||
red: color_ramp(chroma(color.love)),
|
red: color_ramp(chroma(color.love)),
|
||||||
|
|
24
test.rs
24
test.rs
|
@ -10,49 +10,49 @@ use element::Element;
|
||||||
use frame::frame;
|
use frame::frame;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
geometry::{rect::RectF, vector::vec2f},
|
geometry::{rect::RectF, vector::vec2f},
|
||||||
platform::WindowOptions,
|
platform::WindowOptions,aa
|
||||||
};
|
};
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;a
|
||||||
use simplelog::SimpleLogger;
|
use simplelog::SimpleLogger;
|
||||||
use themes::{rose_pine, ThemeColors};
|
use themes::{rose_pine, ThemeColors};
|
||||||
use view::view;
|
use view::view;a
|
||||||
mod adapter {
|
mod adapter {
|
||||||
use crate::element::AnyElement;
|
use crate::element::AnyElement;
|
||||||
use crate::element::{LayoutContext, PaintContext};
|
use crate::element::{LayoutContext, PaintContext};
|
||||||
use gpui::{geometry::rect::RectF, LayoutEngine};
|
use gpui::{geometry::rect::RectF, LayoutEngine};aaaa
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
pub struct Adapter<V>(pub(crate) AnyElement<V>);
|
pub struct Adapter<V>(pub(crate) AnyElement<V>);
|
||||||
impl<V: 'static> gpui::Element<V> for Adapter<V> {
|
impl<V: 'static> gpui::Element<V> for Adapter<V> {aa
|
||||||
type LayoutState = Option<LayoutEngine>;
|
type LayoutState = Option<LayaoutEngine>;
|
||||||
type PaintState = ();
|
type PaintState = ();
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
constraint: gpui::SizeConstraint,
|
constraint: gpui::SizeConstraint,
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
cx: &mut LayoutContext<V>,
|
cx: &mut LayoutContext<V>,aa
|
||||||
) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
|
) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
|
||||||
cx.push_layout_engine(LayoutEngine::new());
|
cx.push_layout_engine(LayoutEngine::new());
|
||||||
let node = self.0.layout(view, cx).log_err();
|
let node = self.0.layout(view, cx).log_err();a
|
||||||
if let Some(node) = node {
|
if let Some(node) = node {
|
||||||
let layout_engine = cx.layout_engine().unwrap();
|
let layout_engine = cx.layout_engine().unwrap();
|
||||||
layout_engine.compute_layout(node, constraint.max).log_err();
|
layout_engine.compute_layout(node, constraint.max).log_err();
|
||||||
}
|
}
|
||||||
let layout_engine = cx.pop_layout_engine();
|
let layout_engine = cx.pop_layout_engine();
|
||||||
if true {
|
if true {a
|
||||||
if !layout_engine.is_some() {
|
if !layout_engine.is_some() {
|
||||||
::core::panicking::panic("assertion failed: layout_engine.is_some()")
|
::core::panicking::panic("assertion failed: layout_engine.is_some()")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(constraint.max, layout_engine)
|
(constraint.max, layout_engine)a
|
||||||
}
|
}
|
||||||
fn paint(
|
fn paint(a
|
||||||
&mut self,
|
&mut self,
|
||||||
scene: &mut gpui::SceneBuilder,
|
scene: &mut gpui::SceneBuilder,
|
||||||
bounds: RectF,
|
bounds: RectF,
|
||||||
visible_bounds: RectF,
|
visible_bounds: RectF,
|
||||||
layout_engine: &mut Option<LayoutEngine>,
|
layout_engine: &mut Option<LayoutEngine>,
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
legacy_cx: &mut gpui::PaintContext<V>,
|
legacy_cx: &mut gpui::PaintContext<V>,aaa
|
||||||
) -> Self::PaintState {
|
) -> Self::PaintState {
|
||||||
legacy_cx.push_layout_engine(layout_engine.take().unwrap());
|
legacy_cx.push_layout_engine(layout_engine.take().unwrap());
|
||||||
let mut cx = PaintContext::new(legacy_cx, scene);
|
let mut cx = PaintContext::new(legacy_cx, scene);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue