From cf20686a433a54121a0196b9263e8ed87ec64bb9 Mon Sep 17 00:00:00 2001 From: bloeys Date: Fri, 3 Feb 2023 02:51:53 +0400 Subject: [PATCH] Fix bug when opening file on launch --- editor.go | 2 ++ main.go | 26 +++++++++----------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/editor.go b/editor.go index 6015fe1..242a227 100755 --- a/editor.go +++ b/editor.go @@ -496,6 +496,8 @@ func NewEditor(fPath string) *Editor { FilePath: fPath, FileContents: string(b), } + + e.RefreshFontSettings() e.LinesHead, e.LineCount = ParseLines(e.FileContents) return e } diff --git a/main.go b/main.go index 8b82776..689cfb4 100755 --- a/main.go +++ b/main.go @@ -111,18 +111,10 @@ func (g *Gopad) Init() { //Read os.Args for i := 1; i < len(os.Args); i++ { - b, err := os.ReadFile(os.Args[i]) - if err != nil { - errMsg := "Error opening file. Error: " + err.Error() - println(errMsg) - continue - } - g.editors = append(g.editors, Editor{ - FileName: filepath.Base(os.Args[i]), - FilePath: os.Args[i], - FileContents: string(b), - }) + e := *NewEditor(os.Args[i]) + g.editors = append(g.editors, e) + g.activeEditor = len(g.editors) - 1 } g.activeEditor = len(g.editors) - 1 @@ -171,12 +163,6 @@ func (g *Gopad) Update() { return } - // Close editors if needed - if g.editorToClose > -1 { - g.closeEditor(g.editorToClose) - g.editorToClose = -1 - } - if g.haveErr { g.showErrorPopup() } @@ -448,6 +434,12 @@ func (g *Gopad) handleFileClick(fPath string) { func (g *Gopad) FrameEnd() { g.newRunes = []rune{} + + // Close editors if needed + if g.editorToClose > -1 { + g.closeEditor(g.editorToClose) + g.editorToClose = -1 + } } func (g *Gopad) DeInit() {