commit f5a1c3d
delthas
·
2024-07-03 00:01:04 +0000 UTC
parent 4d96ac2
Fix rare panic on Control+E on small windows Fixes: https://todo.sr.ht/~delthas/senpai/144
1 files changed,
+4,
-4
+4,
-4
1@@ -295,7 +295,7 @@ func (e *Editor) Set(text string) {
2 e.bumpOldestChange()
3 e.cursorIdx = len(e.text[e.lineIdx].clusters) - 1
4 e.offsetIdx = 0
5- for e.width < e.textWidth[e.cursorIdx]-e.textWidth[e.offsetIdx]+16 {
6+ for e.offsetIdx < len(e.textWidth)-1 && e.width < e.textWidth[e.cursorIdx]-e.textWidth[e.offsetIdx]+16 {
7 e.offsetIdx++
8 }
9 e.autoCache = nil
10@@ -389,7 +389,7 @@ func (e *Editor) End() {
11 return
12 }
13 e.cursorIdx = len(e.text[e.lineIdx].clusters) - 1
14- for e.width < e.textWidth[e.cursorIdx]-e.textWidth[e.offsetIdx]+16 {
15+ for e.offsetIdx < len(e.textWidth)-1 && e.width < e.textWidth[e.cursorIdx]-e.textWidth[e.offsetIdx]+16 {
16 e.offsetIdx++
17 }
18 e.autoCache = nil
19@@ -449,7 +449,7 @@ func (e *Editor) AutoComplete() (ok bool) {
20 if len(e.textWidth) <= e.offsetIdx {
21 e.offsetIdx = 0
22 }
23- for e.width < e.textWidth[e.cursorIdx]-e.textWidth[e.offsetIdx]+16 {
24+ for e.offsetIdx < len(e.textWidth)-1 && e.width < e.textWidth[e.cursorIdx]-e.textWidth[e.offsetIdx]+16 {
25 e.offsetIdx++
26 }
27 e.autoCache = nil
28@@ -477,7 +477,7 @@ func (e *Editor) backsearchUpdate(start int) {
29 e.recompute()
30 e.setCursor(runeOffset(string(e.text[i].runes), match) + len(e.backsearchPattern))
31 e.offsetIdx = 0
32- for e.width < e.textWidth[e.cursorIdx]-e.textWidth[e.offsetIdx]+16 {
33+ for e.offsetIdx < len(e.textWidth)-1 && e.width < e.textWidth[e.cursorIdx]-e.textWidth[e.offsetIdx]+16 {
34 e.offsetIdx++
35 }
36 e.autoCache = nil