aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/editor.rs
diff options
context:
space:
mode:
authorwongjiahau2024-05-01 20:42:31 +0000
committerJJ2024-05-01 23:06:08 +0000
commit3bff36ab90aba7de8bb5bff7dbb8230d81cdf582 (patch)
tree733bdb4ff30a35c2212910d48a635ddf4c23b2e3 /helix-view/src/editor.rs
parent2cadec0b1182332338a5a1cc3062776f834d8835 (diff)
Add file explorer and tree helper
ref: https://github.com/helix-editor/helix/issues/200 ref: https://github.com/helix-editor/helix/pull/2377 ref: https://github.com/helix-editor/helix/pull/5566 ref: https://github.com/helix-editor/helix/pull/5768 Co-authored-by: cossonleo <cossonleo@foxmail.com> Co-authored-by: JJ <git@toki.la> Co-authored-by: Quan Tong <quantonganh@gmail.com>
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r--helix-view/src/editor.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index dd360a78..44dd1041 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -231,6 +231,30 @@ where
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
+pub struct ExplorerConfig {
+ pub position: ExplorerPosition,
+ /// explorer column width
+ pub column_width: usize,
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+pub enum ExplorerPosition {
+ Left,
+ Right,
+}
+
+impl Default for ExplorerConfig {
+ fn default() -> Self {
+ Self {
+ position: ExplorerPosition::Left,
+ column_width: 36,
+ }
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct Config {
/// Padding to keep between the edge of the screen and the cursor when scrolling. Defaults to 5.
pub scrolloff: usize,
@@ -325,6 +349,8 @@ pub struct Config {
/// labels characters used in jumpmode
#[serde(skip_serializing, deserialize_with = "deserialize_alphabet")]
pub jump_label_alphabet: Vec<char>,
+ /// Explorer configuration.
+ pub explorer: ExplorerConfig,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
@@ -902,6 +928,7 @@ impl Default for Config {
popup_border: PopupBorderConfig::None,
indent_heuristic: IndentationHeuristic::default(),
jump_label_alphabet: ('a'..='z').collect(),
+ explorer: ExplorerConfig::default(),
}
}
}
@@ -1065,6 +1092,18 @@ pub enum CloseError {
SaveError(anyhow::Error),
}
+impl From<CloseError> for anyhow::Error {
+ fn from(error: CloseError) -> Self {
+ match error {
+ CloseError::DoesNotExist => anyhow::anyhow!("Document doesn't exist"),
+ CloseError::BufferModified(error) => {
+ anyhow::anyhow!(format!("Buffer modified: '{error}'"))
+ }
+ CloseError::SaveError(error) => anyhow::anyhow!(format!("Save error: {error}")),
+ }
+ }
+}
+
impl Editor {
pub fn new(
mut area: Rect,