Skip to main content

freya_edit/
config.rs

1#[derive(Clone, Copy, PartialEq, Debug)]
2pub struct EditableConfig {
3    pub(crate) indentation: u8,
4    pub(crate) allow_tabs: bool,
5    pub(crate) allow_changes: bool,
6    pub(crate) allow_read_clipboard: bool,
7    pub(crate) allow_write_clipboard: bool,
8}
9
10impl Default for EditableConfig {
11    fn default() -> Self {
12        Self::new()
13    }
14}
15
16impl EditableConfig {
17    /// Create a [`EditableConfig`].
18    pub fn new() -> Self {
19        Self {
20            indentation: 4,
21            allow_tabs: false,
22            allow_changes: true,
23            allow_read_clipboard: true,
24            allow_write_clipboard: true,
25        }
26    }
27
28    /// Specify a custom indentation
29    pub fn with_indentation(mut self, indentation: u8) -> Self {
30        self.indentation = indentation;
31        self
32    }
33
34    /// Specify whether you want to allow tabs to be inserted
35    pub fn with_allow_tabs(mut self, allow_tabs: bool) -> Self {
36        self.allow_tabs = allow_tabs;
37        self
38    }
39
40    /// Allow changes through keyboard events or not
41    pub fn with_allow_changes(mut self, allow_changes: bool) -> Self {
42        self.allow_changes = allow_changes;
43        self
44    }
45
46    /// Allow reading from the clipboard (paste).
47    pub fn with_allow_read_clipboard(mut self, allow_read_clipboard: bool) -> Self {
48        self.allow_read_clipboard = allow_read_clipboard;
49        self
50    }
51
52    /// Allow writing to the clipboard (copy and cut).
53    pub fn with_allow_write_clipboard(mut self, allow_write_clipboard: bool) -> Self {
54        self.allow_write_clipboard = allow_write_clipboard;
55        self
56    }
57}