Implement vertical cursor movement
This commit is contained in:
parent
5509673ff3
commit
00ef9c1955
@ -162,22 +162,32 @@ func (self *Readline) move_cursor_right(amt uint, traverse_line_breaks bool) uin
|
|||||||
return amt_moved
|
return amt_moved
|
||||||
}
|
}
|
||||||
|
|
||||||
func move_up_one_line(self *Readline) bool {
|
func (self *Readline) move_cursor_to_target_line(source_line, target_line *ScreenLine) {
|
||||||
return false
|
if source_line != target_line {
|
||||||
|
visual_distance_into_text := source_line.CursorCell - source_line.PromptLen
|
||||||
|
self.cursor.Y = target_line.ParentLineNumber
|
||||||
|
tp := wcswidth.TruncateToVisualLength(target_line.Text, visual_distance_into_text)
|
||||||
|
self.cursor.X = target_line.OffsetInParentLine + len(tp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Readline) move_cursor_up(amt uint) uint {
|
func (self *Readline) move_cursor_vertically(amt int) (ans int) {
|
||||||
ans := uint(0)
|
|
||||||
if self.screen_width == 0 {
|
if self.screen_width == 0 {
|
||||||
self.update_current_screen_size()
|
self.update_current_screen_size()
|
||||||
}
|
}
|
||||||
for ans < amt {
|
screen_lines := self.get_screen_lines()
|
||||||
if move_up_one_line(self) {
|
cursor_line_num := 0
|
||||||
ans++
|
for i, sl := range screen_lines {
|
||||||
} else {
|
if sl.CursorCell > -1 {
|
||||||
|
cursor_line_num = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
target_line_num := (cursor_line_num + amt + len(screen_lines)) % len(screen_lines)
|
||||||
|
ans = target_line_num - cursor_line_num
|
||||||
|
if ans != 0 {
|
||||||
|
self.move_cursor_to_target_line(screen_lines[cursor_line_num], screen_lines[target_line_num])
|
||||||
|
}
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,11 +344,11 @@ func (self *Readline) perform_action(ac Action, repeat_count uint) error {
|
|||||||
case ActionAcceptInput:
|
case ActionAcceptInput:
|
||||||
return ErrAcceptInput
|
return ErrAcceptInput
|
||||||
case ActionCursorUp:
|
case ActionCursorUp:
|
||||||
if self.move_cursor_up(repeat_count) > 0 {
|
if self.move_cursor_vertically(-int(repeat_count)) != 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
case ActionCursorDown:
|
case ActionCursorDown:
|
||||||
if self.move_cursor_down(repeat_count) > 0 {
|
if self.move_cursor_vertically(int(repeat_count)) != 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
case ActionHistoryPreviousOrCursorUp:
|
case ActionHistoryPreviousOrCursorUp:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user