WIP compiling but failing with circular reference

This commit is contained in:
K Simmons 2022-08-07 19:23:22 -07:00
parent 6442ec59e7
commit 690ea57211
22 changed files with 664 additions and 515 deletions

View File

@ -8,8 +8,8 @@ use gpui::{
elements::*, elements::*,
platform::CursorStyle, platform::CursorStyle,
views::{ItemType, Select, SelectStyle}, views::{ItemType, Select, SelectStyle},
AppContext, Entity, ModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription, AnyViewHandle, AppContext, Entity, ModelHandle, MouseButton, MutableAppContext, RenderContext,
Task, View, ViewContext, ViewHandle, Subscription, Task, View, ViewContext, ViewHandle,
}; };
use menu::Confirm; use menu::Confirm;
use postage::prelude::Stream; use postage::prelude::Stream;
@ -397,7 +397,7 @@ impl View for ChatPanel {
.boxed() .boxed()
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
if matches!( if matches!(
*self.rpc.status().borrow(), *self.rpc.status().borrow(),
client::Status::Connected { .. } client::Status::Connected { .. }

View File

@ -4,7 +4,8 @@ use gpui::{
actions, actions,
elements::{ChildView, Flex, Label, ParentElement}, elements::{ChildView, Flex, Label, ParentElement},
keymap::Keystroke, keymap::Keystroke,
Action, Element, Entity, MouseState, MutableAppContext, View, ViewContext, ViewHandle, Action, AnyViewHandle, Element, Entity, MouseState, MutableAppContext, View, ViewContext,
ViewHandle,
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use settings::Settings; use settings::Settings;
@ -132,7 +133,7 @@ impl View for CommandPalette {
ChildView::new(self.picker.clone()).boxed() ChildView::new(self.picker.clone()).boxed()
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.picker); cx.focus(&self.picker);
} }
} }

View File

@ -1,7 +1,7 @@
use client::{ContactRequestStatus, User, UserStore}; use client::{ContactRequestStatus, User, UserStore};
use gpui::{ use gpui::{
actions, elements::*, Entity, ModelHandle, MouseState, MutableAppContext, RenderContext, Task, actions, elements::*, AnyViewHandle, Entity, ModelHandle, MouseState, MutableAppContext,
View, ViewContext, ViewHandle, RenderContext, Task, View, ViewContext, ViewHandle,
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use settings::Settings; use settings::Settings;
@ -42,7 +42,7 @@ impl View for ContactFinder {
ChildView::new(self.picker.clone()).boxed() ChildView::new(self.picker.clone()).boxed()
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.picker); cx.focus(&self.picker);
} }
} }

View File

@ -13,9 +13,9 @@ use gpui::{
geometry::{rect::RectF, vector::vec2f}, geometry::{rect::RectF, vector::vec2f},
impl_actions, impl_internal_actions, impl_actions, impl_internal_actions,
platform::CursorStyle, platform::CursorStyle,
AppContext, ClipboardItem, Element, ElementBox, Entity, ModelHandle, MouseButton, AnyViewHandle, AppContext, ClipboardItem, Element, ElementBox, Entity, ModelHandle,
MutableAppContext, RenderContext, Subscription, View, ViewContext, ViewHandle, WeakModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription, View, ViewContext, ViewHandle,
WeakViewHandle, WeakModelHandle, WeakViewHandle,
}; };
use join_project_notification::JoinProjectNotification; use join_project_notification::JoinProjectNotification;
use menu::{Confirm, SelectNext, SelectPrev}; use menu::{Confirm, SelectNext, SelectPrev};
@ -1152,7 +1152,7 @@ impl View for ContactsPanel {
.boxed() .boxed()
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.filter_editor); cx.focus(&self.filter_editor);
} }

View File

@ -1,6 +1,6 @@
use gpui::{ use gpui::{
elements::*, geometry::vector::Vector2F, impl_internal_actions, keymap, platform::CursorStyle, elements::*, geometry::vector::Vector2F, impl_internal_actions, keymap, platform::CursorStyle,
Action, AppContext, Axis, Entity, MouseButton, MutableAppContext, RenderContext, Action, AnyViewHandle, AppContext, Axis, Entity, MouseButton, MutableAppContext, RenderContext,
SizeConstraint, Subscription, View, ViewContext, SizeConstraint, Subscription, View, ViewContext,
}; };
use menu::*; use menu::*;
@ -106,7 +106,7 @@ impl View for ContextMenu {
.boxed() .boxed()
} }
fn on_blur(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
self.reset(cx); self.reset(cx);
} }
} }

View File

@ -99,7 +99,7 @@ impl View for ProjectDiagnosticsEditor {
} }
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
if !self.path_states.is_empty() { if !self.path_states.is_empty() {
cx.focus(&self.editor); cx.focus(&self.editor);
} }

View File

@ -29,8 +29,8 @@ use gpui::{
geometry::vector::{vec2f, Vector2F}, geometry::vector::{vec2f, Vector2F},
impl_actions, impl_internal_actions, impl_actions, impl_internal_actions,
platform::CursorStyle, platform::CursorStyle,
text_layout, AppContext, AsyncAppContext, ClipboardItem, Element, ElementBox, Entity, text_layout, AnyViewHandle, AppContext, AsyncAppContext, ClipboardItem, Element, ElementBox,
ModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription, Task, View, Entity, ModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription, Task, View,
ViewContext, ViewHandle, WeakViewHandle, ViewContext, ViewHandle, WeakViewHandle,
}; };
use highlight_matching_bracket::refresh_matching_bracket_highlights; use highlight_matching_bracket::refresh_matching_bracket_highlights;
@ -6025,7 +6025,7 @@ impl View for Editor {
"Editor" "Editor"
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
let focused_event = EditorFocused(cx.handle()); let focused_event = EditorFocused(cx.handle());
cx.emit_global(focused_event); cx.emit_global(focused_event);
if let Some(rename) = self.pending_rename.as_ref() { if let Some(rename) = self.pending_rename.as_ref() {
@ -6046,7 +6046,7 @@ impl View for Editor {
} }
} }
fn on_blur(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
let blurred_event = EditorBlurred(cx.handle()); let blurred_event = EditorBlurred(cx.handle());
cx.emit_global(blurred_event); cx.emit_global(blurred_event);
self.focused = false; self.focused = false;

View File

@ -1,7 +1,7 @@
use fuzzy::PathMatch; use fuzzy::PathMatch;
use gpui::{ use gpui::{
actions, elements::*, AppContext, Entity, ModelHandle, MouseState, MutableAppContext, actions, elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, MouseState,
RenderContext, Task, View, ViewContext, ViewHandle, MutableAppContext, RenderContext, Task, View, ViewContext, ViewHandle,
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use project::{PathMatchCandidateSet, Project, ProjectPath, WorktreeId}; use project::{PathMatchCandidateSet, Project, ProjectPath, WorktreeId};
@ -53,7 +53,7 @@ impl View for FileFinder {
ChildView::new(self.picker.clone()).boxed() ChildView::new(self.picker.clone()).boxed()
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.picker); cx.focus(&self.picker);
} }
} }

View File

