From e6513cf3c26ed6236dbb74d349e0967e0b3c672a Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 9 Apr 2021 13:48:39 -0400 Subject: [PATCH] Minor code cleanup --- editor/editor.go | 12 ++++-------- editor/input.go | 6 +++--- editor/input_test.go | 5 +++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/editor/editor.go b/editor/editor.go index 91dee01..4dbe1e5 100644 --- a/editor/editor.go +++ b/editor/editor.go @@ -31,14 +31,10 @@ type editor struct { } func NewEditor() *editor { - screen := terminal.Size() - // Subtract rows for status bar and message bar/prompt + screen := terminal.Size() screen.Rows -= 2 - cursor := gilo.DefaultPoint() - offset := gilo.DefaultPoint() - d := document.NewDocument() status := &statusMsg{ "", time.Now(), @@ -46,9 +42,9 @@ func NewEditor() *editor { return &editor{ screen, - cursor, - offset, - d, + gilo.DefaultPoint(), + gilo.DefaultPoint(), + document.NewDocument(), status, newSearch(), gilo.QuitTimes, diff --git a/editor/input.go b/editor/input.go index 1c536cb..5b67cd8 100644 --- a/editor/input.go +++ b/editor/input.go @@ -190,7 +190,7 @@ func parseEscapeSequence() string { for i := 0; i < 2; i++ { ch, size := terminal.ReadKey() if size == 0 { - return string(rune(key.Esc)) + return string(key.Esc) } runes[i] = ch @@ -204,7 +204,7 @@ func parseEscapeSequence() string { } } - return string(rune(key.Esc)) + return string(key.Esc) } func escSeqToKey(seq []rune) string { @@ -255,5 +255,5 @@ func escSeqToKey(seq []rune) string { } } - return string(rune(key.Esc)) + return string(key.Esc) } diff --git a/editor/input_test.go b/editor/input_test.go index 08327d5..f717fdf 100644 --- a/editor/input_test.go +++ b/editor/input_test.go @@ -13,7 +13,7 @@ type moveCursor struct { } var cursorTests = []moveCursor{ - {[]string{string(rune(key.Esc))}, false, gilo.DefaultPoint()}, + {[]string{string(key.Esc)}, false, gilo.DefaultPoint()}, {[]string{keyRight}, true, gilo.NewPoint(1, 0)}, {[]string{keyDown, keyEnd}, true, gilo.NewPoint(14, 1)}, {[]string{keyEnd, keyHome}, true, gilo.DefaultPoint()}, @@ -63,7 +63,8 @@ var seqTests = []seqTest{ {"[6~", keyPageDown}, {"[7~", keyHome}, {"[8~", keyEnd}, - {"OQ", string(rune(key.Esc))}, + {"OQ", string(key.Esc)}, + {"XZ", string(key.Esc)}, } func TestEscToKey(t *testing.T) {