diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-04 11:24:13 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-04 11:24:13 +0300 |
commit | 7a69d53ba72f9e5581c781dd4c54dd3a3e6b89b4 (patch) | |
tree | d84af4e3d72eb02c7cc3a15e08ceda42f59f9b02 /src/history.c | |
parent | 7fff669f5be5021862ae634b65f3ab18b17021dd (diff) |
Remember scroll positions on visited pages
Diffstat (limited to 'src/history.c')
-rw-r--r-- | src/history.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/history.c b/src/history.c index edffd485..ca80ad3f 100644 --- a/src/history.c +++ b/src/history.c | |||
@@ -11,6 +11,7 @@ static const size_t maxAgeVisited_History_ = 3600 * 24 * 30; /* one month */ | |||
11 | void init_HistoryItem(iHistoryItem *d) { | 11 | void init_HistoryItem(iHistoryItem *d) { |
12 | initCurrent_Time(&d->when); | 12 | initCurrent_Time(&d->when); |
13 | init_String(&d->url); | 13 | init_String(&d->url); |
14 | d->scrollY = 0; | ||
14 | } | 15 | } |
15 | 16 | ||
16 | void deinit_HistoryItem(iHistoryItem *d) { | 17 | void deinit_HistoryItem(iHistoryItem *d) { |
@@ -52,13 +53,14 @@ static void writeItems_(const iArray *items, iFile *f) { | |||
52 | iDate date; | 53 | iDate date; |
53 | init_Date(&date, &item->when); | 54 | init_Date(&date, &item->when); |
54 | format_String(line, | 55 | format_String(line, |
55 | "%04d-%02d-%02dT%02d:%02d:%02d %s\n", | 56 | "%04d-%02d-%02dT%02d:%02d:%02d %04x %s\n", |
56 | date.year, | 57 | date.year, |
57 | date.month, | 58 | date.month, |
58 | date.day, | 59 | date.day, |
59 | date.hour, | 60 | date.hour, |
60 | date.minute, | 61 | date.minute, |
61 | date.second, | 62 | date.second, |
63 | item->scrollY, | ||
62 | cstr_String(&item->url)); | 64 | cstr_String(&item->url)); |
63 | writeData_File(f, cstr_String(line), size_String(line)); | 65 | writeData_File(f, cstr_String(line), size_String(line)); |
64 | } | 66 | } |
@@ -84,18 +86,19 @@ static void loadItems_(iArray *items, iFile *f, double maxAge) { | |||
84 | iTime now; | 86 | iTime now; |
85 | initCurrent_Time(&now); | 87 | initCurrent_Time(&now); |
86 | while (nextSplit_Rangecc(&src, "\n", &line)) { | 88 | while (nextSplit_Rangecc(&src, "\n", &line)) { |
87 | int y, m, D, H, M, S; | 89 | int y, m, D, H, M, S, scroll = 0; |
88 | sscanf(line.start, "%04d-%02d-%02dT%02d:%02d:%02d", &y, &m, &D, &H, &M, &S); | 90 | sscanf(line.start, "%04d-%02d-%02dT%02d:%02d:%02d %04x", &y, &m, &D, &H, &M, &S, &scroll); |
89 | if (!y) break; | 91 | if (!y) break; |
90 | iHistoryItem item; | 92 | iHistoryItem item; |
91 | init_HistoryItem(&item); | 93 | init_HistoryItem(&item); |
94 | item.scrollY = scroll; | ||
92 | init_Time( | 95 | init_Time( |
93 | &item.when, | 96 | &item.when, |
94 | &(iDate){ .year = y, .month = m, .day = D, .hour = H, .minute = M, .second = S }); | 97 | &(iDate){ .year = y, .month = m, .day = D, .hour = H, .minute = M, .second = S }); |
95 | if (maxAge > 0.0 && secondsSince_Time(&now, &item.when) > maxAge) { | 98 | if (maxAge > 0.0 && secondsSince_Time(&now, &item.when) > maxAge) { |
96 | continue; /* Too old. */ | 99 | continue; /* Too old. */ |
97 | } | 100 | } |
98 | initRange_String(&item.url, (iRangecc){ line.start + 20, line.end }); | 101 | initRange_String(&item.url, (iRangecc){ line.start + 25, line.end }); |
99 | pushBack_Array(items, &item); | 102 | pushBack_Array(items, &item); |
100 | } | 103 | } |
101 | } | 104 | } |
@@ -194,7 +197,9 @@ void addUrl_History(iHistory *d, const iString *url ){ | |||
194 | iBool goBack_History(iHistory *d) { | 197 | iBool goBack_History(iHistory *d) { |
195 | if (d->stackPos < size_Array(&d->stack) - 1) { | 198 | if (d->stackPos < size_Array(&d->stack) - 1) { |
196 | d->stackPos++; | 199 | d->stackPos++; |
197 | postCommandf_App("open history:1 url:%s", cstr_String(url_History(d, d->stackPos))); | 200 | postCommandf_App("open history:1 scroll:%d url:%s", |
201 | item_History(d)->scrollY, | ||
202 | cstr_String(url_History(d, d->stackPos))); | ||
198 | return iTrue; | 203 | return iTrue; |
199 | } | 204 | } |
200 | return iFalse; | 205 | return iFalse; |