jcs
/amend
/amendments
/9
browser: Fix diff viewing when already scrolled
The TE was not getting scrolled back up when changed, but doing this
is tricker than it should be to avoid excessive redraws
jcs made amendment 9 over 3 years ago
--- browser.c Mon Oct 18 13:09:06 2021
+++ browser.c Tue Oct 19 22:16:07 2021
@@ -147,6 +147,7 @@ browser_init(struct repo *repo)
te_bounds = bounds;
InsetRect(&te_bounds, 2, 2);
browser->diff_te = TENew(&te_bounds, &bounds);
+ TEAutoView(true, browser->diff_te);
/* scrollbar for diff text */
bounds.right = browser->win->portRect.right - padding;
@@ -159,7 +160,7 @@ browser_init(struct repo *repo)
browser_update_menu(browser);
DrawMenuBar();
browser_add_files(browser);
- UpdateScrollbarForTE(browser->diff_scroller, browser->diff_te);
+ UpdateScrollbarForTE(browser->diff_scroller, browser->diff_te, true);
ShowWindow(browser->win);
return browser;
@@ -323,7 +324,7 @@ browser_show_commit(struct browser *browser, struct re
}
InvalRect(&(*(browser->diff_te))->viewRect);
- UpdateScrollbarForTE(browser->diff_scroller, browser->diff_te);
+ UpdateScrollbarForTE(browser->diff_scroller, browser->diff_te, true);
}
void
@@ -410,7 +411,7 @@ browser_update(struct browser *browser, EventRecord *e
void
browser_mouse_down(struct browser *browser, EventRecord *event)
{
- Cell selected = { 0 }, now = { 0 }, t = { 0 };
+ Cell selected = { 0 }, now = { 0 };
Point p;
ControlHandle control;
Rect r;
--- committer.c Mon Oct 18 16:47:01 2021
+++ committer.c Tue Oct 19 22:07:19 2021
@@ -90,6 +90,7 @@ committer_init(struct browser *browser)
te_bounds = bounds;
InsetRect(&te_bounds, 2, 2);
committer->log_te = TENew(&te_bounds, &bounds);
+ TEAutoView(true, committer->log_te);
/* scrollbar for log message */
bounds.left = bounds.right;
@@ -111,6 +112,7 @@ committer_init(struct browser *browser)
te_bounds = bounds;
InsetRect(&te_bounds, 2, 2);
committer->diff_te = TENew(&te_bounds, &bounds);
+ TEAutoView(true, committer->diff_te);
/* scrollbar for diff */
bounds.left = bounds.right;
@@ -226,7 +228,7 @@ committer_key_down(struct committer *committer, EventR
k = (event->message & charCodeMask);
TEKey(k, committer->log_te);
- UpdateScrollbarForTE(committer->log_scroller, committer->log_te);
+ UpdateScrollbarForTE(committer->log_scroller, committer->log_te, false);
committer_update_menu(committer);
}
@@ -367,7 +369,7 @@ committer_generate_diff(struct committer *committer)
HUnlock(committer->diff_te);
InvalRect(&committer->win->portRect);
- UpdateScrollbarForTE(committer->diff_scroller, committer->diff_te);
+ UpdateScrollbarForTE(committer->diff_scroller, committer->diff_te, true);
cur_committer = NULL;
committer_status(NULL);
--- main.c Mon Oct 18 09:22:19 2021
+++ main.c Tue Oct 19 22:18:38 2021
@@ -222,9 +222,9 @@ handle_menu(long menu_id)
switch (LoWord(menu_id)) {
case EDIT_MENU_COPY_ID:
if (cur_browser && cur_browser->committer)
- TECopyRemovingFakeTabs(cur_browser->committer->diff_te);
+ TECopy(cur_browser->committer->diff_te);
else if (cur_browser)
- TECopyRemovingFakeTabs(cur_browser->diff_te);
+ TECopy(cur_browser->diff_te);
break;
case EDIT_MENU_SELECT_ALL_ID:
if (cur_browser && cur_browser->committer)
--- util.c Mon Oct 18 13:14:58 2021
+++ util.c Tue Oct 19 22:14:49 2021
@@ -298,7 +298,7 @@ open_dialog_hook(short theItem, DialogPtr theDialog)
}
short
-getpath(short vRefNum, Str255 fileName, char **ret, short include_file)
+getpath(short vRefNum, Str255 fileName, char **ret, bool include_file)
{
WDPBRec wdir;
HVolumeParam wvol;
@@ -400,7 +400,7 @@ stat(const char *path, struct stat *sb)
return 0;
}
-short
+bool
is_dir(char *path)
{
struct stat st;
@@ -411,9 +411,9 @@ is_dir(char *path)
/* bit 4 is set in ioFlAttrib if the item is a directory */
if (st.st_flags & (1 << 4))
- return 1;
+ return true;
- return 0;
+ return false;
}
short
@@ -458,10 +458,11 @@ DrawGrowIconOnly(WindowPtr win)
}
void
-UpdateScrollbarForTE(ControlHandle scroller, TEHandle te)
+UpdateScrollbarForTE(ControlHandle scroller, TEHandle te, bool reset)
{
size_t vlines;
TERec *ter;
+ short vtop;
HLock(te);
ter = *te;
@@ -470,8 +471,22 @@ UpdateScrollbarForTE(ControlHandle scroller, TEHandle
if (vlines >= ter->nLines)
vlines = ter->nLines;
SetCtlMax(scroller, ter->nLines - vlines + 1);
+
+ if (reset) {
SetCtlValue(scroller, 1);
+ /*
+ * TESetSelect will redraw if TEAutoView is enabled, but only if
+ * the control was scrolled already
+ */
+ vtop = (*te)->viewRect.top;
+ TESetSelect(0, 0, te);
+ if (vtop == (*te)->viewRect.top)
+ TEUpdate(&ter->viewRect, te);
+ ValidRect(&ter->viewRect);
+ } else if (GetCtlValue(scroller) > GetCtlMax(scroller))
+ SetCtlValue(scroller, GetCtlMax(scroller));
+
HUnlock(te);
}
@@ -538,42 +553,6 @@ TECanAddLine(TEHandle teh, size_t addition)
HUnlock(teh);
return ret;
-}
-
-void
-TECopyRemovingFakeTabs(TEHandle teh)
-{
- TERec *te;
- char *sel, *tetext;
- short len, pos, i;
- char c;
-
- HLock(teh);
- te = *teh;
- len = te->selEnd - te->selStart;
- if (len < 1) {
- HUnlock(teh);
- return;
- }
-
- HLock(te->hText);
- tetext = *(te->hText);
- sel = xmalloc(len);
- pos = 0;
- for (i = 0; i < len; i++) {
- c = tetext[te->selStart + i];
- if (c == '\0' && tetext[te->selStart + i + 1] == '\t')
- /* fake tab, skip both */
- i++;
- else
- sel[pos++] = c;
- }
-
- ZeroScrap();
- PutScrap(pos, 'TEXT', sel);
- free(sel);
- HUnlock(te->hText);
- HUnlock(teh);
}
void
--- util.h Mon Oct 18 13:09:59 2021
+++ util.h Tue Oct 19 22:16:59 2021
@@ -29,6 +29,10 @@
#define nitems(what) (sizeof((what)) / sizeof((what)[0]))
+#ifndef bool
+typedef Boolean bool;
+#endif
+
typedef signed long off_t;
typedef signed long ssize_t;
typedef unsigned char u_char;
@@ -71,19 +75,18 @@ long xGetStringAsLong(short id);
char *askfileordirpath(void);
short getpath(short vRefNum, Str255 fileName, char **ret,
- short include_file);
+ bool include_file);
pascal short open_dialog_hook(short theItem, DialogPtr theDialog);
pascal Boolean open_dialog_filter(DialogPtr theDialog,
EventRecord *theEvent, short *itemHit);
-short is_dir(char *path);
+bool is_dir(char *path);
short stat(const char *path, struct stat *sb);
short FontHeight(short font_id, short size);
void DrawGrowIconOnly(WindowPtr win);
-void UpdateScrollbarForTE(ControlHandle scroller, TEHandle te);
+void UpdateScrollbarForTE(ControlHandle scroller, TEHandle te, bool reset);
void SetTrackControlTE(TEHandle te);
pascal void TrackMouseDownInControl(ControlHandle control, short part);
-void TECopyRemovingFakeTabs(TEHandle teh);
short TECanAddLine(TEHandle teh, size_t addition);
void TEAppendFast(char *str, size_t len, TEHandle te);