diff options
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/editor.rs | 19 | ||||
-rw-r--r-- | helix-view/src/graphics.rs | 67 | ||||
-rw-r--r-- | helix-view/src/input.rs | 27 | ||||
-rw-r--r-- | helix-view/src/tree.rs | 1 |
4 files changed, 105 insertions, 9 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 8ef4413e..c5a458d7 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -156,6 +156,8 @@ pub struct Config { pub rulers: Vec<u16>, #[serde(default)] pub whitespace: WhitespaceConfig, + /// Vertical indent width guides. + pub indent_guides: IndentGuidesConfig, } #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] @@ -364,6 +366,22 @@ impl Default for WhitespaceCharacters { } } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default)] +pub struct IndentGuidesConfig { + pub render: bool, + pub character: char, +} + +impl Default for IndentGuidesConfig { + fn default() -> Self { + Self { + render: false, + character: '│', + } + } +} + impl Default for Config { fn default() -> Self { Self { @@ -391,6 +409,7 @@ impl Default for Config { lsp: LspConfig::default(), rulers: Vec::new(), whitespace: WhitespaceConfig::default(), + indent_guides: IndentGuidesConfig::default(), } } } diff --git a/helix-view/src/graphics.rs b/helix-view/src/graphics.rs index 6d0a9292..7033b7a4 100644 --- a/helix-view/src/graphics.rs +++ b/helix-view/src/graphics.rs @@ -27,8 +27,61 @@ impl Default for CursorKind { #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Margin {
- pub vertical: u16,
- pub horizontal: u16,
+ pub left: u16,
+ pub right: u16,
+ pub top: u16,
+ pub bottom: u16,
+}
+
+impl Margin {
+ pub fn none() -> Self {
+ Self {
+ left: 0,
+ right: 0,
+ top: 0,
+ bottom: 0,
+ }
+ }
+
+ /// Set uniform margin for all sides.
+ pub fn all(value: u16) -> Self {
+ Self {
+ left: value,
+ right: value,
+ top: value,
+ bottom: value,
+ }
+ }
+
+ /// Set the margin of left and right sides to specified value.
+ pub fn horizontal(value: u16) -> Self {
+ Self {
+ left: value,
+ right: value,
+ top: 0,
+ bottom: 0,
+ }
+ }
+
+ /// Set the margin of top and bottom sides to specified value.
+ pub fn vertical(value: u16) -> Self {
+ Self {
+ left: 0,
+ right: 0,
+ top: value,
+ bottom: value,
+ }
+ }
+
+ /// Get the total width of the margin (left + right)
+ pub fn width(&self) -> u16 {
+ self.left + self.right
+ }
+
+ /// Get the total height of the margin (top + bottom)
+ pub fn height(&self) -> u16 {
+ self.top + self.bottom
+ }
}
/// A simple rectangle used in the computation of the layout and to give widgets an hint about the
@@ -141,14 +194,14 @@ impl Rect { }
pub fn inner(self, margin: &Margin) -> Rect {
- if self.width < 2 * margin.horizontal || self.height < 2 * margin.vertical {
+ if self.width < margin.width() || self.height < margin.height() {
Rect::default()
} else {
Rect {
- x: self.x + margin.horizontal,
- y: self.y + margin.vertical,
- width: self.width - 2 * margin.horizontal,
- height: self.height - 2 * margin.vertical,
+ x: self.x + margin.left,
+ y: self.y + margin.top,
+ width: self.width - margin.width(),
+ height: self.height - margin.height(),
}
}
}
diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 5b867930..093006c4 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -1,6 +1,6 @@ //! Input event handling, currently backed by crossterm. use anyhow::{anyhow, Error}; -use helix_core::unicode::width::UnicodeWidthStr; +use helix_core::unicode::{segmentation::UnicodeSegmentation, width::UnicodeWidthStr}; use serde::de::{self, Deserialize, Deserializer}; use std::fmt; @@ -22,6 +22,31 @@ impl KeyEvent { _ => None, } } + + /// Format the key in such a way that a concatenated sequence + /// of keys can be read easily. + /// + /// ``` + /// # use std::str::FromStr; + /// # use helix_view::input::KeyEvent; + /// + /// let k = KeyEvent::from_str("w").unwrap().key_sequence_format(); + /// assert_eq!(k, "w"); + /// + /// let k = KeyEvent::from_str("C-w").unwrap().key_sequence_format(); + /// assert_eq!(k, "<C-w>"); + /// + /// let k = KeyEvent::from_str(" ").unwrap().key_sequence_format(); + /// assert_eq!(k, "<space>"); + /// ``` + pub fn key_sequence_format(&self) -> String { + let s = self.to_string(); + if s.graphemes(true).count() > 1 { + format!("<{}>", s) + } else { + s + } + } } pub(crate) mod keys { diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index e6dba916..3ba85b56 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -233,7 +233,6 @@ impl Tree { { if let Some(pos) = container.children.iter().position(|&child| child == index) { container.children.remove(pos); - // TODO: if container now only has one child, remove it and place child in parent if container.children.is_empty() && parent_id != self.root { // if container now empty, remove it |