@ -1,7 +1,7 @@
use editor::{display_map::ToDisplayPoint, Autoscroll, DisplayPoint, Editor}; use editor::{display_map::ToDisplayPoint, Autoscroll, DisplayPoint, Editor};
use gpui::{ use gpui::{
actions, elements::*, geometry::vector::Vector2F, Axis, Entity, MutableAppContext, actions, elements::*, geometry::vector::Vector2F, AnyViewHandle, Axis, Entity,
RenderContext, View, ViewContext, ViewHandle, MutableAppContext, RenderContext, View, ViewContext, ViewHandle,
}; };
use menu::{Cancel, Confirm}; use menu::{Cancel, Confirm};
use settings::Settings; use settings::Settings;
@ -183,7 +183,7 @@ impl View for GoToLine {
.named("go to line") .named("go to line")
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.line_editor); cx.focus(&self.line_editor);
} }
} }

View File

@ -35,115 +35,132 @@ enum {
sym_parenthesized = 16, sym_parenthesized = 16,
}; };
static const char * const ts_symbol_names[] = { static const char *const ts_symbol_names[] = {
[ts_builtin_sym_end] = "end", [ts_builtin_sym_end] = "end",
[sym_identifier] = "identifier", [sym_identifier] = "identifier",
[anon_sym_BANG] = "!", [anon_sym_BANG] = "!",
[anon_sym_AMP_AMP] = "&&", [anon_sym_AMP_AMP] = "&&",
[anon_sym_PIPE_PIPE] = "||", [anon_sym_PIPE_PIPE] = "||",
[anon_sym_EQ_EQ] = "==", [anon_sym_EQ_EQ] = "==",
[anon_sym_BANG_EQ] = "!=", [anon_sym_BANG_EQ] = "!=",
[anon_sym_LPAREN] = "(", [anon_sym_LPAREN] = "(",
[anon_sym_RPAREN] = ")", [anon_sym_RPAREN] = ")",
[sym_source] = "source", [sym_source] = "source",
[sym__expression] = "_expression", [sym__expression] = "_expression",
[sym_not] = "not", [sym_not] = "not",
[sym_and] = "and", [sym_and] = "and",
[sym_or] = "or", [sym_or] = "or",
[sym_equal] = "equal", [sym_equal] = "equal",
[sym_not_equal] = "not_equal", [sym_not_equal] = "not_equal",
[sym_parenthesized] = "parenthesized", [sym_parenthesized] = "parenthesized",
}; };
static const TSSymbol ts_symbol_map[] = { static const TSSymbol ts_symbol_map[] = {
[ts_builtin_sym_end] = ts_builtin_sym_end, [ts_builtin_sym_end] = ts_builtin_sym_end,
[sym_identifier] = sym_identifier, [sym_identifier] = sym_identifier,
[anon_sym_BANG] = anon_sym_BANG, [anon_sym_BANG] = anon_sym_BANG,
[anon_sym_AMP_AMP] = anon_sym_AMP_AMP, [anon_sym_AMP_AMP] = anon_sym_AMP_AMP,
[anon_sym_PIPE_PIPE] = anon_sym_PIPE_PIPE, [anon_sym_PIPE_PIPE] = anon_sym_PIPE_PIPE,
[anon_sym_EQ_EQ] = anon_sym_EQ_EQ, [anon_sym_EQ_EQ] = anon_sym_EQ_EQ,
[anon_sym_BANG_EQ] = anon_sym_BANG_EQ, [anon_sym_BANG_EQ] = anon_sym_BANG_EQ,
[anon_sym_LPAREN] = anon_sym_LPAREN, [anon_sym_LPAREN] = anon_sym_LPAREN,
[anon_sym_RPAREN] = anon_sym_RPAREN, [anon_sym_RPAREN] = anon_sym_RPAREN,
[sym_source] = sym_source, [sym_source] = sym_source,
[sym__expression] = sym__expression, [sym__expression] = sym__expression,
[sym_not] = sym_not, [sym_not] = sym_not,
[sym_and] = sym_and, [sym_and] = sym_and,
[sym_or] = sym_or, [sym_or] = sym_or,
[sym_equal] = sym_equal, [sym_equal] = sym_equal,
[sym_not_equal] = sym_not_equal, [sym_not_equal] = sym_not_equal,
[sym_parenthesized] = sym_parenthesized, [sym_parenthesized] = sym_parenthesized,
}; };
static const TSSymbolMetadata ts_symbol_metadata[] = { static const TSSymbolMetadata ts_symbol_metadata[] = {
[ts_builtin_sym_end] = { [ts_builtin_sym_end] =
.visible = false, {
.named = true, .visible = false,
}, .named = true,
[sym_identifier] = { },
.visible = true, [sym_identifier] =
.named = true, {
}, .visible = true,
[anon_sym_BANG] = { .named = true,
.visible = true, },
.named = false, [anon_sym_BANG] =
}, {
[anon_sym_AMP_AMP] = { .visible = true,
.visible = true, .named = false,
.named = false, },
}, [anon_sym_AMP_AMP] =
[anon_sym_PIPE_PIPE] = { {
.visible = true, .visible = true,
.named = false, .named = false,
}, },
[anon_sym_EQ_EQ] = { [anon_sym_PIPE_PIPE] =
.visible = true, {
.named = false, .visible = true,
}, .named = false,
[anon_sym_BANG_EQ] = { },
.visible = true, [anon_sym_EQ_EQ] =
.named = false, {
}, .visible = true,
[anon_sym_LPAREN] = { .named = false,
.visible = true, },
.named = false, [anon_sym_BANG_EQ] =
}, {
[anon_sym_RPAREN] = { .visible = true,
.visible = true, .named = false,
.named = false, },
}, [anon_sym_LPAREN] =
[sym_source] = { {
.visible = true, .visible = true,
.named = true, .named = false,
}, },
[sym__expression] = { [anon_sym_RPAREN] =
.visible = false, {
.named = true, .visible = true,
}, .named = false,
[sym_not] = { },
.visible = true, [sym_source] =
.named = true, {
}, .visible = true,
[sym_and] = { .named = true,
.visible = true, },
.named = true, [sym__expression] =
}, {
[sym_or] = { .visible = false,
.visible = true, .named = true,
.named = true, },
}, [sym_not] =
[sym_equal] = { {
.visible = true, .visible = true,
.named = true, .named = true,
}, },
[sym_not_equal] = { [sym_and] =
.visible = true, {
.named = true, .visible = true,
}, .named = true,
[sym_parenthesized] = { },
.visible = true, [sym_or] =
.named = true, {
}, .visible = true,
.named = true,
},
[sym_equal] =
{
.visible = true,
.named = true,
},
[sym_not_equal] =
{
.visible = true,
.named = true,
},
[sym_parenthesized] =
{
.visible = true,
.named = true,
},
}; };
enum { enum {
@ -152,340 +169,378 @@ enum {
field_right = 3, field_right = 3,
}; };
static const char * const ts_field_names[] = { static const char *const ts_field_names[] = {
[0] = NULL, [0] = NULL,
[field_expression] = "expression", [field_expression] = "expression",
[field_left] = "left", [field_left] = "left",
[field_right] = "right", [field_right] = "right",
}; };
static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = {
[1] = {.index = 0, .length = 1}, [1] = {.index = 0, .length = 1},
[2] = {.index = 1, .length = 2}, [2] = {.index = 1, .length = 2},
}; };
static const TSFieldMapEntry ts_field_map_entries[] = { static const TSFieldMapEntry ts_field_map_entries[] = {
[0] = [0] = {field_expression, 1},
{field_expression, 1}, [1] = {field_left, 0},
[1] =
{field_left, 0},
{field_right, 2}, {field_right, 2},
}; };
static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = { static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT]
[0] = {0}, [MAX_ALIAS_SEQUENCE_LENGTH] = {
[0] = {0},
}; };
static const uint16_t ts_non_terminal_alias_map[] = { static const uint16_t ts_non_terminal_alias_map[] = {
0, 0,
}; };
static bool ts_lex(TSLexer *lexer, TSStateId state) { static bool ts_lex(TSLexer *lexer, TSStateId state) {
START_LEXER(); START_LEXER();
eof = lexer->eof(lexer); eof = lexer->eof(lexer);
switch (state) { switch (state) {
case 0: case 0:
if (eof) ADVANCE(7); if (eof)
if (lookahead == '!') ADVANCE(10); ADVANCE(7);
if (lookahead == '&') ADVANCE(2); if (lookahead == '!')
if (lookahead == '(') ADVANCE(15); ADVANCE(10);
if (lookahead == ')') ADVANCE(16); if (lookahead == '&')
if (lookahead == '=') ADVANCE(4); ADVANCE(2);
if (lookahead == '|') ADVANCE(5); if (lookahead == '(')
if (lookahead == '\t' || ADVANCE(15);
lookahead == '\n' || if (lookahead == ')')
lookahead == '\r' || ADVANCE(16);
lookahead == ' ') SKIP(0) if (lookahead == '=')
if (lookahead == '-' || ADVANCE(4);
('0' <= lookahead && lookahead <= '9') || if (lookahead == '|')
('A' <= lookahead && lookahead <= 'Z') || ADVANCE(5);
lookahead == '_' || if (lookahead == '\t' || lookahead == '\n' || lookahead == '\r' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(8); lookahead == ' ')
END_STATE(); SKIP(0)
case 1: if (lookahead == '-' || ('0' <= lookahead && lookahead <= '9') ||
if (lookahead == '!') ADVANCE(9); ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' ||
if (lookahead == '(') ADVANCE(15); ('a' <= lookahead && lookahead <= 'z'))
if (lookahead == '\t' || ADVANCE(8);
lookahead == '\n' || END_STATE();
lookahead == '\r' || case 1:
lookahead == ' ') SKIP(1) if (lookahead == '!')
if (lookahead == '-' || ADVANCE(9);
('0' <= lookahead && lookahead <= '9') || if (lookahead == '(')
('A' <= lookahead && lookahead <= 'Z') || ADVANCE(15);
lookahead == '_' || if (lookahead == '\t' || lookahead == '\n' || lookahead == '\r' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(8); lookahead == ' ')
END_STATE(); SKIP(1)
case 2: if (lookahead == '-' || ('0' <= lookahead && lookahead <= '9') ||
if (lookahead == '&') ADVANCE(11); ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' ||
END_STATE(); ('a' <= lookahead && lookahead <= 'z'))
case 3: ADVANCE(8);
if (lookahead == '=') ADVANCE(14); END_STATE();
END_STATE(); case 2:
case 4: if (lookahead == '&')
if (lookahead == '=') ADVANCE(13); ADVANCE(11);
END_STATE(); END_STATE();
case 5: case 3:
if (lookahead == '|') ADVANCE(12); if (lookahead == '=')
END_STATE(); ADVANCE(14);
case 6: END_STATE();
if (eof) ADVANCE(7); case 4:
if (lookahead == '!') ADVANCE(3); if (lookahead == '=')
if (lookahead == '&') ADVANCE(2); ADVANCE(13);
if (lookahead == ')') ADVANCE(16); END_STATE();
if (lookahead == '=') ADVANCE(4); case 5:
if (lookahead == '|') ADVANCE(5); if (lookahead == '|')
if (lookahead == '\t' || ADVANCE(12);
lookahead == '\n' || END_STATE();
lookahead == '\r' || case 6:
lookahead == ' ') SKIP(6) if (eof)
END_STATE(); ADVANCE(7);
case 7: if (lookahead == '!')
ACCEPT_TOKEN(ts_builtin_sym_end); ADVANCE(3);
END_STATE(); if (lookahead == '&')
case 8: ADVANCE(2);
ACCEPT_TOKEN(sym_identifier); if (lookahead == ')')
if (lookahead == '-' || ADVANCE(16);
('0' <= lookahead && lookahead <= '9') || if (lookahead == '=')
('A' <= lookahead && lookahead <= 'Z') || ADVANCE(4);
lookahead == '_' || if (lookahead == '|')
('a' <= lookahead && lookahead <= 'z')) ADVANCE(8); ADVANCE(5);
END_STATE(); if (lookahead == '\t' || lookahead == '\n' || lookahead == '\r' ||
case 9: lookahead == ' ')
ACCEPT_TOKEN(anon_sym_BANG); SKIP(6)
END_STATE(); END_STATE();
case 10: case 7:
ACCEPT_TOKEN(anon_sym_BANG); ACCEPT_TOKEN(ts_builtin_sym_end);
if (lookahead == '=') ADVANCE(14); END_STATE();
END_STATE(); case 8:
case 11: ACCEPT_TOKEN(sym_identifier);
ACCEPT_TOKEN(anon_sym_AMP_AMP); if (lookahead == '-' || ('0' <= lookahead && lookahead <= '9') ||
END_STATE(); ('A' <= lookahead && lookahead <= 'Z') || lookahead == '_' ||
case 12: ('a' <= lookahead && lookahead <= 'z'))
ACCEPT_TOKEN(anon_sym_PIPE_PIPE); ADVANCE(8);
END_STATE(); END_STATE();
case 13: case 9:
ACCEPT_TOKEN(anon_sym_EQ_EQ); ACCEPT_TOKEN(anon_sym_BANG);
END_STATE(); END_STATE();
case 14: case 10:
ACCEPT_TOKEN(anon_sym_BANG_EQ); ACCEPT_TOKEN(anon_sym_BANG);
END_STATE(); if (lookahead == '=')
case 15: ADVANCE(14);
ACCEPT_TOKEN(anon_sym_LPAREN); END_STATE();
END_STATE(); case 11:
case 16: ACCEPT_TOKEN(anon_sym_AMP_AMP);
ACCEPT_TOKEN(anon_sym_RPAREN); END_STATE();
END_STATE(); case 12:
default: ACCEPT_TOKEN(anon_sym_PIPE_PIPE);
return false; END_STATE();
case 13:
ACCEPT_TOKEN(anon_sym_EQ_EQ);
END_STATE();
case 14:
ACCEPT_TOKEN(anon_sym_BANG_EQ);
END_STATE();
case 15:
ACCEPT_TOKEN(anon_sym_LPAREN);
END_STATE();
case 16:
ACCEPT_TOKEN(anon_sym_RPAREN);
END_STATE();
default:
return false;
} }
} }
static const TSLexMode ts_lex_modes[STATE_COUNT] = { static const TSLexMode ts_lex_modes[STATE_COUNT] = {
[0] = {.lex_state = 0}, [0] = {.lex_state = 0}, [1] = {.lex_state = 1}, [2] = {.lex_state = 1},
[1] = {.lex_state = 1}, [3] = {.lex_state = 1}, [4] = {.lex_state = 1}, [5] = {.lex_state = 1},
[2] = {.lex_state = 1}, [6] = {.lex_state = 6}, [7] = {.lex_state = 0}, [8] = {.lex_state = 0},
[3] = {.lex_state = 1}, [9] = {.lex_state = 0}, [10] = {.lex_state = 0}, [11] = {.lex_state = 0},
[4] = {.lex_state = 1}, [12] = {.lex_state = 0}, [13] = {.lex_state = 0}, [14] = {.lex_state = 0},
[5] = {.lex_state = 1}, [15] = {.lex_state = 0}, [16] = {.lex_state = 0}, [17] = {.lex_state = 0},
[6] = {.lex_state = 6},
[7] = {.lex_state = 0},
[8] = {.lex_state = 0},
[9] = {.lex_state = 0},
[10] = {.lex_state = 0},
[11] = {.lex_state = 0},
[12] = {.lex_state = 0},
[13] = {.lex_state = 0},
[14] = {.lex_state = 0},
[15] = {.lex_state = 0},
[16] = {.lex_state = 0},
[17] = {.lex_state = 0},
}; };
static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[0] = { [0] =
[ts_builtin_sym_end] = ACTIONS(1), {
[sym_identifier] = ACTIONS(1), [ts_builtin_sym_end] = ACTIONS(1),
[anon_sym_BANG] = ACTIONS(1), [sym_identifier] = ACTIONS(1),
[anon_sym_AMP_AMP] = ACTIONS(1), [anon_sym_BANG] = ACTIONS(1),
[anon_sym_PIPE_PIPE] = ACTIONS(1), [anon_sym_AMP_AMP] = ACTIONS(1),
[anon_sym_EQ_EQ] = ACTIONS(1), [anon_sym_PIPE_PIPE] = ACTIONS(1),
[anon_sym_BANG_EQ] = ACTIONS(1), [anon_sym_EQ_EQ] = ACTIONS(1),
[anon_sym_LPAREN] = ACTIONS(1), [anon_sym_BANG_EQ] = ACTIONS(1),
[anon_sym_RPAREN] = ACTIONS(1), [anon_sym_LPAREN] = ACTIONS(1),
}, [anon_sym_RPAREN] = ACTIONS(1),
[1] = { },
[sym_source] = STATE(15), [1] =
[sym__expression] = STATE(13), {
[sym_not] = STATE(13), [sym_source] = STATE(15),
[sym_and] = STATE(13), [sym__expression] = STATE(13),
[sym_or] = STATE(13), [sym_not] = STATE(13),
[sym_equal] = STATE(13), [sym_and] = STATE(13),
[sym_not_equal] = STATE(13), [sym_or] = STATE(13),
[sym_parenthesized] = STATE(13), [sym_equal] = STATE(13),
[sym_identifier] = ACTIONS(3), [sym_not_equal] = STATE(13),
[anon_sym_BANG] = ACTIONS(5), [sym_parenthesized] = STATE(13),
[anon_sym_LPAREN] = ACTIONS(7), [sym_identifier] = ACTIONS(3),
}, [anon_sym_BANG] = ACTIONS(5),
[2] = { [anon_sym_LPAREN] = ACTIONS(7),
[sym__expression] = STATE(7), },
[sym_not] = STATE(7), [2] =
[sym_and] = STATE(7), {
[sym_or] = STATE(7), [sym__expression] = STATE(7),
[sym_equal] = STATE(7), [sym_not] = STATE(7),
[sym_not_equal] = STATE(7), [sym_and] = STATE(7),
[sym_parenthesized] = STATE(7), [sym_or] = STATE(7),
[sym_identifier] = ACTIONS(3), [sym_equal] = STATE(7),
[anon_sym_BANG] = ACTIONS(5), [sym_not_equal] = STATE(7),
[anon_sym_LPAREN] = ACTIONS(7), [sym_parenthesized] = STATE(7),
}, [sym_identifier] = ACTIONS(3),
[3] = { [anon_sym_BANG] = ACTIONS(5),
[sym__expression] = STATE(14), [anon_sym_LPAREN] = ACTIONS(7),
[sym_not] = STATE(14), },
[sym_and] = STATE(14), [3] =
[sym_or] = STATE(14), {
[sym_equal] = STATE(14), [sym__expression] = STATE(14),
[sym_not_equal] = STATE(14), [sym_not] = STATE(14),
[sym_parenthesized] = STATE(14), [sym_and] = STATE(14),
[sym_identifier] = ACTIONS(3), [sym_or] = STATE(14),
[anon_sym_BANG] = ACTIONS(5), [sym_equal] = STATE(14),
[anon_sym_LPAREN] = ACTIONS(7), [sym_not_equal] = STATE(14),
}, [sym_parenthesized] = STATE(14),
[4] = { [sym_identifier] = ACTIONS(3),
[sym__expression] = STATE(11), [anon_sym_BANG] = ACTIONS(5),
[sym_not] = STATE(11), [anon_sym_LPAREN] = ACTIONS(7),
[sym_and] = STATE(11), },
[sym_or] = STATE(11), [4] =
[sym_equal] = STATE(11), {
[sym_not_equal] = STATE(11), [sym__expression] = STATE(11),
[sym_parenthesized] = STATE(11), [sym_not] = STATE(11),
[sym_identifier] = ACTIONS(3), [sym_and] = STATE(11),
[anon_sym_BANG] = ACTIONS(5), [sym_or] = STATE(11),
[anon_sym_LPAREN] = ACTIONS(7), [sym_equal] = STATE(11),
}, [sym_not_equal] = STATE(11),
[5] = { [sym_parenthesized] = STATE(11),
[sym__expression] = STATE(12), [sym_identifier] = ACTIONS(3),
[sym_not] = STATE(12), [anon_sym_BANG] = ACTIONS(5),
[sym_and] = STATE(12), [anon_sym_LPAREN] = ACTIONS(7),
[sym_or] = STATE(12), },
[sym_equal] = STATE(12), [5] =
[sym_not_equal] = STATE(12), {
[sym_parenthesized] = STATE(12), [sym__expression] = STATE(12),
[sym_identifier] = ACTIONS(3), [sym_not] = STATE(12),
[anon_sym_BANG] = ACTIONS(5), [sym_and] = STATE(12),
[anon_sym_LPAREN] = ACTIONS(7), [sym_or] = STATE(12),
}, [sym_equal] = STATE(12),
[sym_not_equal] = STATE(12),
[sym_parenthesized] = STATE(12),
[sym_identifier] = ACTIONS(3),
[anon_sym_BANG] = ACTIONS(5),
[anon_sym_LPAREN] = ACTIONS(7),
},
}; };
static const uint16_t ts_small_parse_table[] = { static const uint16_t ts_small_parse_table[] = {
[0] = 3, [0] = 3,
ACTIONS(11), 1, ACTIONS(11),
anon_sym_EQ_EQ, 1,
ACTIONS(13), 1, anon_sym_EQ_EQ,
anon_sym_BANG_EQ, ACTIONS(13),
ACTIONS(9), 4, 1,
ts_builtin_sym_end, anon_sym_BANG_EQ,
anon_sym_AMP_AMP, ACTIONS(9),
anon_sym_PIPE_PIPE, 4,
anon_sym_RPAREN, ts_builtin_sym_end,
[13] = 1, anon_sym_AMP_AMP,
ACTIONS(15), 4, anon_sym_PIPE_PIPE,
ts_builtin_sym_end, anon_sym_RPAREN,
anon_sym_AMP_AMP, [13] = 1,
anon_sym_PIPE_PIPE, ACTIONS(15),
anon_sym_RPAREN, 4,
[20] = 1, ts_builtin_sym_end,
ACTIONS(17), 4, anon_sym_AMP_AMP,
ts_builtin_sym_end, anon_sym_PIPE_PIPE,
anon_sym_AMP_AMP, anon_sym_RPAREN,
anon_sym_PIPE_PIPE, [20] = 1,
anon_sym_RPAREN, ACTIONS(17),
[27] = 1, 4,
ACTIONS(19), 4, ts_builtin_sym_end,
ts_builtin_sym_end, anon_sym_AMP_AMP,
anon_sym_AMP_AMP, anon_sym_PIPE_PIPE,
anon_sym_PIPE_PIPE, anon_sym_RPAREN,
anon_sym_RPAREN, [27] = 1,
[34] = 1, ACTIONS(19),
ACTIONS(21), 4, 4,
ts_builtin_sym_end, ts_builtin_sym_end,
anon_sym_AMP_AMP, anon_sym_AMP_AMP,
anon_sym_PIPE_PIPE, anon_sym_PIPE_PIPE,
anon_sym_RPAREN, anon_sym_RPAREN,
[41] = 1, [34] = 1,
ACTIONS(23), 4, ACTIONS(21),
ts_builtin_sym_end, 4,
anon_sym_AMP_AMP, ts_builtin_sym_end,
anon_sym_PIPE_PIPE, anon_sym_AMP_AMP,
anon_sym_RPAREN, anon_sym_PIPE_PIPE,
[48] = 2, anon_sym_RPAREN,
ACTIONS(27), 1, [41] = 1,
anon_sym_AMP_AMP, ACTIONS(23),
ACTIONS(25), 3, 4,
ts_builtin_sym_end, ts_builtin_sym_end,
anon_sym_PIPE_PIPE, anon_sym_AMP_AMP,
anon_sym_RPAREN, anon_sym_PIPE_PIPE,
[57] = 3, anon_sym_RPAREN,
ACTIONS(27), 1, [48] = 2,
anon_sym_AMP_AMP, ACTIONS(27),
ACTIONS(29), 1, 1,
ts_builtin_sym_end, anon_sym_AMP_AMP,
ACTIONS(31), 1, ACTIONS(25),
anon_sym_PIPE_PIPE, 3,
[67] = 3, ts_builtin_sym_end,
ACTIONS(27), 1, anon_sym_PIPE_PIPE,
anon_sym_AMP_AMP, anon_sym_RPAREN,
ACTIONS(31), 1, [57] = 3,
anon_sym_PIPE_PIPE, ACTIONS(27),
ACTIONS(33), 1, 1,
anon_sym_RPAREN, anon_sym_AMP_AMP,
[77] = 1, ACTIONS(29),
ACTIONS(35), 1, 1,
ts_builtin_sym_end, ts_builtin_sym_end,
[81] = 1, ACTIONS(31),
ACTIONS(37), 1, 1,
sym_identifier, anon_sym_PIPE_PIPE,
[85] = 1, [67] = 3,
ACTIONS(39), 1, ACTIONS(27),
sym_identifier, 1,
anon_sym_AMP_AMP,
ACTIONS(31),
1,
anon_sym_PIPE_PIPE,
ACTIONS(33),
1,
anon_sym_RPAREN,
[77] = 1,
ACTIONS(35),
1,
ts_builtin_sym_end,
[81] = 1,
ACTIONS(37),
1,
sym_identifier,
[85] = 1,
ACTIONS(39),
1,
sym_identifier,
}; };
static const uint32_t ts_small_parse_table_map[] = { static const uint32_t ts_small_parse_table_map[] = {
[SMALL_STATE(6)] = 0, [SMALL_STATE(6)] = 0, [SMALL_STATE(7)] = 13, [SMALL_STATE(8)] = 20,
[SMALL_STATE(7)] = 13, [SMALL_STATE(9)] = 27, [SMALL_STATE(10)] = 34, [SMALL_STATE(11)] = 41,
[SMALL_STATE(8)] = 20, [SMALL_STATE(12)] = 48, [SMALL_STATE(13)] = 57, [SMALL_STATE(14)] = 67,
[SMALL_STATE(9)] = 27, [SMALL_STATE(15)] = 77, [SMALL_STATE(16)] = 81, [SMALL_STATE(17)] = 85,
[SMALL_STATE(10)] = 34,
[SMALL_STATE(11)] = 41,
[SMALL_STATE(12)] = 48,
[SMALL_STATE(13)] = 57,
[SMALL_STATE(14)] = 67,
[SMALL_STATE(15)] = 77,
[SMALL_STATE(16)] = 81,
[SMALL_STATE(17)] = 85,
}; };
static const TSParseActionEntry ts_parse_actions[] = { static const TSParseActionEntry ts_parse_actions[] = {
[0] = {.entry = {.count = 0, .reusable = false}}, [0] = {.entry = {.count = 0, .reusable = false}},
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(), [1] = {.entry = {.count = 1, .reusable = false}},
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(6), RECOVER(),
[5] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2), [3] = {.entry = {.count = 1, .reusable = true}},
[7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(3), SHIFT(6),
[9] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__expression, 1), [5] = {.entry = {.count = 1, .reusable = true}},
[11] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), SHIFT(2),
[13] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17), [7] = {.entry = {.count = 1, .reusable = true}},
[15] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_not, 2, .production_id = 1), SHIFT(3),
[17] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_equal, 3, .production_id = 2), [9] = {.entry = {.count = 1, .reusable = true}},
[19] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_not_equal, 3, .production_id = 2), REDUCE(sym__expression, 1),
[21] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_parenthesized, 3, .production_id = 1), [11] = {.entry = {.count = 1, .reusable = true}},
[23] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_and, 3, .production_id = 2), SHIFT(16),
[25] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_or, 3, .production_id = 2), [13] = {.entry = {.count = 1, .reusable = true}},
[27] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), SHIFT(17),
[29] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source, 1), [15] = {.entry = {.count = 1, .reusable = true}},
[31] = {.entry = {.count = 1, .reusable = true}}, SHIFT(5), REDUCE(sym_not, 2, .production_id = 1),
[33] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), [17] = {.entry = {.count = 1, .reusable = true}},
[35] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), REDUCE(sym_equal, 3, .production_id = 2),
[37] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8), [19] = {.entry = {.count = 1, .reusable = true}},
[39] = {.entry = {.count = 1, .reusable = true}}, SHIFT(9), REDUCE(sym_not_equal, 3, .production_id = 2),
[21] = {.entry = {.count = 1, .reusable = true}},
REDUCE(sym_parenthesized, 3, .production_id = 1),
[23] = {.entry = {.count = 1, .reusable = true}},
REDUCE(sym_and, 3, .production_id = 2),
[25] = {.entry = {.count = 1, .reusable = true}},
REDUCE(sym_or, 3, .production_id = 2),
[27] = {.entry = {.count = 1, .reusable = true}},
SHIFT(4),
[29] = {.entry = {.count = 1, .reusable = true}},
REDUCE(sym_source, 1),
[31] = {.entry = {.count = 1, .reusable = true}},
SHIFT(5),
[33] = {.entry = {.count = 1, .reusable = true}},
SHIFT(10),
[35] = {.entry = {.count = 1, .reusable = true}},
ACCEPT_INPUT(),
[37] = {.entry = {.count = 1, .reusable = true}},
SHIFT(8),
[39] = {.entry = {.count = 1, .reusable = true}},
SHIFT(9),
}; };
#ifdef __cplusplus #ifdef __cplusplus
@ -497,30 +552,30 @@ extern "C" {
extern const TSLanguage *tree_sitter_context_predicate(void) { extern const TSLanguage *tree_sitter_context_predicate(void) {
static const TSLanguage language = { static const TSLanguage language = {
.version = LANGUAGE_VERSION, .version = LANGUAGE_VERSION,
.symbol_count = SYMBOL_COUNT, .symbol_count = SYMBOL_COUNT,
.alias_count = ALIAS_COUNT, .alias_count = ALIAS_COUNT,
.token_count = TOKEN_COUNT, .token_count = TOKEN_COUNT,
.external_token_count = EXTERNAL_TOKEN_COUNT, .external_token_count = EXTERNAL_TOKEN_COUNT,
.state_count = STATE_COUNT, .state_count = STATE_COUNT,
.large_state_count = LARGE_STATE_COUNT, .large_state_count = LARGE_STATE_COUNT,
.production_id_count = PRODUCTION_ID_COUNT, .production_id_count = PRODUCTION_ID_COUNT,
.field_count = FIELD_COUNT, .field_count = FIELD_COUNT,
.max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH, .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
.parse_table = &ts_parse_table[0][0], .parse_table = &ts_parse_table[0][0],
.small_parse_table = ts_small_parse_table, .small_parse_table = ts_small_parse_table,
.small_parse_table_map = ts_small_parse_table_map, .small_parse_table_map = ts_small_parse_table_map,
.parse_actions = ts_parse_actions, .parse_actions = ts_parse_actions,
.symbol_names = ts_symbol_names, .symbol_names = ts_symbol_names,
.field_names = ts_field_names, .field_names = ts_field_names,
.field_map_slices = ts_field_map_slices, .field_map_slices = ts_field_map_slices,
.field_map_entries = ts_field_map_entries, .field_map_entries = ts_field_map_entries,
.symbol_metadata = ts_symbol_metadata, .symbol_metadata = ts_symbol_metadata,
.public_symbol_map = ts_symbol_map, .public_symbol_map = ts_symbol_map,
.alias_map = ts_non_terminal_alias_map, .alias_map = ts_non_terminal_alias_map,
.alias_sequences = &ts_alias_sequences[0][0], .alias_sequences = &ts_alias_sequences[0][0],
.lex_modes = ts_lex_modes, .lex_modes = ts_lex_modes,
.lex_fn = ts_lex, .lex_fn = ts_lex,
}; };
return &language; return &language;
} }

View File

@ -55,8 +55,8 @@ pub trait Entity: 'static {
pub trait View: Entity + Sized { pub trait View: Entity + Sized {
fn ui_name() -> &'static str; fn ui_name() -> &'static str;
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox; fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox;
fn on_focus(&mut self, _: &mut ViewContext<Self>) {} fn on_focus_in(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {}
fn on_blur(&mut self, _: &mut ViewContext<Self>) {} fn on_focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {}
fn keymap_context(&self, _: &AppContext) -> keymap::Context { fn keymap_context(&self, _: &AppContext) -> keymap::Context {
Self::default_keymap_context() Self::default_keymap_context()
} }
@ -1903,7 +1903,7 @@ impl MutableAppContext {
is_fullscreen: false, is_fullscreen: false,
}, },
); );
root_view.update(this, |view, cx| view.on_focus(cx)); root_view.update(this, |view, cx| view.on_focus_in(cx.handle().into(), cx));
this.open_platform_window(window_id, window_options); this.open_platform_window(window_id, window_options);
(window_id, root_view) (window_id, root_view)
@ -2500,14 +2500,16 @@ impl MutableAppContext {
window.is_active = active; window.is_active = active;
//Handle focus //Handle focus
let view_id = window.focused_view_id?; let focused_id = window.focused_view_id?;
if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) { for view_id in this.parents(window_id, focused_id).collect::<Vec<_>>() {
if active { if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) {
view.on_focus(this, window_id, view_id); if active {
} else { view.on_focus_in(this, window_id, view_id, focused_id);
view.on_blur(this, window_id, view_id); } else {
view.on_focus_out(this, window_id, view_id, focused_id);
}
this.cx.views.insert((window_id, view_id), view);
} }
this.cx.views.insert((window_id, view_id), view);
} }
let mut observations = this.window_activation_observations.clone(); let mut observations = this.window_activation_observations.clone();
@ -2537,26 +2539,45 @@ impl MutableAppContext {
blurred_id blurred_id
}); });
if let Some(blurred_id) = blurred_id { let blurred_parents = blurred_id
if let Some(mut blurred_view) = this.cx.views.remove(&(window_id, blurred_id)) { .map(|blurred_id| this.parents(window_id, blurred_id).collect::<Vec<_>>())
blurred_view.on_blur(this, window_id, blurred_id); .unwrap_or_default();
this.cx.views.insert((window_id, blurred_id), blurred_view); let focused_parents = focused_id
.map(|focused_id| this.parents(window_id, focused_id).collect::<Vec<_>>())
.unwrap_or_default();
let mut subscriptions = this.focus_observations.clone(); if let Some(blurred_id) = blurred_id {
subscriptions for view_id in blurred_parents.iter().copied() {
.emit_and_cleanup(blurred_id, this, |callback, this| callback(false, this)); // We've reached a common anscestor. Break.
if focused_parents.contains(&view_id) {
break;
}
if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) {
view.on_focus_out(this, window_id, view_id, blurred_id);
this.cx.views.insert((window_id, view_id), view);
}
} }
let mut subscriptions = this.focus_observations.clone();
subscriptions
.emit_and_cleanup(blurred_id, this, |callback, this| callback(false, this));
} }
if let Some(focused_id) = focused_id { if let Some(focused_id) = focused_id {
if let Some(mut focused_view) = this.cx.views.remove(&(window_id, focused_id)) { for view_id in focused_parents {
focused_view.on_focus(this, window_id, focused_id); if blurred_parents.contains(&view_id) {
this.cx.views.insert((window_id, focused_id), focused_view); break;
}
let mut subscriptions = this.focus_observations.clone(); if let Some(mut view) = this.cx.views.remove(&(window_id, view_id)) {
subscriptions view.on_focus_in(this, window_id, view_id, focused_id);
.emit_and_cleanup(focused_id, this, |callback, this| callback(true, this)); this.cx.views.insert((window_id, focused_id), view);
}
} }
let mut subscriptions = this.focus_observations.clone();
subscriptions
.emit_and_cleanup(focused_id, this, |callback, this| callback(true, this));
} }
}) })
} }
@ -2742,7 +2763,7 @@ impl ReadView for MutableAppContext {
if let Some(view) = self.cx.views.get(&(handle.window_id, handle.view_id)) { if let Some(view) = self.cx.views.get(&(handle.window_id, handle.view_id)) {
view.as_any().downcast_ref().expect("downcast is type safe") view.as_any().downcast_ref().expect("downcast is type safe")
} else { } else {
panic!("circular view reference"); panic!("circular view reference for type {}", type_name::<T>());
} }
} }
} }
@ -3216,8 +3237,20 @@ pub trait AnyView {
) -> Option<Pin<Box<dyn 'static + Future<Output = ()>>>>; ) -> Option<Pin<Box<dyn 'static + Future<Output = ()>>>>;
fn ui_name(&self) -> &'static str; fn ui_name(&self) -> &'static str;
fn render<'a>(&mut self, params: RenderParams, cx: &mut MutableAppContext) -> ElementBox; fn render<'a>(&mut self, params: RenderParams, cx: &mut MutableAppContext) -> ElementBox;
fn on_focus(&mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize); fn on_focus_in(
fn on_blur(&mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize); &mut self,
cx: &mut MutableAppContext,
window_id: usize,
view_id: usize,
focused_id: usize,
);
fn on_focus_out(
&mut self,
cx: &mut MutableAppContext,
window_id: usize,
view_id: usize,
focused_id: usize,
);
fn keymap_context(&self, cx: &AppContext) -> keymap::Context; fn keymap_context(&self, cx: &AppContext) -> keymap::Context;
fn debug_json(&self, cx: &AppContext) -> serde_json::Value; fn debug_json(&self, cx: &AppContext) -> serde_json::Value;
@ -3242,6 +3275,14 @@ pub trait AnyView {
window_id: usize, window_id: usize,
view_id: usize, view_id: usize,
); );
fn any_handle(&self, window_id: usize, view_id: usize, cx: &AppContext) -> AnyViewHandle {
AnyViewHandle::new(
window_id,
view_id,
self.as_any().type_id(),
cx.ref_counts.clone(),
)
}
} }
impl<T> AnyView for T impl<T> AnyView for T
@ -3275,14 +3316,48 @@ where
View::render(self, &mut RenderContext::new(params, cx)) View::render(self, &mut RenderContext::new(params, cx))
} }
fn on_focus(&mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize) { fn on_focus_in(
&mut self,
cx: &mut MutableAppContext,
window_id: usize,
view_id: usize,
focused_id: usize,
) {
let mut cx = ViewContext::new(cx, window_id, view_id); let mut cx = ViewContext::new(cx, window_id, view_id);
View::on_focus(self, &mut cx); let focused_view_handle: AnyViewHandle = if view_id == focused_id {
cx.handle().into()
} else {
let focused_type = cx
.views
.get(&(window_id, focused_id))
.unwrap()
.as_any()
.type_id();
AnyViewHandle::new(window_id, focused_id, focused_type, cx.ref_counts.clone())
};
View::on_focus_in(self, focused_view_handle, &mut cx);
} }
fn on_blur(&mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize) { fn on_focus_out(
&mut self,
cx: &mut MutableAppContext,
window_id: usize,
view_id: usize,
blurred_id: usize,
) {
let mut cx = ViewContext::new(cx, window_id, view_id); let mut cx = ViewContext::new(cx, window_id, view_id);
View::on_blur(self, &mut cx); let blurred_view_handle: AnyViewHandle = if view_id == blurred_id {
cx.handle().into()
} else {
let blurred_type = cx
.views
.get(&(window_id, blurred_id))
.unwrap()
.as_any()
.type_id();
AnyViewHandle::new(window_id, blurred_id, blurred_type, cx.ref_counts.clone())
};
View::on_focus_out(self, blurred_view_handle, &mut cx);
} }
fn keymap_context(&self, cx: &AppContext) -> keymap::Context { fn keymap_context(&self, cx: &AppContext) -> keymap::Context {
@ -6665,12 +6740,16 @@ mod tests {
"View" "View"
} }
fn on_focus(&mut self, _: &mut ViewContext<Self>) { fn on_focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
self.events.lock().push(format!("{} focused", &self.name)); if cx.handle().id() == focused.id() {
self.events.lock().push(format!("{} focused", &self.name));
}
} }
fn on_blur(&mut self, _: &mut ViewContext<Self>) { fn on_focus_out(&mut self, blurred: AnyViewHandle, cx: &mut ViewContext<Self>) {
self.events.lock().push(format!("{} blurred", &self.name)); if cx.handle().id() == blurred.id() {
self.events.lock().push(format!("{} blurred", &self.name));
}
} }
} }
@ -7018,7 +7097,7 @@ mod tests {
let (window_id, view_1) = cx.add_window(Default::default(), |_| view_1); let (window_id, view_1) = cx.add_window(Default::default(), |_| view_1);
let view_2 = cx.add_view(&view_1, |_| view_2); let view_2 = cx.add_view(&view_1, |_| view_2);
let view_3 = cx.add_view(&view_2, |cx| { cx.add_view(&view_2, |cx| {
cx.focus_self(); cx.focus_self();
view_3 view_3
}); });

View File

@ -4,8 +4,8 @@ use editor::{
}; };
use fuzzy::StringMatch; use fuzzy::StringMatch;
use gpui::{ use gpui::{
actions, elements::*, geometry::vector::Vector2F, AppContext, Entity, MouseState, actions, elements::*, geometry::vector::Vector2F, AnyViewHandle, AppContext, Entity,
MutableAppContext, RenderContext, Task, View, ViewContext, ViewHandle, MouseState, MutableAppContext, RenderContext, Task, View, ViewContext, ViewHandle,
}; };
use language::Outline; use language::Outline;
use ordered_float::OrderedFloat; use ordered_float::OrderedFloat;
@ -52,7 +52,7 @@ impl View for OutlineView {
ChildView::new(self.picker.clone()).boxed() ChildView::new(self.picker.clone()).boxed()
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.picker); cx.focus(&self.picker);
} }
} }

