Skip to content

Commit

Permalink
Bugfix/clear d count on escape (#61)
Browse files Browse the repository at this point in the history
* fix: reset d count on escape

* fix: block basically all other commands and input during pending deletion
  • Loading branch information
tauraamui authored Nov 9, 2023
1 parent 2204c3e commit 94ebb40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/mode.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum Mode as u8 {
insert
command
search
pending_delete
}

fn (mode Mode) draw(mut ctx tui.Context, x int, y int) int {
Expand All @@ -46,6 +47,7 @@ fn (mode Mode) color() Color {
.insert { status_orange }
.command { status_cyan }
.search { status_purple }
.pending_delete { status_green }
}
}

Expand All @@ -56,6 +58,7 @@ fn (mode Mode) str() string {
.insert { "INSERT" }
.command { "COMMAND" }
.search { "SEARCH" }
.pending_delete { "NORMAL" }
}
}

10 changes: 10 additions & 0 deletions src/view.v
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,13 @@ fn (mut view View) on_key_down(e &tui.Event) {
}
}
}
.pending_delete {
match e.code {
.escape { view.escape() }
.d { view.d() }
else {}
}
}
}
}

Expand Down Expand Up @@ -923,6 +930,7 @@ fn (mut view View) escape() {
view.clamp_cursor_x_pos()
view.cmd_buf.clear()
view.search.clear()
view.d_count = 0

// if current line only contains whitespace prefix clear the line
line := view.buffer.lines[view.cursor.pos.y]
Expand Down Expand Up @@ -1111,13 +1119,15 @@ fn (mut view View) dollar() {

fn (mut view View) d() {
view.d_count += 1
if view.d_count == 1 { view.mode = .pending_delete }
if view.d_count == 2 {
index := if view.cursor.pos.y == view.buffer.lines.len { view.cursor.pos.y - 1 } else { view.cursor.pos.y }
view.y_lines = []string{}
view.y_lines << view.buffer.lines[index]
view.buffer.lines.delete(index)
view.d_count = 0
view.clamp_cursor_within_document_bounds()
view.mode = .normal
}
}

Expand Down

0 comments on commit 94ebb40

Please sign in to comment.