Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): restore get active at #1076

Merged
merged 3 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions zellij-server/src/panes/floating_panes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
use std::cell::RefCell;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::rc::Rc;
use std::time::Instant;
use zellij_tile::data::{ModeInfo, Palette};
use zellij_utils::pane_size::{Offset, PaneGeom, Size, Viewport};

Expand Down Expand Up @@ -354,6 +355,11 @@ impl FloatingPanes {
}
return false;
}
fn set_pane_active_at(&mut self, pane_id: PaneId) {
if let Some(pane) = self.panes.get_mut(&pane_id) {
pane.set_active_at(Instant::now());
}
}
pub fn move_focus_left(
&mut self,
client_id: ClientId,
Expand Down Expand Up @@ -398,6 +404,7 @@ impl FloatingPanes {
for client_id in connected_clients {
self.focus_pane(p, client_id);
}
self.set_pane_active_at(p);

self.set_force_render();
return true;
Expand All @@ -413,6 +420,7 @@ impl FloatingPanes {
for client_id in connected_clients {
self.focus_pane(updated_active_pane, client_id);
}
self.set_pane_active_at(updated_active_pane);
self.set_force_render();
}
None => {
Expand Down Expand Up @@ -468,6 +476,7 @@ impl FloatingPanes {
self.focus_pane(p, client_id);
}

self.set_pane_active_at(p);
self.set_force_render();
return true;
}
Expand All @@ -482,6 +491,7 @@ impl FloatingPanes {
for client_id in connected_clients {
self.focus_pane(updated_active_pane, client_id);
}
self.set_pane_active_at(updated_active_pane);
self.set_force_render();
}
None => {
Expand Down Expand Up @@ -537,6 +547,7 @@ impl FloatingPanes {
}

self.set_force_render();
self.set_pane_active_at(p);
return true;
}
None => Some(active_pane_id),
Expand All @@ -550,6 +561,7 @@ impl FloatingPanes {
for client_id in connected_clients {
self.focus_pane(updated_active_pane, client_id);
}
self.set_pane_active_at(updated_active_pane);
self.set_force_render();
}
None => {
Expand Down Expand Up @@ -603,6 +615,7 @@ impl FloatingPanes {
for client_id in connected_clients {
self.focus_pane(p, client_id);
}
self.set_pane_active_at(p);

self.set_force_render();
return true;
Expand All @@ -618,6 +631,7 @@ impl FloatingPanes {
for client_id in connected_clients {
self.focus_pane(updated_active_pane, client_id);
}
self.set_pane_active_at(updated_active_pane);
self.set_force_render();
}
None => {
Expand Down Expand Up @@ -709,6 +723,7 @@ impl FloatingPanes {
self.active_panes.insert(client_id, pane_id);
self.z_indices.retain(|p_id| *p_id != pane_id);
self.z_indices.push(pane_id);
self.set_pane_active_at(pane_id);
self.set_force_render();
}
pub fn defocus_pane(&mut self, pane_id: PaneId, client_id: ClientId) {
Expand Down
6 changes: 3 additions & 3 deletions zellij-server/src/panes/plugin_pane.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fmt::Write;
use std::sync::mpsc::channel;
use std::time::Instant;
use std::unimplemented;

use crate::output::CharacterChunk;
use crate::panes::PaneId;
Expand Down Expand Up @@ -106,13 +105,14 @@ impl Pane for PluginPane {
self.should_render = true;
}
fn handle_pty_bytes(&mut self, _event: VteBytes) {
unimplemented!()
// noop
}
fn cursor_coordinates(&self) -> Option<(usize, usize)> {
None
}
fn adjust_input_to_terminal(&self, _input_bytes: Vec<u8>) -> Vec<u8> {
unimplemented!()
// noop
vec![]
}
fn position_and_size(&self) -> PaneGeom {
self.geom
Expand Down
29 changes: 25 additions & 4 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1324,11 +1324,13 @@ impl Tab {
all_terminals.next().is_some()
}
fn next_active_pane(&self, panes: &[PaneId]) -> Option<PaneId> {
panes
let mut panes: Vec<_> = panes
.iter()
.rev()
.find(|pid| self.panes.get(pid).unwrap().selectable())
.copied()
.map(|p_id| self.panes.get(p_id).unwrap())
.collect();
panes.sort_by(|a, b| b.active_at().cmp(&a.active_at()));

panes.iter().find(|pane| pane.selectable()).map(|p| p.pid())
}
pub fn relayout_tab(&mut self, direction: Direction) {
let mut pane_grid = TiledPaneGrid::new(
Expand Down Expand Up @@ -1511,6 +1513,11 @@ impl Tab {
}
}
}
fn set_pane_active_at(&mut self, pane_id: PaneId) {
if let Some(pane) = self.panes.get_mut(&pane_id) {
pane.set_active_at(Instant::now());
}
}

pub fn move_focus(&mut self, client_id: ClientId) {
if !self.has_selectable_panes() {
Expand All @@ -1530,6 +1537,7 @@ impl Tab {
for client_id in connected_clients {
self.active_panes.insert(client_id, next_active_pane_id);
}
self.set_pane_active_at(next_active_pane_id);
}
pub fn focus_next_pane(&mut self, client_id: ClientId) {
if !self.has_selectable_panes() {
Expand All @@ -1549,6 +1557,7 @@ impl Tab {
for client_id in connected_clients {
self.active_panes.insert(client_id, next_active_pane_id);
}
self.set_pane_active_at(next_active_pane_id);
}
pub fn focus_previous_pane(&mut self, client_id: ClientId) {
if !self.has_selectable_panes() {
Expand All @@ -1568,6 +1577,7 @@ impl Tab {
for client_id in connected_clients {
self.active_panes.insert(client_id, next_active_pane_id);
}
self.set_pane_active_at(next_active_pane_id);
}
// returns a boolean that indicates whether the focus moved
pub fn move_focus_left(&mut self, client_id: ClientId) -> bool {
Expand Down Expand Up @@ -1619,6 +1629,7 @@ impl Tab {
} else {
self.active_panes.insert(client_id, p);
}
self.set_pane_active_at(p);

return true;
}
Expand All @@ -1634,6 +1645,7 @@ impl Tab {
for client_id in connected_clients {
self.active_panes.insert(client_id, updated_active_pane);
}
self.set_pane_active_at(updated_active_pane);
}
None => {
// TODO: can this happen?
Expand Down Expand Up @@ -1697,8 +1709,10 @@ impl Tab {
for client_id in connected_clients {
self.active_panes.insert(client_id, updated_active_pane);
}
self.set_pane_active_at(updated_active_pane);
} else {
self.active_panes.insert(client_id, updated_active_pane);
self.set_pane_active_at(updated_active_pane);
}
}
None => {
Expand Down Expand Up @@ -1761,8 +1775,10 @@ impl Tab {
for client_id in connected_clients {
self.active_panes.insert(client_id, updated_active_pane);
}
self.set_pane_active_at(updated_active_pane);
} else {
self.active_panes.insert(client_id, updated_active_pane);
self.set_pane_active_at(updated_active_pane);
}
}
None => {
Expand Down Expand Up @@ -1820,6 +1836,7 @@ impl Tab {
} else {
self.active_panes.insert(client_id, p);
}
self.set_pane_active_at(p);
return true;
}
None => Some(active_pane_id),
Expand All @@ -1836,8 +1853,10 @@ impl Tab {
for client_id in connected_clients {
self.active_panes.insert(client_id, updated_active_pane);
}
self.set_pane_active_at(updated_active_pane);
} else {
self.active_panes.insert(client_id, updated_active_pane);
self.set_pane_active_at(updated_active_pane);
}
}
None => {
Expand Down Expand Up @@ -2468,6 +2487,7 @@ impl Tab {
for client_id in connected_clients {
self.floating_panes.focus_pane(clicked_pane, client_id);
}
self.set_pane_active_at(clicked_pane);
return;
}
}
Expand All @@ -2482,6 +2502,7 @@ impl Tab {
} else {
self.active_panes.insert(client_id, clicked_pane);
}
self.set_pane_active_at(clicked_pane);
if self.floating_panes.panes_are_visible() {
self.floating_panes.toggle_show_panes(false);
self.set_force_render();
Expand Down