aboutsummaryrefslogtreecommitdiff
path: root/0001-Make-initial-editing-mode-configurable.patch
blob: 4a8beb40f03c19b108e11c11ad2406068551b8c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
From d3ce6c32f4b4957759209ee6cb215e7968c343e8 Mon Sep 17 00:00:00 2001
From: JJ <git@toki.la>
Date: Sat, 15 Jul 2023 17:40:45 -0700
Subject: [PATCH 1/2] Make initial editing mode configurable

ref: https://github.com/helix-editor/helix/pull/3366
---
 book/src/configuration.md | 1 +
 helix-view/src/editor.rs  | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/book/src/configuration.md b/book/src/configuration.md
index 1b94ae85..b69bb486 100644
--- a/book/src/configuration.md
+++ b/book/src/configuration.md
@@ -59,6 +59,7 @@ ### `[editor]` Section
 | `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative | `false` |
 | `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` |
 | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` |
+| `initial-mode` | The initial mode for newly opened editors. | `"normal"` |
 | `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` |
 | `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` |
 | `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` |
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index affe87dd..3c00a61e 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -281,6 +281,8 @@ pub struct Config {
     pub bufferline: BufferLine,
     /// Vertical indent width guides.
     pub indent_guides: IndentGuidesConfig,
+    /// The initial mode for newly opened editors. Defaults to `"normal"`.
+    pub initial_mode: Mode,
     /// Whether to color modes with different colors. Defaults to `false`.
     pub color_modes: bool,
     pub soft_wrap: SoftWrap,
@@ -812,6 +814,7 @@ fn default() -> Self {
             whitespace: WhitespaceConfig::default(),
             bufferline: BufferLine::default(),
             indent_guides: IndentGuidesConfig::default(),
+            initial_mode: Mode::Normal,
             color_modes: false,
             soft_wrap: SoftWrap {
                 enable: Some(false),
@@ -1363,6 +1366,7 @@ pub fn switch(&mut self, id: DocumentId, action: Action) {
 
     /// Generate an id for a new document and register it.
     fn new_document(&mut self, mut doc: Document) -> DocumentId {
+        self.mode = self.config().initial_mode;
         let id = self.next_document_id;
         // Safety: adding 1 from 1 is fine, probably impossible to reach usize max
         self.next_document_id =
-- 
2.41.0


From 96f81b33f6a1380a4acb5b3ca379e30a0fd29e48 Mon Sep 17 00:00:00 2001
From: JJ <git@toki.la>
Date: Sat, 15 Jul 2023 23:40:55 -0700
Subject: [PATCH 2/2] bandaid for enter_normal_mode panicking upon launch

---
 helix-view/src/editor.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 5fce5446..1d1f6bf7 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -1332,7 +1332,8 @@ pub fn switch(&mut self, id: DocumentId, action: Action) {
             return;
         }
 
-        self.enter_normal_mode();
+        // panics upon launch. todo: debug
+        // self.enter_normal_mode();
 
         match action {
             Action::Replace => {
-- 
2.41.0