diff options
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index cca77c15..96440feb 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -171,6 +171,7 @@ struct Impl_DocumentWidget { | |||
171 | const iGmRun * firstVisibleRun; | 171 | const iGmRun * firstVisibleRun; |
172 | const iGmRun * lastVisibleRun; | 172 | const iGmRun * lastVisibleRun; |
173 | iClick click; | 173 | iClick click; |
174 | iString pendingGotoHeading; | ||
174 | float initNormScrollY; | 175 | float initNormScrollY; |
175 | iAnim scrollY; | 176 | iAnim scrollY; |
176 | iAnim sideOpacity; | 177 | iAnim sideOpacity; |
@@ -230,6 +231,7 @@ void init_DocumentWidget(iDocumentWidget *d) { | |||
230 | init_PtrArray(&d->visiblePlayers); | 231 | init_PtrArray(&d->visiblePlayers); |
231 | d->grabbedPlayer = NULL; | 232 | d->grabbedPlayer = NULL; |
232 | d->playerTimer = 0; | 233 | d->playerTimer = 0; |
234 | init_String(&d->pendingGotoHeading); | ||
233 | init_Click(&d->click, d, SDL_BUTTON_LEFT); | 235 | init_Click(&d->click, d, SDL_BUTTON_LEFT); |
234 | addChild_Widget(w, iClob(d->scroll = new_ScrollWidget())); | 236 | addChild_Widget(w, iClob(d->scroll = new_ScrollWidget())); |
235 | d->menu = NULL; /* created when clicking */ | 237 | d->menu = NULL; /* created when clicking */ |
@@ -259,6 +261,7 @@ void deinit_DocumentWidget(iDocumentWidget *d) { | |||
259 | deinit_Array(&d->outline); | 261 | deinit_Array(&d->outline); |
260 | iRelease(d->media); | 262 | iRelease(d->media); |
261 | iRelease(d->request); | 263 | iRelease(d->request); |
264 | deinit_String(&d->pendingGotoHeading); | ||
262 | deinit_Block(&d->sourceContent); | 265 | deinit_Block(&d->sourceContent); |
263 | deinit_String(&d->sourceMime); | 266 | deinit_String(&d->sourceMime); |
264 | iRelease(d->doc); | 267 | iRelease(d->doc); |
@@ -1070,6 +1073,16 @@ static void scrollTo_DocumentWidget_(iDocumentWidget *d, int documentY, iBool ce | |||
1070 | scroll_DocumentWidget_(d, 0); /* clamp it */ | 1073 | scroll_DocumentWidget_(d, 0); /* clamp it */ |
1071 | } | 1074 | } |
1072 | 1075 | ||
1076 | static void scrollToHeading_DocumentWidget_(iDocumentWidget *d, const char *heading) { | ||
1077 | iConstForEach(Array, h, headings_GmDocument(d->doc)) { | ||
1078 | const iGmHeading *head = h.value; | ||
1079 | if (startsWithCase_Rangecc(head->text, heading)) { | ||
1080 | postCommandf_App("document.goto loc:%p", head->text.start); | ||
1081 | break; | ||
1082 | } | ||
1083 | } | ||
1084 | } | ||
1085 | |||
1073 | static void scrollWideBlock_DocumentWidget_(iDocumentWidget *d, iInt2 mousePos, int delta, | 1086 | static void scrollWideBlock_DocumentWidget_(iDocumentWidget *d, iInt2 mousePos, int delta, |
1074 | int duration) { | 1087 | int duration) { |
1075 | if (delta == 0) { | 1088 | if (delta == 0) { |
@@ -1623,6 +1636,11 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
1623 | updateSideIconBuf_DocumentWidget_(d); | 1636 | updateSideIconBuf_DocumentWidget_(d); |
1624 | updateOutline_DocumentWidget_(d); | 1637 | updateOutline_DocumentWidget_(d); |
1625 | postCommandf_App("document.changed url:%s", cstr_String(d->mod.url)); | 1638 | postCommandf_App("document.changed url:%s", cstr_String(d->mod.url)); |
1639 | /* Check for a pending goto. */ | ||
1640 | if (!isEmpty_String(&d->pendingGotoHeading)) { | ||
1641 | scrollToHeading_DocumentWidget_(d, cstr_String(&d->pendingGotoHeading)); | ||
1642 | clear_String(&d->pendingGotoHeading); | ||
1643 | } | ||
1626 | return iFalse; | 1644 | return iFalse; |
1627 | } | 1645 | } |
1628 | else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) { | 1646 | else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) { |
@@ -1779,17 +1797,14 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
1779 | return iTrue; | 1797 | return iTrue; |
1780 | } | 1798 | } |
1781 | else if (equal_Command(cmd, "document.goto") && document_App() == d) { | 1799 | else if (equal_Command(cmd, "document.goto") && document_App() == d) { |
1782 | const iRangecc heading = range_Command(cmd, "heading"); | 1800 | const char *heading = suffixPtr_Command(cmd, "heading"); |
1783 | if (heading.start) { | 1801 | if (heading) { |
1784 | const char *target = cstr_Rangecc(heading); | 1802 | if (isRequestOngoing_DocumentWidget(d)) { |
1785 | iConstForEach(Array, h, headings_GmDocument(d->doc)) { | 1803 | /* Scroll position set when request finishes. */ |
1786 | const iGmHeading *head = h.value; | 1804 | setCStr_String(&d->pendingGotoHeading, heading); |
1787 | if (startsWithCase_Rangecc(head->text, target)) { | 1805 | return iTrue; |
1788 | /* TODO: A bit lazy here, the code is right down below. */ | ||
1789 | postCommandf_App("document.goto loc:%p", head->text.start); | ||
1790 | break; | ||
1791 | } | ||
1792 | } | 1806 | } |
1807 | scrollToHeading_DocumentWidget_(d, heading); | ||
1793 | return iTrue; | 1808 | return iTrue; |
1794 | } | 1809 | } |
1795 | const char *loc = pointerLabel_Command(cmd, "loc"); | 1810 | const char *loc = pointerLabel_Command(cmd, "loc"); |