Allow aborting while opening a file with backup

Also fixes an issue where the abort prompt consumes interrupt signals.

Fixes #2151
This commit is contained in:
Zachary Yedidia
2021-08-02 21:05:22 -04:00
parent 33e064b3b9
commit c315a91fc6
3 changed files with 23 additions and 14 deletions

View File

@@ -250,6 +250,9 @@ func NewBufferFromFileAtLoc(path string, btype BufType, cursorLoc Loc) (*Buffer,
return nil, err
} else {
buf = NewBuffer(file, util.FSize(file), filename, cursorLoc, btype)
if buf == nil {
return nil, errors.New("could not open file")
}
}
if readonly && prompt != nil {
@@ -333,8 +336,12 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
b.Settings["encoding"] = "utf-8"
}
hasBackup = b.ApplyBackup(size)
var ok bool
hasBackup, ok = b.ApplyBackup(size)
if !ok {
return NewBufferFromString("", "", btype)
}
if !hasBackup {
reader := bufio.NewReader(transform.NewReader(r, enc.NewDecoder()))