Link Here
|
1 |
From f17fb682573985656fa26bf10370b9e1d88e3bdf Mon Sep 17 00:00:00 2001 |
2 |
From: ailin-nemui <ailin-nemui@users.noreply.github.com> |
3 |
Date: Sat, 18 Jun 2022 12:42:47 +0200 |
4 |
Subject: [PATCH] Merge pull request #1387 from ailin-nemui/textbufferview |
5 |
|
6 |
Textbufferview |
7 |
|
8 |
(cherry picked from commit 783dd375339c1c98be36e277d47afdd6918d6160) |
9 |
--- |
10 |
src/fe-text/textbuffer-commands.c | 1 + |
11 |
src/fe-text/textbuffer-view.c | 54 +++++++++++++++++++------------ |
12 |
3 files changed, 37 insertions(+), 24 deletions(-) |
13 |
|
14 |
diff --git a/src/fe-text/textbuffer-commands.c b/src/fe-text/textbuffer-commands.c |
15 |
index f30eab0e06..6ed7c39c51 100644 |
16 |
--- src/fe-text/textbuffer-commands.c |
17 |
+++ src/fe-text/textbuffer-commands.c |
18 |
@@ -393,6 +393,7 @@ static void cmd_scrollback_redraw(void) |
19 |
|
20 |
term_refresh_freeze(); |
21 |
textbuffer_view_reset_cache(gui->view); |
22 |
+ textbuffer_view_resize(gui->view, gui->view->width, gui->view->height); |
23 |
gui_window_redraw(active_win); |
24 |
term_refresh_thaw(); |
25 |
} |
26 |
diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c |
27 |
index 79f3522c85..2cc6ce6dde 100644 |
28 |
--- src/fe-text/textbuffer-view.c |
29 |
+++ src/fe-text/textbuffer-view.c |
30 |
@@ -402,10 +402,9 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line) |
31 |
|
32 |
if (rec->count > 1) { |
33 |
for (pos = 0; lines != NULL; pos++) { |
34 |
- void *data = lines->data; |
35 |
+ LINE_CACHE_SUB_REC *data = lines->data; |
36 |
|
37 |
- memcpy(&rec->lines[pos], data, |
38 |
- sizeof(LINE_CACHE_SUB_REC)); |
39 |
+ memcpy(&rec->lines[pos], data, sizeof(LINE_CACHE_SUB_REC)); |
40 |
|
41 |
lines = g_slist_remove(lines, data); |
42 |
g_free(data); |
43 |
@@ -427,7 +426,7 @@ static void view_remove_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, |
44 |
|
45 |
cache = g_hash_table_lookup(view->cache->line_cache, line); |
46 |
if (cache != NULL) { |
47 |
- g_free(cache); |
48 |
+ line_cache_destroy(NULL, cache); |
49 |
g_hash_table_remove(view->cache->line_cache, line); |
50 |
} |
51 |
} |
52 |
@@ -438,7 +437,7 @@ static void view_update_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, |
53 |
view_remove_cache(view, line, update_counter); |
54 |
|
55 |
if (view->buffer->cur_line == line) |
56 |
- view->cache->last_linecount = view_get_linecount(view, line); |
57 |
+ view_get_linecount(view, line); |
58 |
} |
59 |
|
60 |
void textbuffer_view_reset_cache(TEXT_BUFFER_VIEW_REC *view) |
61 |
@@ -467,6 +466,7 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, |
62 |
unichar chr; |
63 |
int xpos, color, drawcount, first, need_move, need_clrtoeol, char_width; |
64 |
unsigned int fg24, bg24; |
65 |
+ fg24 = bg24 = UINT_MAX; |
66 |
|
67 |
if (view->dirty) /* don't bother drawing anything - redraw is coming */ |
68 |
return 0; |
69 |
@@ -767,7 +767,6 @@ static void view_unregister_indent_func(TEXT_BUFFER_VIEW_REC *view, |
70 |
/* recreate cache so it won't contain references |
71 |
to the indent function */ |
72 |
textbuffer_view_reset_cache(view); |
73 |
- view->cache = textbuffer_cache_get(view->siblings, view->width); |
74 |
} |
75 |
|
76 |
void textbuffer_views_unregister_indent_func(INDENT_FUNC indent_func) |
77 |
@@ -1033,13 +1032,17 @@ void textbuffer_view_clear(TEXT_BUFFER_VIEW_REC *view) |
78 |
/* Scroll the view up/down */ |
79 |
void textbuffer_view_scroll(TEXT_BUFFER_VIEW_REC *view, int lines) |
80 |
{ |
81 |
- int count; |
82 |
+ int count, ypos; |
83 |
|
84 |
- g_return_if_fail(view != NULL); |
85 |
+ g_return_if_fail(view != NULL); |
86 |
+ |
87 |
+ count = view_scroll(view, &view->startline, &view->subline, lines, TRUE); |
88 |
+ |
89 |
+ ypos = view->ypos + (lines < 0 ? count : -count); |
90 |
+ textbuffer_view_init_ypos(view); |
91 |
+ if (ypos != view->ypos) |
92 |
+ textbuffer_view_resize(view, view->width, view->height); |
93 |
|
94 |
- count = view_scroll(view, &view->startline, &view->subline, |
95 |
- lines, TRUE); |
96 |
- view->ypos += lines < 0 ? count : -count; |
97 |
view->bottom = view_is_bottom(view); |
98 |
if (view->bottom) view->more_text = FALSE; |
99 |
|
100 |
@@ -1079,10 +1082,10 @@ LINE_CACHE_REC *textbuffer_view_get_line_cache(TEXT_BUFFER_VIEW_REC *view, |
101 |
cache = g_hash_table_lookup(view->cache->line_cache, line); |
102 |
if (cache == NULL) |
103 |
cache = view_update_line_cache(view, line); |
104 |
- else |
105 |
+ else |
106 |
cache->last_access = time(NULL); |
107 |
|
108 |
- return cache; |
109 |
+ return cache; |
110 |
} |
111 |
|
112 |
static void view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line) |
113 |
@@ -1263,12 +1266,13 @@ static void view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, |
114 |
view_bookmarks_check(view, line); |
115 |
|
116 |
if (view->buffer->cur_line == line) { |
117 |
- /* the last line is being removed */ |
118 |
+ /* the last line is being removed */ |
119 |
LINE_REC *prevline; |
120 |
|
121 |
- prevline = view->buffer->first_line == line ? NULL : |
122 |
- textbuffer_line_last(view->buffer)->prev; |
123 |
- view->cache->last_linecount = prevline == NULL ? 0 : |
124 |
+ prevline = view->buffer->first_line == line ? |
125 |
+ NULL : |
126 |
+ textbuffer_line_last(view->buffer)->prev; |
127 |
+ if (prevline != NULL) |
128 |
view_get_linecount(view, prevline); |
129 |
} |
130 |
|
131 |
@@ -1474,8 +1478,10 @@ void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view, |
132 |
|
133 |
if (view->window != window) { |
134 |
view->window = window; |
135 |
- if (window != NULL) |
136 |
+ if (window != NULL) { |
137 |
+ textbuffer_view_resize(view, view->width, view->height); |
138 |
view->dirty = TRUE; |
139 |
+ } |
140 |
} |
141 |
} |
142 |
|
143 |
@@ -1504,12 +1510,18 @@ static int line_cache_check_remove(void *key, LINE_CACHE_REC *cache, |
144 |
static int sig_check_linecache(void) |
145 |
{ |
146 |
GSList *tmp, *caches; |
147 |
- time_t now; |
148 |
+ time_t now; |
149 |
|
150 |
- now = time(NULL); caches = NULL; |
151 |
+ now = time(NULL); |
152 |
+ caches = NULL; |
153 |
for (tmp = views; tmp != NULL; tmp = tmp->next) { |
154 |
TEXT_BUFFER_VIEW_REC *rec = tmp->data; |
155 |
|
156 |
+ if (rec->window != NULL) { |
157 |
+ /* keep visible lines mapped */ |
158 |
+ view_get_lines_height(rec, rec->startline, rec->subline, NULL); |
159 |
+ } |
160 |
+ |
161 |
if (g_slist_find(caches, rec->cache) != NULL) |
162 |
continue; |
163 |
|
164 |
@@ -1519,7 +1531,7 @@ static int sig_check_linecache(void) |
165 |
&now); |
166 |
} |
167 |
|
168 |
- g_slist_free(caches); |
169 |
+ g_slist_free(caches); |
170 |
return 1; |
171 |
} |
172 |
|