Fix panic caused by incorrectly constructed empty line

Also be more defensive in draw_screen() about rendering lines.
This commit is contained in:
Kovid Goyal 2023-04-02 10:18:23 +05:30
parent dae49d788e
commit dfa41f01fd
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 17 additions and 19 deletions

View File

@ -685,13 +685,11 @@ func rename_lines(path, other_path string, columns, margin_size int, ans []*Logi
func render(collection *Collection, diff_map map[string]*Patch, screen_size screen_size, largest_line_number int, image_size graphics.Size) (result *LogicalLines, err error) {
margin_size := utils.Max(3, len(strconv.Itoa(largest_line_number))+1)
ans := make([]*LogicalLine, 0, 1024)
empty_line := LogicalLine{line_type: EMPTY_LINE}
columns := screen_size.columns
err = collection.Apply(func(path, item_type, changed_path string) error {
ans = title_lines(path, changed_path, columns, margin_size, ans)
defer func() {
el := empty_line
ans = append(ans, &el)
ans = append(ans, &LogicalLine{line_type: EMPTY_LINE, screen_lines: []*ScreenLine{{}}})
}()
is_binary := !is_path_text(path)

View File

@ -354,26 +354,26 @@ func (self *Handler) draw_screen() {
seen_images := utils.NewSet[int]()
for num_written := 0; num_written < self.screen_size.num_lines; num_written++ {
ll := self.logical_lines.At(pos.logical_line)
if ll == nil {
if ll == nil || self.logical_lines.ScreenLineAt(pos) == nil {
num_written--
continue
}
is_image := ll.line_type == IMAGE_LINE
ll.render_screen_line(pos.screen_line, lp, self.logical_lines.margin_size, self.logical_lines.columns)
if is_image && !seen_images.Has(pos.logical_line) && pos.screen_line >= ll.image_lines_offset {
seen_images.Add(pos.logical_line)
self.draw_image_pair(ll, pos.screen_line-ll.image_lines_offset)
}
if self.current_search != nil {
if mkp := self.current_search.markup_line(pos, num_written); mkp != "" {
} else {
is_image := ll.line_type == IMAGE_LINE
ll.render_screen_line(pos.screen_line, lp, self.logical_lines.margin_size, self.logical_lines.columns)
if is_image && !seen_images.Has(pos.logical_line) && pos.screen_line >= ll.image_lines_offset {
seen_images.Add(pos.logical_line)
self.draw_image_pair(ll, pos.screen_line-ll.image_lines_offset)
}
if self.current_search != nil {
if mkp := self.current_search.markup_line(pos, num_written); mkp != "" {
lp.QueueWriteString(mkp)
}
}
if mkp := self.add_mouse_selection_to_line(pos, num_written); mkp != "" {
lp.QueueWriteString(mkp)
}
lp.MoveCursorVertically(1)
lp.QueueWriteString("\x1b[m\r")
}
if mkp := self.add_mouse_selection_to_line(pos, num_written); mkp != "" {
lp.QueueWriteString(mkp)
}
lp.MoveCursorVertically(1)
lp.QueueWriteString("\x1b[m\r")
if self.logical_lines.IncrementScrollPosBy(&pos, 1) == 0 {
break
}