History

Checkpoint

Antonio Scandurra committed 3 years ago

Commit 98c0e001 parent 3d8e9a52 files · +40 −32Browse files

Unified · Split

2 files
  1. crates/gpui3/src/elements/div.rs +10 −6
  2. crates/gpui3/src/window.rs +30 −26
crates/gpui3/src/elements/div.rs+10−6
@@ -428,15 +428,19 @@ where · 427 unmodified lines
428428 }
429429
430430 let key_listeners = mem::take(&mut self.listeners.key);
431− cx.with_focus(
432− self.focusability.focus_handle().cloned(),
433− &key_listeners,
434− |cx| {
431+ cx.with_key_listeners(&key_listeners, |cx| {
432+ if let Some(focus_handle) = self.focusability.focus_handle().cloned() {
433+ cx.with_focus(focus_handle, |cx| {
434+ for child in &mut self.children {
435+ child.initialize(view_state, cx);
436+ }
437+ })
438+ } else {
435439 for child in &mut self.children {
436440 child.initialize(view_state, cx);
437441 }
438− },
439− );
442+ }
443+ });
440444 self.listeners.key = key_listeners;
441445
442446 element_state.unwrap_or_default()
crates/gpui3/src/window.rs+30−26
@@ -147,7 +147,7 @@ pub struct Window { · 146 unmodified lines
147147 content_mask_stack: Vec<ContentMask<Pixels>>,
148148 mouse_listeners: HashMap<TypeId, Vec<(StackingOrder, AnyListener)>>,
149149 key_listeners: HashMap<TypeId, Vec<AnyListener>>,
150− push_key_listeners: bool,
150+ key_events_enabled: bool,
151151 focus_stack: Vec<FocusId>,
152152 focus_parents_by_child: HashMap<FocusId, FocusId>,
153153 pub(crate) focus_listeners: Vec<AnyFocusListener>,
@@ -220,7 +220,7 @@ impl Window { · 66 unmodified lines
220220 content_mask_stack: Vec::new(),
221221 mouse_listeners: HashMap::default(),
222222 key_listeners: HashMap::default(),
223− push_key_listeners: true,
223+ key_events_enabled: true,
224224 focus_stack: Vec::new(),
225225 focus_parents_by_child: HashMap::default(),
226226 focus_listeners: Vec::new(),
@@ -823,7 +823,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { · 596 unmodified lines
823823 window.focus_listeners.clear();
824824 window.key_listeners.values_mut().for_each(Vec::clear);
825825 window.focus_parents_by_child.clear();
826− window.push_key_listeners = true;
826+ window.key_events_enabled = true;
827827 }
828828
829829 fn end_frame(&mut self) {
@@ -1219,31 +1219,17 @@ impl<'a, 'w, V: Send + Sync + 'static> ViewContext<'a, 'w, V> { · 389 unmodified lines
12191219 }));
12201220 }
12211221
1222− pub fn with_focus<R>(
1222+ pub fn with_key_listeners<R>(
12231223 &mut self,
1224− focus_handle: Option<FocusHandle>,
12251224 key_listeners: &[(TypeId, KeyListener<V>)],
12261225 f: impl FnOnce(&mut Self) -> R,
12271226 ) -> R {
1228− let Some(focus_handle) = focus_handle else {
1229− return f(self);
1230− };
1231−
1232− let handle = self.handle();
1233− let window = &mut *self.window;
1234−
1235− if let Some(parent_focus_id) = window.focus_stack.last() {
1236− window
1237− .focus_parents_by_child
1238− .insert(focus_handle.id, *parent_focus_id);
1239− }
1240− window.focus_stack.push(focus_handle.id);
1241−
1242− if window.push_key_listeners {
1227+ if self.window.key_events_enabled {
1228+ let handle = self.handle();
12431229 for (type_id, listener) in key_listeners {
12441230 let handle = handle.clone();
12451231 let listener = listener.clone();
1246− window
1232+ self.window
12471233 .key_listeners
12481234 .entry(*type_id)
12491235 .or_default()
@@ -1255,17 +1241,35 @@ impl<'a, 'w, V: Send + Sync + 'static> ViewContext<'a, 'w, V> { · 5 unmodified lines
12551241 }
12561242 }
12571243
1258− if Some(focus_handle.id) == window.focus {
1259− window.push_key_listeners = false;
1260− }
1261−
12621244 let result = f(self);
12631245
1264− if self.window.push_key_listeners {
1246+ if self.window.key_events_enabled {
12651247 for (type_id, _) in key_listeners {
12661248 self.window.key_listeners.get_mut(type_id).unwrap().pop();
12671249 }
12681250 }
1251+
1252+ result
1253+ }
1254+
1255+ pub fn with_focus<R>(
1256+ &mut self,
1257+ focus_handle: FocusHandle,
1258+ f: impl FnOnce(&mut Self) -> R,
1259+ ) -> R {
1260+ if let Some(parent_focus_id) = self.window.focus_stack.last().copied() {
1261+ self.window
1262+ .focus_parents_by_child
1263+ .insert(focus_handle.id, parent_focus_id);
1264+ }
1265+ self.window.focus_stack.push(focus_handle.id);
1266+
1267+ if Some(focus_handle.id) == self.window.focus {
1268+ self.window.key_events_enabled = false;
1269+ }
1270+
1271+ let result = f(self);
1272+
12691273 self.window.focus_stack.pop();
12701274 result
12711275 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t