View File

@ -7,8 +7,8 @@ use gpui::{
geometry::vector::{vec2f, Vector2F}, geometry::vector::{vec2f, Vector2F},
keymap, keymap,
platform::CursorStyle, platform::CursorStyle,
AppContext, Axis, Element, ElementBox, Entity, MouseButton, MouseState, MutableAppContext, AnyViewHandle, AppContext, Axis, Element, ElementBox, Entity, MouseButton, MouseState,
RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle, MutableAppContext, RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
}; };
use menu::{Cancel, Confirm, SelectFirst, SelectIndex, SelectLast, SelectNext, SelectPrev}; use menu::{Cancel, Confirm, SelectFirst, SelectIndex, SelectLast, SelectNext, SelectPrev};
use settings::Settings; use settings::Settings;
@ -118,7 +118,7 @@ impl<D: PickerDelegate> View for Picker<D> {
cx cx
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.query_editor); cx.focus(&self.query_editor);
} }
} }

View File

@ -3,8 +3,8 @@ use editor::{
}; };
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, elements::*, AppContext, Entity, ModelHandle, MouseState, MutableAppContext, actions, elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, MouseState,
RenderContext, Task, View, ViewContext, ViewHandle, MutableAppContext, RenderContext, Task, View, ViewContext, ViewHandle,
}; };
use ordered_float::OrderedFloat; use ordered_float::OrderedFloat;
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
@ -51,7 +51,7 @@ impl View for ProjectSymbolsView {
ChildView::new(self.picker.clone()).boxed() ChildView::new(self.picker.clone()).boxed()
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.picker); cx.focus(&self.picker);
} }
} }

