From 57ad948af1dbdcfac4ebf3521158eadf69902e8f Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 6 Jan 2020 08:36:56 -0800 Subject: [PATCH] mux: add bonus lines to GetTabRenderChangesResponse The server now uses this to send the line content for whichever line the cursor is on, which makes typing latency better. --- src/server/codec.rs | 3 +++ src/server/listener.rs | 11 +++++++++++ src/server/tab.rs | 15 ++++++++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/server/codec.rs b/src/server/codec.rs index 6dedc7556..c94a13b46 100644 --- a/src/server/codec.rs +++ b/src/server/codec.rs @@ -426,6 +426,9 @@ pub struct GetTabRenderChangesResponse { pub dimensions: RenderableDimensions, pub dirty_lines: Vec>, pub title: String, + /// Lines that the server thought we'd almost certainly + /// want to fetch as soon as we received this response + pub bonus_lines: SerializedLines, } #[derive(Deserialize, Serialize, PartialEq, Debug)] diff --git a/src/server/listener.rs b/src/server/listener.rs index f0ce9927a..6b34c35af 100644 --- a/src/server/listener.rs +++ b/src/server/listener.rs @@ -408,6 +408,16 @@ fn maybe_push_tab_changes( let title = tab.get_title(); + let (cursor_line, lines) = tab + .renderer() + .get_lines(cursor_position.y..cursor_position.y + 1); + let bonus_lines = lines + .into_iter() + .enumerate() + .map(|(idx, line)| (cursor_line + idx as StableRowIndex, line)) + .collect::>() + .into(); + sender.send(DecodedPdu { pdu: Pdu::GetTabRenderChangesResponse(GetTabRenderChangesResponse { tab_id, @@ -416,6 +426,7 @@ fn maybe_push_tab_changes( dimensions: dims, cursor_position, title, + bonus_lines, }), serial: 0, })?; diff --git a/src/server/tab.rs b/src/server/tab.rs index 9d6d3583f..3bc876079 100644 --- a/src/server/tab.rs +++ b/src/server/tab.rs @@ -348,20 +348,21 @@ impl RenderableInner { if delta.cursor_position != self.cursor_position { self.dirty_rows.add(self.cursor_position.y); + // But note that the server may have sent this in bonus_lines; + // we'll address that below self.dirty_rows.add(delta.cursor_position.y); - log::trace!( - "cursor move, so dirty {} and {}. to_fetch is {:?}", - self.cursor_position.y, - delta.cursor_position.y, - to_fetch - ); - to_fetch.add(delta.cursor_position.y); } self.cursor_position = delta.cursor_position; self.dimensions = delta.dimensions; self.title = delta.title; + for (stable_row, line) in delta.bonus_lines.lines() { + to_fetch.remove(stable_row); + self.dirty_rows.add(stable_row); + self.lines.put(stable_row, line); + } + self.fetch_lines(to_fetch); }