mirror of
https://github.com/bloeys/gopad.git
synced 2025-12-29 06:58:21 +00:00
Fix bug when opening file on launch
This commit is contained in:
@ -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
26
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() {
|
||||
|
||||
Reference in New Issue
Block a user