From 890b51b568bcbd8fdbe594f5fcda77d82c18288a Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sat, 28 Aug 2021 10:13:19 +0300 Subject: Paginated variables --- helix-term/src/ui/editor.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 92a631ed..4843b9ed 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -711,6 +711,30 @@ impl EditorView { event: KeyEvent, ) -> Option { self.autoinfo = None; + + if cxt.editor.variables.is_some() { + match event { + KeyEvent { + code: KeyCode::Char('h'), + .. + } => { + cxt.editor.variables_page = cxt.editor.variables_page.saturating_sub(1); + } + KeyEvent { + code: KeyCode::Char('l'), + .. + } => { + cxt.editor.variables_page = cxt.editor.variables_page.saturating_add(1); + } + KeyEvent { + code: KeyCode::Esc, .. + } => { + cxt.editor.variables = None; + } + _ => {} + } + return None; + } match self.keymaps.get_mut(&mode).unwrap().get(event) { KeymapResult::Matched(command) => command.execute(cxt), KeymapResult::Pending(node) => self.autoinfo = Some(node.into()), @@ -1084,6 +1108,35 @@ impl Component for EditorView { ); } + if let Some(ref vars) = cx.editor.variables { + let mut text = String::new(); + let mut height = 0; + let mut max_len = 0; + + let per_page = 15; + let num_vars = vars.len(); + let start = (per_page * cx.editor.variables_page).min(num_vars); + let end = (start + per_page).min(num_vars); + for line in vars[start..end].to_vec() { + max_len = max_len.max(line.len() as u16); + height += 1; + text.push_str(&line); + } + + if vars.len() > per_page { + text += "\nMove h, l"; + height += 1; + } + + let mut info = Info { + height: 20.min(height + 2), + width: 70.min(max_len), + title: format!("{} variables", num_vars), + text: text + "\nExit Esc", + }; + info.render(area, surface, cx); + } + if let Some(ref mut info) = self.autoinfo { info.render(area, surface, cx); } -- cgit v1.2.3-70-g09d2