jcs
/textview
/amendments
/89
TVAppendLocked: Remember the first line touched
When we're running with autocalc off, this will speed up redrawing
when it's turned back on.
jcs made amendment 89 22 days ago
--- textview.c Fri Oct 30 20:34:08 2026
+++ textview.c Mon Nov 2 22:02:55 2026
@@ -194,6 +194,11 @@ TVAutoCalc(TVHandle tvh, Boolean calc)
tv = TVLock(tvh);
tv->autocalc = calc;
+ if (calc && tv->pending_redraw) {
+ tv->pending_redraw = false;
+ TVRedrawAppendLocked(tv, tv->pending_from_line,
+ tv->pending_from_end);
+ }
TVUnlock(tv);
}
@@ -363,6 +368,7 @@ TVClear(TVHandle tvh)
tv->sel_start = 0;
tv->sel_end = 0;
tv->click_count = 0;
+ tv->pending_redraw = false;
/* clear line groups except first one */
for (n = 1; n < sizeof(tv->line_groups) / sizeof(tv->line_groups[0]);
@@ -481,12 +487,9 @@ TVAppendLocked(struct TVRec *tv, struct TVStyle *style
struct TVSlab *text_slab;
struct TVChunk *chunk, *prev_chunk;
struct TVStyle *cur_style;
- struct TVLine *fromline, *toline;
+ struct TVLine *fromline;
Handle text_slabh;
- RgnHandle vacated;
- BigRect redraw;
- Rect r;
- unsigned long avail, wastop, fromend;
+ unsigned long avail, fromnline, fromend;
TVSlabLocator prev_style, prev_chunk_loc;
char *text_slab_data;
Boolean new_chunk;
@@ -498,7 +501,8 @@ TVAppendLocked(struct TVRec *tv, struct TVStyle *style
return false;
new_chunk = false;
- fromline = TVGetLine(tv, tv->nlines);
+ fromnline = tv->nlines;
+ fromline = TVGetLine(tv, fromnline);
fromend = fromline ? fromline->end : 0;
/* setup style */
@@ -565,12 +569,39 @@ TVAppendLocked(struct TVRec *tv, struct TVStyle *style
chunk->need_recalc = true;
}
- if (!tv->autocalc)
+ if (!tv->autocalc) {
+ if (!tv->pending_redraw) {
+ tv->pending_redraw = true;
+ tv->pending_from_line = fromnline;
+ tv->pending_from_end = fromend;
+ }
return true;
+ }
+ if (tv->pending_redraw) {
+ tv->pending_redraw = false;
+ fromnline = tv->pending_from_line;
+ fromend = tv->pending_from_end;
+ }
+
+ return TVRedrawAppendLocked(tv, fromnline, fromend);
+}
+
+Boolean
+TVRedrawAppendLocked(struct TVRec *tv, unsigned long fromnline,
+ unsigned long fromend)
+{
+ struct TVLine *fromline, *toline;
+ RgnHandle vacated;
+ BigRect redraw;
+ Rect r;
+ unsigned long wastop;
+
if (!TVCalcLinesLocked(tv, false))
return false;
+ fromline = TVGetLine(tv, fromnline);
+
/* keep scrolling and redrawing in one CopyBits */
TVUseCanvas(tv);
--- textview.h Thu Oct 15 09:41:50 2026
+++ textview.h Mon Nov 2 22:02:10 2026
@@ -165,6 +165,9 @@ struct TVRec {
Pattern tab_pat;
Boolean autocalc;
+ Boolean pending_redraw;
+ unsigned long pending_from_line;
+ unsigned long pending_from_end;
Boolean autoscroll;
Boolean linewrap;
char unlock_refcnt;
@@ -243,6 +246,8 @@ struct TVSlab * TVGetTextSlab(struct TVRec *tv, unsign
struct TVChunk * TVGetChunk(struct TVRec *tv, TVSlabLocator loc);
struct TVChunk * TVCreateChunk(struct TVRec *tv);
struct TVLine * TVGetLine(struct TVRec *tv, unsigned long line);
+Boolean TVRedrawAppendLocked(struct TVRec *tv, unsigned long fromnline,
+ unsigned long fromend);
Boolean TVAppendLocked(struct TVRec *tv, struct TVStyle *style, char *text,
unsigned long length, char terminator);
short TVScrollDivisor(struct TVRec *tv);
--- tv_layout.c Mon Nov 2 20:54:52 2026
+++ tv_layout.c Mon Nov 2 21:46:42 2026
@@ -68,7 +68,8 @@ TVResize(TVHandle tvh)
tv->nlines = 0;
tv->last_space = 0;
tv->space_width = 0;
-
+ tv->pending_redraw = false;
+
for (chunk = TVGetChunk(tv, tv->first_chunk); chunk != NULL;
chunk = TVGetChunk(tv, chunk->next_chunk)) {
chunk->start_line = 0;