diff options
author | Pascal Kuthe | 2023-11-21 00:46:12 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2024-03-23 06:35:25 +0000 |
commit | b46064b8c469c85b9626dba60728e23798354ed8 (patch) | |
tree | 203d9698a3e99767202c05e8c62850ea199a2a06 /helix-view | |
parent | 3001f22b315e479dcfc24c7a0fd221d7fb03d276 (diff) |
Add an Amp-like jump command
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/document.rs | 13 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 23 | ||||
-rw-r--r-- | helix-view/src/view.rs | 7 |
3 files changed, 41 insertions, 2 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 090e4dd5..da68a67f 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -8,7 +8,7 @@ use helix_core::chars::char_is_word; use helix_core::doc_formatter::TextFormat; use helix_core::encoding::Encoding; use helix_core::syntax::{Highlight, LanguageServerFeature}; -use helix_core::text_annotations::InlineAnnotation; +use helix_core::text_annotations::{InlineAnnotation, Overlay}; use helix_lsp::util::lsp_pos_to_pos; use helix_vcs::{DiffHandle, DiffProviderRegistry}; @@ -125,6 +125,7 @@ pub struct Document { /// /// To know if they're up-to-date, check the `id` field in `DocumentInlayHints`. pub(crate) inlay_hints: HashMap<ViewId, DocumentInlayHints>, + pub(crate) jump_labels: HashMap<ViewId, Vec<Overlay>>, /// Set to `true` when the document is updated, reset to `false` on the next inlay hints /// update from the LSP pub inlay_hints_oudated: bool, @@ -665,6 +666,7 @@ impl Document { version_control_head: None, focused_at: std::time::Instant::now(), readonly: false, + jump_labels: HashMap::new(), } } @@ -1138,6 +1140,7 @@ impl Document { pub fn remove_view(&mut self, view_id: ViewId) { self.selections.remove(&view_id); self.inlay_hints.remove(&view_id); + self.jump_labels.remove(&view_id); } /// Apply a [`Transaction`] to the [`Document`] to change its text. @@ -1943,6 +1946,14 @@ impl Document { self.inlay_hints.insert(view_id, inlay_hints); } + pub fn set_jump_labels(&mut self, view_id: ViewId, labels: Vec<Overlay>) { + self.jump_labels.insert(view_id, labels); + } + + pub fn remove_jump_labels(&mut self, view_id: ViewId) { + self.jump_labels.remove(&view_id); + } + /// Get the inlay hints for this document and `view_id`. pub fn inlay_hints(&self, view_id: ViewId) -> Option<&DocumentInlayHints> { self.inlay_hints.get(&view_id) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index bad61052..3c530c4e 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -22,7 +22,7 @@ use tokio_stream::wrappers::UnboundedReceiverStream; use std::{ borrow::Cow, cell::Cell, - collections::{BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, HashSet}, fs, io::{self, stdin}, num::NonZeroUsize, @@ -212,6 +212,23 @@ impl Default for FilePickerConfig { } } +fn deserialize_alphabet<'de, D>(deserializer: D) -> Result<Vec<char>, D::Error> +where + D: Deserializer<'de>, +{ + use serde::de::Error; + + let str = String::deserialize(deserializer)?; + let chars: Vec<_> = str.chars().collect(); + let unique_chars: HashSet<_> = chars.iter().copied().collect(); + if unique_chars.len() != chars.len() { + return Err(<D::Error as Error>::custom( + "jump-label-alphabet must contain unique characters", + )); + } + Ok(chars) +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct Config { @@ -305,6 +322,9 @@ pub struct Config { /// Which indent heuristic to use when a new line is inserted #[serde(default)] pub indent_heuristic: IndentationHeuristic, + /// labels characters used in jumpmode + #[serde(skip_serializing, deserialize_with = "deserialize_alphabet")] + pub jump_label_alphabet: Vec<char>, } #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)] @@ -870,6 +890,7 @@ impl Default for Config { smart_tab: Some(SmartTabConfig::default()), popup_border: PopupBorderConfig::None, indent_heuristic: IndentationHeuristic::default(), + jump_label_alphabet: ('a'..='z').collect(), } } } diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index bbdc74a7..b5dc0615 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -415,6 +415,13 @@ impl View { ) -> TextAnnotations<'a> { let mut text_annotations = TextAnnotations::default(); + if let Some(labels) = doc.jump_labels.get(&self.id) { + let style = theme + .and_then(|t| t.find_scope_index("ui.virtual.jump-label")) + .map(Highlight); + text_annotations.add_overlay(labels, style); + } + let DocumentInlayHints { id: _, type_inlay_hints, |