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,
FileContents: string(b),
}
e.RefreshFontSettings()
e.LinesHead, e.LineCount = ParseLines(e.FileContents)
return e
}

26
main.go
View File

@ -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() {