mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 14:55:38 -04:00
action/command: Prevent overwriting settings set locally or by plugin
- on `reload` - on `filetype` change
This commit is contained in:
parent
f661b64e0a
commit
05529596cf
@ -410,7 +410,7 @@ func reloadRuntime(reloadPlugins bool) {
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
config.InitLocalSettings(b.Settings, b.Path)
|
||||
for k, v := range b.Settings {
|
||||
b.SetOptionNative(k, v)
|
||||
b.DoSetOptionNative(k, v)
|
||||
}
|
||||
b.UpdateRules()
|
||||
}
|
||||
@ -610,9 +610,8 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
|
||||
|
||||
// ...at last check the buffer locals
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
if err := b.SetOptionNative(option, nativeValue); err != nil {
|
||||
return err
|
||||
}
|
||||
b.DoSetOptionNative(option, nativeValue)
|
||||
delete(b.LocalSettings, option)
|
||||
}
|
||||
|
||||
return config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
|
||||
|
@ -86,6 +86,8 @@ type SharedBuffer struct {
|
||||
|
||||
// Settings customized by the user
|
||||
Settings map[string]interface{}
|
||||
// LocalSettings customized by the user for this buffer only
|
||||
LocalSettings map[string]bool
|
||||
|
||||
Suggestions []string
|
||||
Completions []string
|
||||
@ -326,6 +328,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
|
||||
// assigning the filetype.
|
||||
settings := config.DefaultCommonSettings()
|
||||
b.Settings = config.DefaultCommonSettings()
|
||||
b.LocalSettings = make(map[string]bool)
|
||||
for k, v := range config.GlobalSettings {
|
||||
if _, ok := config.DefaultGlobalOnlySettings[k]; !ok {
|
||||
// make sure setting is not global-only
|
||||
|
@ -8,13 +8,9 @@ import (
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
)
|
||||
|
||||
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
|
||||
if err := config.OptionIsValid(option, nativeValue); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
|
||||
if reflect.DeepEqual(b.Settings[option], nativeValue) {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
b.Settings[option] = nativeValue
|
||||
@ -46,10 +42,14 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
|
||||
// filetype should not override volatile settings
|
||||
continue
|
||||
}
|
||||
if _, ok := b.LocalSettings[k]; ok {
|
||||
// filetype should not override local settings
|
||||
continue
|
||||
}
|
||||
if _, ok := settings[k]; ok {
|
||||
b.SetOptionNative(k, settings[k])
|
||||
b.DoSetOptionNative(k, settings[k])
|
||||
} else {
|
||||
b.SetOptionNative(k, v)
|
||||
b.DoSetOptionNative(k, v)
|
||||
}
|
||||
}
|
||||
b.UpdateRules()
|
||||
@ -101,6 +101,15 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
|
||||
if b.OptionCallback != nil {
|
||||
b.OptionCallback(option, nativeValue)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
|
||||
if err := config.OptionIsValid(option, nativeValue); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.DoSetOptionNative(option, nativeValue)
|
||||
b.LocalSettings[option] = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user