Skip to content

Commit

Permalink
view.h()
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Oct 22, 2023
1 parent da0c352 commit c2966a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ved.v
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,8 @@ fn (mut ved Ved) key_normal(key gg.KeyCode, mod gg.Modifier) {
.h {
if shift {
ved.view.shift_h()
} else if ved.view.x > 0 {
ved.view.x--
} else {
ved.view.h()
}
}
.l {
Expand Down
14 changes: 14 additions & 0 deletions view.v
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ fn (mut view View) open_file(path string, line_nr int) {
view.move_to_line(line_nr)
}

view.l()
view.h() // so that cursor pos is correct and doesn't point to no longer existing text

view.hash_comment = !view.path.ends_with('.v')
view.hl_on = !view.path.ends_with('.md') && !view.path.ends_with('.txt')
&& view.path.contains('.')
Expand Down Expand Up @@ -301,6 +304,17 @@ fn (mut view View) l() {
}
}

fn (mut view View) h() {
if view.x > 0 {
view.x--
}
line := view.line()
// Cursor is outside the line, move it to the end of it
if view.x > line.len {
view.x = line.len
}
}

fn (mut view View) shift_g() {
view.y = view.lines.len - 1
view.from = view.y - view.page_height + 1
Expand Down

0 comments on commit c2966a7

Please sign in to comment.