Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/a-A-key-commands #48

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/view.v
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ fn (mut view View) on_key_down(e &tui.Event) {
.w { view.w() }
.b { view.b() }
.o { view.o() }
.a { if e.modifiers == .shift { view.shift_a() } else { view.a() } }
.up { view.k() }
.right { view.l() }
.down { view.j() }
Expand Down Expand Up @@ -1114,6 +1115,16 @@ fn (mut view View) o() {
view.buffer.lines.insert(y+1, "${whitespace_prefix}")
}

fn (mut view View) a() {
view.mode = .insert
defer { view.cursor.pos.x++ }
valxntine marked this conversation as resolved.
Show resolved Hide resolved
}

fn (mut view View) shift_a() {
view.dollar()
view.a()
}

fn (mut view View) enter() {
defer { view.move_cursor_down(1) }
mut x := view.cursor.pos.x
Expand Down
29 changes: 29 additions & 0 deletions src/view_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,32 @@ fn test_calc_b_move_amount_code_line() {
fake_cursor_pos.x -= amount
assert fake_line[fake_cursor_pos.x].ascii_str() == "s"
}

fn test_a_enters_insert_mode_after_cursor_position() {
mut fake_view := View{ log: unsafe { nil }, mode: .normal }

fake_view.buffer.lines = ["single line of text!"]

fake_view.cursor.pos.x = 0

fake_view.a()

assert fake_view.cursor.pos.x == 1
assert fake_view.mode == .insert
}

fn test_shift_a_enters_insert_mode_at_the_end_of_current_line() {
mut fake_view := View{ log: unsafe { nil }, mode: .normal }

fake_view.buffer.lines = ["some line of text", "single line of text!", "a third line!"]

fake_view.cursor.pos.y = 1
// use random starting location, not at the start
fake_view.cursor.pos.x = 3

fake_view.shift_a()

assert fake_view.cursor.pos.x == 20
assert fake_view.cursor.pos.y == 1
assert fake_view.mode == .insert
}
Loading