Enable autosave option

The autosave option is now specified as an integer, which denotes
the number of seconds to wait between saving the file. If the option
is 0, then autosaving is disabled. If the option is given by the user
as a boolean, it will be converted to 8 if true, and 0 if false.

Fixes #1479
This commit is contained in:
Zachary Yedidia
2020-02-08 16:53:08 -05:00
parent 8a907956d1
commit 6514b77e0d
4 changed files with 38 additions and 25 deletions

View File

@@ -35,7 +35,7 @@ func init() {
// Options with validators
var optionValidators = map[string]optionValidator{
// "autosave": validateNonNegativeValue,
"autosave": validateNonNegativeValue,
"tabsize": validatePositiveValue,
"scrollmargin": validateNonNegativeValue,
"scrollspeed": validateNonNegativeValue,
@@ -58,6 +58,18 @@ func ReadSettings() error {
if err != nil {
return errors.New("Error reading settings.json: " + err.Error())
}
// check if autosave is a boolean and convert it to float if so
if v, ok := parsedSettings["autosave"]; ok {
s, ok := v.(bool)
if ok {
if s {
parsedSettings["autosave"] = 8.0
} else {
parsedSettings["autosave"] = 0.0
}
}
}
}
}
return nil
@@ -232,7 +244,7 @@ func DefaultCommonSettings() map[string]interface{} {
// a list of settings that should only be globally modified and their
// default values
var defaultGlobalSettings = map[string]interface{}{
// "autosave": float64(0),
"autosave": float64(0),
"colorscheme": "default",
"infobar": true,
"keymenu": false,