View File

@ -6,8 +6,8 @@ use crate::{
use collections::HashMap; use collections::HashMap;
use editor::{Anchor, Autoscroll, Editor}; use editor::{Anchor, Autoscroll, Editor};
use gpui::{ use gpui::{
actions, elements::*, impl_actions, platform::CursorStyle, Action, AppContext, Entity, actions, elements::*, impl_actions, platform::CursorStyle, Action, AnyViewHandle, AppContext,
MouseButton, MutableAppContext, RenderContext, Subscription, Task, View, ViewContext, Entity, MouseButton, MutableAppContext, RenderContext, Subscription, Task, View, ViewContext,
ViewHandle, WeakViewHandle, ViewHandle, WeakViewHandle,
}; };
use language::OffsetRangeExt; use language::OffsetRangeExt;
@ -80,7 +80,7 @@ impl View for BufferSearchBar {
"BufferSearchBar" "BufferSearchBar"
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.query_editor); cx.focus(&self.query_editor);
} }

View File

@ -6,9 +6,9 @@ use crate::{
use collections::HashMap; use collections::HashMap;
use editor::{Anchor, Autoscroll, Editor, MultiBuffer, SelectAll, MAX_TAB_TITLE_LEN}; use editor::{Anchor, Autoscroll, Editor, MultiBuffer, SelectAll, MAX_TAB_TITLE_LEN};
use gpui::{ use gpui::{
actions, elements::*, platform::CursorStyle, Action, AppContext, ElementBox, Entity, actions, elements::*, platform::CursorStyle, Action, AnyViewHandle, AppContext, ElementBox,
ModelContext, ModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription, Task, Entity, ModelContext, ModelHandle, MouseButton, MutableAppContext, RenderContext, Subscription,
View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle, Task, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle,
}; };
use menu::Confirm; use menu::Confirm;
use project::{search::SearchQuery, Project}; use project::{search::SearchQuery, Project};
@ -190,7 +190,7 @@ impl View for ProjectSearchView {
} }
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
let handle = cx.weak_handle(); let handle = cx.weak_handle();
cx.update_global(|state: &mut ActiveSearches, cx| { cx.update_global(|state: &mut ActiveSearches, cx| {
state state

View File

@ -6,7 +6,8 @@ use gpui::{
geometry::vector::Vector2F, geometry::vector::Vector2F,
impl_internal_actions, impl_internal_actions,
keymap::Keystroke, keymap::Keystroke,
AppContext, Element, ElementBox, ModelHandle, MutableAppContext, View, ViewContext, ViewHandle, AnyViewHandle, AppContext, Element, ElementBox, ModelHandle, MutableAppContext, View,
ViewContext, ViewHandle,
}; };
use workspace::pane; use workspace::pane;
@ -190,7 +191,7 @@ impl View for ConnectedView {
.boxed() .boxed()
} }
fn on_focus(&mut self, _cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, _cx: &mut ViewContext<Self>) {
self.has_new_content = false; self.has_new_content = false;
} }

View File

@ -161,6 +161,13 @@ impl Dimensions for TerminalSize {
fn columns(&self) -> usize { fn columns(&self) -> usize {
self.num_columns() self.num_columns()
} }
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.emit(Event::Activate);
cx.defer(|view, cx| {
cx.focus(view.content.handle());
});
}
} }
#[derive(Error, Debug)] #[derive(Error, Debug)]

