UpdateRules: fix set filetype unknown
Fix `set filetype unknown` not working as expected in the following scenario: 1. open foo.txt (no filetype detected) -> ft is `unknown`, highlighted with default.yaml, as expected 2. `set filetype go` -> ft is `go`, highlighted with go.yaml as expected 3. `set filetype unknown` -> ft is still `go`, still highlighted with go.yaml (whereas expected behavior is: ft is `unknown`, highlighted with default.yaml) Fix that by always updating b.SyntaxDef value, not reusing the old one. This also makes the code simpler and easier to understand.
This commit is contained in:
parent
0806addbd7
commit
5610d01e08
1 changed files with 10 additions and 10 deletions
|
@ -753,6 +753,8 @@ func (b *Buffer) UpdateRules() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.SyntaxDef = nil
|
||||||
|
|
||||||
// syntaxFileInfo is an internal helper structure
|
// syntaxFileInfo is an internal helper structure
|
||||||
// to store properties of one single syntax file
|
// to store properties of one single syntax file
|
||||||
type syntaxFileInfo struct {
|
type syntaxFileInfo struct {
|
||||||
|
@ -945,7 +947,6 @@ func (b *Buffer) UpdateRules() {
|
||||||
highlight.ResolveIncludes(b.SyntaxDef, files)
|
highlight.ResolveIncludes(b.SyntaxDef, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Highlighter == nil || syntaxFile != "" {
|
|
||||||
if b.SyntaxDef != nil {
|
if b.SyntaxDef != nil {
|
||||||
b.Settings["filetype"] = b.SyntaxDef.FileType
|
b.Settings["filetype"] = b.SyntaxDef.FileType
|
||||||
} else {
|
} else {
|
||||||
|
@ -956,7 +957,6 @@ func (b *Buffer) UpdateRules() {
|
||||||
b.SyntaxDef = findRuntimeSyntaxDef("default", nil)
|
b.SyntaxDef = findRuntimeSyntaxDef("default", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if b.SyntaxDef != nil {
|
if b.SyntaxDef != nil {
|
||||||
b.Highlighter = highlight.NewHighlighter(b.SyntaxDef)
|
b.Highlighter = highlight.NewHighlighter(b.SyntaxDef)
|
||||||
|
|
Loading…
Reference in a new issue