Skip to content

Commit

Permalink
Make initial editing mode configurable
Browse files Browse the repository at this point in the history
ref: helix-editor/helix#3366

Co-authored-by: JJ <git@toki.la>
  • Loading branch information
p-e-w and omentic committed May 1, 2024
1 parent 7cf6502 commit 3ecf200
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Its settings will be merged with the configuration directory `config.toml` and t
| `popup-border` | Draw border around `popup`, `menu`, `all`, or `none` | `none` |
| `indent-heuristic` | How the indentation for a newly inserted line is computed: `simple` just copies the indentation level from the previous line, `tree-sitter` computes the indentation based on the syntax tree and `hybrid` combines both approaches. If the chosen heuristic is not available, a different one will be used as a fallback (the fallback order being `hybrid` -> `tree-sitter` -> `simple`). | `hybrid`
| `jump-label-alphabet` | The characters that are used to generate two character jump labels. Characters at the start of the alphabet are used first. | `"abcdefghijklmnopqrstuvwxyz"`
| `initial-mode` | The initial mode for newly opened editors. | `"normal"` |

### `[editor.statusline]` Section

Expand Down
7 changes: 6 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ pub struct Config {
pub jump_label_alphabet: Vec<char>,
/// Explorer configuration.
pub explorer: ExplorerConfig,
/// The initial mode for newly opened editors. Defaults to `"normal"`.
pub initial_mode: Mode,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -929,6 +931,7 @@ impl Default for Config {
indent_heuristic: IndentationHeuristic::default(),
jump_label_alphabet: ('a'..='z').collect(),
explorer: ExplorerConfig::default(),
initial_mode: Mode::Normal,
}
}
}
Expand Down Expand Up @@ -1504,7 +1507,8 @@ impl Editor {
return;
}

self.enter_normal_mode();
// this causes tree.rs to panic upon launch. todo: debug
// self.enter_normal_mode();

match action {
Action::Replace => {
Expand Down Expand Up @@ -1593,6 +1597,7 @@ impl Editor {

/// 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 =
Expand Down

0 comments on commit 3ecf200

Please sign in to comment.