diff --git a/ved.v b/ved.v index 3fa9931..7294221 100644 --- a/ved.v +++ b/ved.v @@ -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 { diff --git a/view.v b/view.v index 897e9c5..259bcd5 100644 --- a/view.v +++ b/view.v @@ -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('.') @@ -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