mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 14:22:42 +09:00
buffer: Store the encoding inside the buffer
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/zyedidia/micro/v2/pkg/highlight"
|
||||
"golang.org/x/text/encoding"
|
||||
"golang.org/x/text/encoding/htmlindex"
|
||||
"golang.org/x/text/encoding/unicode"
|
||||
"golang.org/x/text/transform"
|
||||
@@ -87,6 +88,8 @@ type SharedBuffer struct {
|
||||
// LocalSettings customized by the user for this buffer only
|
||||
LocalSettings map[string]bool
|
||||
|
||||
encoding encoding.Encoding
|
||||
|
||||
Suggestions []string
|
||||
Completions []string
|
||||
CurSuggestion int
|
||||
@@ -337,9 +340,9 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
|
||||
}
|
||||
config.UpdatePathGlobLocals(b.Settings, absPath)
|
||||
|
||||
enc, err := htmlindex.Get(b.Settings["encoding"].(string))
|
||||
b.encoding, err = htmlindex.Get(b.Settings["encoding"].(string))
|
||||
if err != nil {
|
||||
enc = unicode.UTF8
|
||||
b.encoding = unicode.UTF8
|
||||
b.Settings["encoding"] = "utf-8"
|
||||
}
|
||||
|
||||
@@ -350,7 +353,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
|
||||
return NewBufferFromString("", "", btype)
|
||||
}
|
||||
if !hasBackup {
|
||||
reader := bufio.NewReader(transform.NewReader(r, enc.NewDecoder()))
|
||||
reader := bufio.NewReader(transform.NewReader(r, b.encoding.NewDecoder()))
|
||||
|
||||
var ff FileFormat = FFAuto
|
||||
|
||||
|
||||
Reference in New Issue
Block a user