From a7dbd419967a1e1880b00bc6f7ed7c80ac102bc9 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 10 Jun 2010 19:43:48 -0400 Subject: [PATCH] Move application of string_expand to draw_text ... fixes bug which truncated long lines to a fixed number of chars. --- NEWS | 1 + tig.c | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 86bad0c..9f44a9f 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,7 @@ Bug fixes: - Status view: fix usage from sub directories, which was broken by the changes made to support blame view from sub directories. + - Fix text expansion to not truncate long lines - Fix parsing of boolean show-date values. - Fix relative date. - Fix unbind to behave as if the keybinding was never defined. diff --git a/tig.c b/tig.c index dd155e3..e5612c1 100644 --- a/tig.c +++ b/tig.c @@ -209,7 +209,7 @@ string_ncopy_do(char *dst, size_t dstlen, const char *src, size_t srclen) #define string_add(dst, from, src) \ string_ncopy_do(dst + (from), sizeof(dst) - (from), src, sizeof(src)) -static void +static size_t string_expand(char *dst, size_t dstlen, const char *src, int tabsize) { size_t size, pos; @@ -228,6 +228,7 @@ string_expand(char *dst, size_t dstlen, const char *src, int tabsize) } dst[size] = 0; + return pos; } static char * @@ -2396,7 +2397,15 @@ draw_space(struct view *view, enum line_type type, int max, int spaces) static bool draw_text(struct view *view, enum line_type type, const char *string, bool trim) { - view->col += draw_chars(view, type, string, view->width + view->yoffset - view->col, trim); + char text[SIZEOF_STR]; + + do { + size_t pos = string_expand(text, sizeof(text), string, opt_tab_size); + + view->col += draw_chars(view, type, text, view->width + view->yoffset - view->col, trim); + string += pos; + } while (*string && view->width + view->yoffset > view->col); + return view->width + view->yoffset <= view->col; } @@ -3984,13 +3993,10 @@ parse_author_line(char *ident, const char **author, struct time *time) static bool pager_draw(struct view *view, struct line *line, unsigned int lineno) { - char text[SIZEOF_STR]; - if (opt_line_number && draw_lineno(view, lineno)) return TRUE; - string_expand(text, sizeof(text), line->data, opt_tab_size); - draw_text(view, line->type, text, TRUE); + draw_text(view, line->type, line->data, TRUE); return TRUE; } @@ -5070,7 +5076,6 @@ blame_draw(struct view *view, struct line *line, unsigned int lineno) struct blame *blame = line->data; struct time *time = NULL; const char *id = NULL, *author = NULL; - char text[SIZEOF_STR]; if (blame->commit && *blame->commit->filename) { id = blame->commit->id; @@ -5090,8 +5095,7 @@ blame_draw(struct view *view, struct line *line, unsigned int lineno) if (draw_lineno(view, lineno)) return TRUE; - string_expand(text, sizeof(text), blame->text, opt_tab_size); - draw_text(view, LINE_DEFAULT, text, TRUE); + draw_text(view, LINE_DEFAULT, blame->text, TRUE); return TRUE; } -- 2.30.2