Fix bug when opening file on launch

This commit is contained in:
bloeys
2023-02-03 02:51:53 +04:00
parent b0733e9a0c
commit cf20686a43
2 changed files with 11 additions and 17 deletions

View File

@ -496,6 +496,8 @@ func NewEditor(fPath string) *Editor {
FilePath: fPath, FilePath: fPath,
FileContents: string(b), FileContents: string(b),
} }
e.RefreshFontSettings()
e.LinesHead, e.LineCount = ParseLines(e.FileContents) e.LinesHead, e.LineCount = ParseLines(e.FileContents)
return e return e
} }

26
main.go
View File

@ -111,18 +111,10 @@ func (g *Gopad) Init() {
//Read os.Args //Read os.Args
for i := 1; i < len(os.Args); i++ { 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{ e := *NewEditor(os.Args[i])
FileName: filepath.Base(os.Args[i]), g.editors = append(g.editors, e)
FilePath: os.Args[i], g.activeEditor = len(g.editors) - 1
FileContents: string(b),
})
} }
g.activeEditor = len(g.editors) - 1 g.activeEditor = len(g.editors) - 1
@ -171,12 +163,6 @@ func (g *Gopad) Update() {
return return
} }
// Close editors if needed
if g.editorToClose > -1 {
g.closeEditor(g.editorToClose)
g.editorToClose = -1
}
if g.haveErr { if g.haveErr {
g.showErrorPopup() g.showErrorPopup()
} }
@ -448,6 +434,12 @@ func (g *Gopad) handleFileClick(fPath string) {
func (g *Gopad) FrameEnd() { func (g *Gopad) FrameEnd() {
g.newRunes = []rune{} g.newRunes = []rune{}
// Close editors if needed
if g.editorToClose > -1 {
g.closeEditor(g.editorToClose)
g.editorToClose = -1
}
} }
func (g *Gopad) DeInit() { func (g *Gopad) DeInit() {