diff --git a/zee/build.rs b/zee/build.rs index 221ee9a..64230e3 100644 --- a/zee/build.rs +++ b/zee/build.rs @@ -11,6 +11,7 @@ static DEFAULT_CONFIG_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/config"); pub struct EditorConfig { #[serde(default)] pub theme: String, + pub indentation_override: Option, pub modes: Vec, #[serde(default)] pub trim_trailing_whitespace_on_save: bool, diff --git a/zee/config/config.ron b/zee/config/config.ron index 926d4f8..6e87866 100644 --- a/zee/config/config.ron +++ b/zee/config/config.ron @@ -7,6 +7,9 @@ // Which colour theme to use. theme: "zee-gruvbox", + // The global indentation override setting + indentation_override: None, + // Remove trailing whitespace on all lines when saving. // Allowed values: `true` or `false` trim_trailing_whitespace_on_save: true, diff --git a/zee/src/components/buffer/mod.rs b/zee/src/components/buffer/mod.rs index 57158b5..96bca37 100644 --- a/zee/src/components/buffer/mod.rs +++ b/zee/src/components/buffer/mod.rs @@ -237,6 +237,7 @@ impl Component for Buffer { // The textarea components that displays text let textarea = TextArea::with(TextAreaProperties { + context: self.properties.context.clone(), theme: self.properties.theme.syntax.clone(), focused: self.properties.focused, text: content.staged().clone(), diff --git a/zee/src/components/buffer/textarea.rs b/zee/src/components/buffer/textarea.rs index 68050ee..9e9e4af 100644 --- a/zee/src/components/buffer/textarea.rs +++ b/zee/src/components/buffer/textarea.rs @@ -17,6 +17,7 @@ use crate::syntax::{ #[derive(Clone)] pub struct Properties { + pub context: crate::editor::ContextHandle, pub theme: SyntaxTheme, pub focused: bool, pub text: Rope, @@ -179,8 +180,13 @@ impl TextArea { scope, is_error, ); - let grapheme_width = - zee_edit::graphemes::width(self.properties.mode.indentation.tab_width(), &grapheme); + let grapheme_width = zee_edit::graphemes::width( + match &self.properties.context.config.indentation_override { + Some(setting) => setting.width, + None => self.properties.mode.indentation.tab_width(), + }, + &grapheme, + ); let horizontal_bounds_inclusive = frame.min_x()..=frame.max_x(); if !horizontal_bounds_inclusive.contains(&(visual_x + grapheme_width)) { break; diff --git a/zee/src/config.rs b/zee/src/config.rs index eef6e96..8d9a3dc 100644 --- a/zee/src/config.rs +++ b/zee/src/config.rs @@ -12,6 +12,7 @@ use crate::error::{Context, Result}; pub struct EditorConfig { #[serde(default)] pub theme: String, + pub indentation_override: Option, pub modes: Vec, /// Remove whitespace from the end of lines when saving. On large files this could negatively /// impact performance. Default: `true`. diff --git a/zee/src/editor/buffer.rs b/zee/src/editor/buffer.rs index 0542ab9..7f65880 100644 --- a/zee/src/editor/buffer.rs +++ b/zee/src/editor/buffer.rs @@ -391,10 +391,20 @@ impl Buffer { CursorMessage::CopySelection => self.copy_selection_to_clipboard(cursor_id), CursorMessage::CutSelection => self.cut_selection_to_clipboard(cursor_id), CursorMessage::InsertTab => { - let (indentation_unit, indentation_count) = ( - self.mode.indentation.to_char(), - self.mode.indentation.char_count(), - ); + let (indentation_unit, indentation_count) = + match &self.context.config.indentation_override { + Some(setting) => ( + setting.unit.to_char(), + match &setting.unit { + zee_grammar::config::IndentationUnit::Space => setting.width, + zee_grammar::config::IndentationUnit::Tab => 1, + }, + ), + None => ( + self.mode.indentation.to_char(), + self.mode.indentation.char_count(), + ), + }; let diff = self.cursors[cursor_id.0].insert_chars( &mut self.content, std::iter::repeat(indentation_unit).take(indentation_count),