Fix fileformat

This commit is contained in:
Zachary Yedidia
2019-01-14 23:24:49 -05:00
parent 3380170af8
commit 4a5b759f16
4 changed files with 19 additions and 5 deletions

View File

@@ -163,6 +163,13 @@ func NewBuffer(reader io.Reader, size int64, path string, cursorPosition []strin
b.EventHandler = NewEventHandler(b.SharedBuffer, b.cursors)
}
switch b.Endings {
case FFUnix:
b.Settings["fileformat"] = "unix"
case FFDos:
b.Settings["fileformat"] = "dos"
}
b.Path = path
b.AbsPath = absPath

View File

@@ -53,7 +53,7 @@ type FileFormat byte
// and delete in it
type LineArray struct {
lines []Line
endings FileFormat
Endings FileFormat
initsize uint64
}
@@ -95,11 +95,12 @@ func NewLineArray(size uint64, endings FileFormat, reader io.Reader) *LineArray
if dlen > 1 && data[dlen-2] == '\r' {
data = append(data[:dlen-2], '\n')
if endings == FFAuto {
la.endings = FFDos
la.Endings = FFDos
}
dlen = len(data)
} else if dlen > 0 {
if endings == FFAuto {
la.endings = FFUnix
la.Endings = FFUnix
}
}
@@ -143,7 +144,7 @@ func (la *LineArray) Bytes() []byte {
for i, l := range la.lines {
str = append(str, l.data...)
if i != len(la.lines)-1 {
if la.endings == FFDos {
if la.Endings == FFDos {
str = append(str, '\r')
}
str = append(str, '\n')

View File

@@ -107,7 +107,7 @@ func (b *Buffer) SaveAs(filename string) error {
// end of line
var eol []byte
if b.Settings["fileformat"] == "dos" {
if b.Endings == FFDos {
eol = []byte{'\r', '\n'}
} else {
eol = []byte{'\n'}

View File

@@ -30,6 +30,12 @@ func (b *Buffer) SetOption(option, value string) error {
} else if option == "filetype" {
b.UpdateRules()
} else if option == "fileformat" {
switch b.Settings["fileformat"].(string) {
case "unix":
b.Endings = FFUnix
case "dos":
b.Endings = FFDos
}
b.isModified = true
} else if option == "syntax" {
if !nativeValue.(bool) {