aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/editor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r--helix-view/src/editor.rs104
1 files changed, 95 insertions, 9 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 3ee0325d..9af8e4c3 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -73,6 +73,96 @@ where
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
+pub struct GutterConfig {
+ /// Gutter Layout
+ pub layout: Vec<GutterType>,
+ /// Options specific to the "line-numbers" gutter
+ pub line_numbers: GutterLineNumbersConfig,
+}
+
+impl Default for GutterConfig {
+ fn default() -> Self {
+ Self {
+ layout: vec![
+ GutterType::Diagnostics,
+ GutterType::Spacer,
+ GutterType::LineNumbers,
+ GutterType::Spacer,
+ GutterType::Diff,
+ ],
+ line_numbers: GutterLineNumbersConfig::default(),
+ }
+ }
+}
+
+impl From<Vec<GutterType>> for GutterConfig {
+ fn from(x: Vec<GutterType>) -> Self {
+ GutterConfig {
+ layout: x,
+ ..Default::default()
+ }
+ }
+}
+
+fn deserialize_gutter_seq_or_struct<'de, D>(deserializer: D) -> Result<GutterConfig, D::Error>
+where
+ D: Deserializer<'de>,
+{
+ struct GutterVisitor;
+
+ impl<'de> serde::de::Visitor<'de> for GutterVisitor {
+ type Value = GutterConfig;
+
+ fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
+ write!(
+ formatter,
+ "an array of gutter names or a detailed gutter configuration"
+ )
+ }
+
+ fn visit_seq<S>(self, mut seq: S) -> Result<Self::Value, S::Error>
+ where
+ S: serde::de::SeqAccess<'de>,
+ {
+ let mut gutters = Vec::new();
+ while let Some(gutter) = seq.next_element::<&str>()? {
+ gutters.push(
+ gutter
+ .parse::<GutterType>()
+ .map_err(serde::de::Error::custom)?,
+ )
+ }
+
+ Ok(gutters.into())
+ }
+
+ fn visit_map<M>(self, map: M) -> Result<Self::Value, M::Error>
+ where
+ M: serde::de::MapAccess<'de>,
+ {
+ let deserializer = serde::de::value::MapAccessDeserializer::new(map);
+ Deserialize::deserialize(deserializer)
+ }
+ }
+
+ deserializer.deserialize_any(GutterVisitor)
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
+pub struct GutterLineNumbersConfig {
+ /// Minimum number of characters to use for line number gutter. Defaults to 3.
+ pub min_width: usize,
+}
+
+impl Default for GutterLineNumbersConfig {
+ fn default() -> Self {
+ Self { min_width: 3 }
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct FilePickerConfig {
/// IgnoreOptions
/// Enables ignoring hidden files.
@@ -132,8 +222,8 @@ pub struct Config {
pub cursorline: bool,
/// Highlight the columns cursors are currently on. Defaults to false.
pub cursorcolumn: bool,
- /// Gutters. Default ["diagnostics", "line-numbers"]
- pub gutters: Vec<GutterType>,
+ #[serde(deserialize_with = "deserialize_gutter_seq_or_struct")]
+ pub gutters: GutterConfig,
/// Middle click paste support. Defaults to true.
pub middle_click_paste: bool,
/// Automatic insertion of pairs to parentheses, brackets,
@@ -606,13 +696,7 @@ impl Default for Config {
line_number: LineNumber::Absolute,
cursorline: false,
cursorcolumn: false,
- gutters: vec![
- GutterType::Diagnostics,
- GutterType::Spacer,
- GutterType::LineNumbers,
- GutterType::Spacer,
- GutterType::Diff,
- ],
+ gutters: GutterConfig::default(),
middle_click_paste: true,
auto_pairs: AutoPairConfig::default(),
auto_completion: true,
@@ -844,6 +928,7 @@ impl Editor {
let config = self.config();
self.auto_pairs = (&config.auto_pairs).into();
self.reset_idle_timer();
+ self._refresh();
}
pub fn clear_idle_timer(&mut self) {
@@ -984,6 +1069,7 @@ impl Editor {
for (view, _) in self.tree.views_mut() {
let doc = doc_mut!(self, &view.doc);
view.sync_changes(doc);
+ view.gutters = config.gutters.clone();
view.ensure_cursor_in_view(doc, config.scrolloff)
}
}