Skip to content

Commit

Permalink
negative pt in runeAt is weird
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofer committed Nov 18, 2021
1 parent b2b97b2 commit 2ae030c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": 0
},
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${file}"
}
]
}
7 changes: 4 additions & 3 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ func (bp *Buffer) getText() string {
return string(ret)
}

// RuneAt finally reliable!!
// RuneAt finally reliable!! (well, maybe not)
func (bp *Buffer) RuneAt(pt int) (rune, error) {
log.Println("RuneAt pt = ", pt)
if pt >= len(bp.data) {
return 0, errors.New("beyond data buffer in RuneAt")
}
if pt < 0 {
return '\u0000', errors.New("negative buffer pointer in RuneAt")
//return '\u0000', errors.New("negative buffer pointer in RuneAt")
pt = 0
}
if npt := bp.dataPointForBufferPoint(pt); npt < len(bp.data) {
return bp.data[npt], nil
Expand Down Expand Up @@ -325,7 +327,6 @@ func (bp *Buffer) ColumnForPoint(point int) (column int) {
point = bp.TextSize - 1
}
return point - bp.LineStart(point) + 1

}

// XYForPoint returns the cursor location for a pt in the buffer
Expand Down
3 changes: 1 addition & 2 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func (e *Editor) up() {
}
func (e *Editor) down() {
e.CurrentBuffer.PointDown()

}
func (e *Editor) lnbegin() {
e.CurrentBuffer.SetPoint(e.CurrentBuffer.LineStart(e.CurrentBuffer.Point))
Expand Down Expand Up @@ -143,7 +142,7 @@ func (e *Editor) gotoline() {
func (e *Editor) insertfile() {
fname := e.getInput("Insert file: ")
if fname != "" {
res := e.InsertFile(fname, false)
res := e.InsertFile(fname, true)
if res {
e.msg("Loaded file %s", fname)
}
Expand Down
Binary file modified docs/foo
Binary file not shown.
Binary file removed docs/foo1
Binary file not shown.
13 changes: 7 additions & 6 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func (e *Editor) Save(fname string) bool {
}

// LoadFile foo
func (e *Editor) LoadFile(fname string) bool {
return false
}
// func (e *Editor) LoadFile(fname string) bool {
// return false
// }

// InsertFile reads file into buffer at point
func (e *Editor) InsertFile(fname string, modflag bool) bool {
Expand All @@ -58,12 +58,13 @@ func (e *Editor) InsertFile(fname string, modflag bool) bool {
if err != nil {
e.msg("Failed to read and insert file \"%s\".", fname)
}
if modflag == true {
if !modflag { // just do a load into buffer with no modification
bp.setText(string(dat))
} else {
bp.modified = false
} else { // insert into buffer and mark as modified.
bp.Insert(string(dat))
bp.modified = true
}
bp.modified = true
e.msg("File \"%s\" %d bytes read.", fname, len(dat))
return true
}

0 comments on commit 2ae030c

Please sign in to comment.