View File

@ -1,7 +1,7 @@
use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, elements::*, AppContext, Element, ElementBox, Entity, MouseState, MutableAppContext, actions, elements::*, AnyViewHandle, AppContext, Element, ElementBox, Entity, MouseState,
RenderContext, View, ViewContext, ViewHandle, MutableAppContext, RenderContext, View, ViewContext, ViewHandle,
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use settings::Settings; use settings::Settings;
@ -249,7 +249,7 @@ impl View for ThemeSelector {
ChildView::new(self.picker.clone()).boxed() ChildView::new(self.picker.clone()).boxed()
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.picker); cx.focus(&self.picker);
} }
} }

View File

@ -13,9 +13,9 @@ use gpui::{
}, },
impl_actions, impl_internal_actions, impl_actions, impl_internal_actions,
platform::{CursorStyle, NavigationDirection}, platform::{CursorStyle, NavigationDirection},
AppContext, AsyncAppContext, Entity, EventContext, ModelHandle, MouseButton, MouseButtonEvent, AnyViewHandle, AppContext, AsyncAppContext, Entity, EventContext, ModelHandle, MouseButton,
MutableAppContext, PromptLevel, Quad, RenderContext, Task, View, ViewContext, ViewHandle, MouseButtonEvent, MutableAppContext, PromptLevel, Quad, RenderContext, Task, View, ViewContext,
WeakViewHandle, ViewHandle, WeakViewHandle,
}; };
use project::{Project, ProjectEntryId, ProjectPath}; use project::{Project, ProjectEntryId, ProjectPath};
use serde::Deserialize; use serde::Deserialize;
@ -830,6 +830,7 @@ impl Pane {
pub fn focus_active_item(&mut self, cx: &mut ViewContext<Self>) { pub fn focus_active_item(&mut self, cx: &mut ViewContext<Self>) {
if let Some(active_item) = self.active_item() { if let Some(active_item) = self.active_item() {
cx.focus(active_item); cx.focus(active_item);
self.activate(cx);
} }
} }
@ -1210,8 +1211,12 @@ impl View for Pane {
.named("pane") .named("pane")
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
self.focus_active_item(cx); if cx.handle().id() == focused.id() {
self.focus_active_item(cx);
} else {
self.activate(cx);
}
} }
} }

View File

@ -2489,7 +2489,7 @@ impl View for Workspace {
.named("workspace") .named("workspace")
} }
fn on_focus(&mut self, cx: &mut ViewContext<Self>) { fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.focus(&self.active_pane); cx.focus(&self.active_pane);
} }
} }

View File

@ -5,6 +5,7 @@
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "styles",
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {