Skip to content

Commit

Permalink
Fixed dd command
Browse files Browse the repository at this point in the history
Finally fixed the `<n>dd` command so that it deletes the correct number of
lines and doesn't leave a character straggling when there's no modifier, making
progress towards addressing issue #1.
  • Loading branch information
driusan committed Jun 19, 2016
1 parent 17077ce commit c1dcab8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions kbmap/deletemode.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ func deleteMap(e key.Event, buff *demodel.CharBuffer, v demodel.Viewport) (demod
case key.CodeD:
// don't need to handle Repeat = 0 case, because the first movement will
// take care of it.
actions.MoveCursor(position.StartOfLine, position.EndOfLine, buff)
actions.MoveCursor(position.StartOfLine, position.DotEnd, buff)
for ; Repeat > 0; Repeat-- {
actions.MoveCursor(position.DotStart, position.NextLine, buff)
}
actions.DeleteCursor(position.DotStart, position.DotEnd, buff)
actions.DeleteCursor(position.DotStart, position.EndOfLineWithNewline, buff)
buff.Undo.Dot = undoDot
return NormalMode, demodel.DirectionUp, nil
}
Expand Down
8 changes: 6 additions & 2 deletions kbmap/normalmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,15 @@ func normalMap(e key.Event, buff *demodel.CharBuffer, v demodel.Viewport) (demod
// better to stop now.
if lineNo >= Repeat {
// we're on the \n itself, so add 1 to get to the actual line.
buff.Dot.Start = uint(i + 1)
if Repeat == 1 {
buff.Dot.Start = 0
} else {
buff.Dot.Start = uint(i + 1)
}
buff.Dot.End = buff.Dot.Start
Repeat = 0
// select the line.
actions.MoveCursor(position.DotStart, position.EndOfLineWithNewline, buff)
actions.MoveCursor(position.DotStart, position.EndOfLine, buff)
break
}
}
Expand Down
6 changes: 3 additions & 3 deletions position/positions.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func EndOfLine(buff demodel.CharBuffer) (uint, error) {
}
for i := buff.Dot.End; i < uint(len(buff.Buffer)); i++ {
if buff.Buffer[i] == '\n' {
return i - 1, nil
return i, nil
}
}
return uint(len(buff.Buffer) - 1), nil
Expand All @@ -213,11 +213,11 @@ func EndOfLineWithNewline(buff demodel.CharBuffer) (uint, error) {
}

if buff.Buffer[buff.Dot.End] == '\n' {
return buff.Dot.End, nil
return buff.Dot.End + 1, nil
}
for i := buff.Dot.End; i < uint(len(buff.Buffer)); i++ {
if buff.Buffer[i] == '\n' {
return i, nil
return i + 1, nil
}
}
return uint(len(buff.Buffer) - 1), nil
Expand Down

0 comments on commit c1dcab8

Please sign in to comment.