From 6214d707f3aac89938441171cf7cc0d96517bbe5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= <blaz@mxxn.io>
Date: Mon, 28 Jun 2021 17:52:38 +0900
Subject: [PATCH] fix: Don't panic on Enter on an empty document.

Refs #386
---
 helix-term/src/commands.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 688e653a..f6511ba5 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2511,7 +2511,7 @@ pub mod insert {
             } else {
                 contents.char(pos - 1)
             };
-            let curr = contents.char(pos);
+            let curr = contents.get_char(pos).unwrap_or(' ');
 
             // TODO: offset range.head by 1? when calculating?
             let indent_level = indent::suggested_indent_for_pos(