diff options
-rw-r--r-- | res/about/version.gmi | 3 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 54 |
2 files changed, 38 insertions, 19 deletions
diff --git a/res/about/version.gmi b/res/about/version.gmi index dfdf2b97..c255e533 100644 --- a/res/about/version.gmi +++ b/res/about/version.gmi | |||
@@ -12,7 +12,8 @@ | |||
12 | * Shift+Insert can be used for pasting clipboard contents into input fields. | 12 | * Shift+Insert can be used for pasting clipboard contents into input fields. |
13 | * Added keybinding (F11) for toggling fullscreen mode. On macOS, the shortcut is ⌃⌘F as before. | 13 | * Added keybinding (F11) for toggling fullscreen mode. On macOS, the shortcut is ⌃⌘F as before. |
14 | * Added keybinding for finding text on page. | 14 | * Added keybinding for finding text on page. |
15 | * Windows: Added a custom window frame to replace the default Windows one. This looks nicer but does not behave exactly like a native window frame. Added a setting to Preferences > Window for switching back to the default frame. | 15 | * Scroll position remains fixed while horizontally resizing the window or sidebars. |
16 | * Windows: Added a custom window frame to replace the default Windows one. This looks nicer but does not behave exactly like a native window frame. Added a setting to Preferences for switching back to the default frame. | ||
16 | * Windows: Fixed a flash of white when the window is first opened. | 17 | * Windows: Fixed a flash of white when the window is first opened. |
17 | 18 | ||
18 | ## 1.1.3 | 19 | ## 1.1.3 |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 603af076..e0415f6c 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1113,6 +1113,9 @@ static void scroll_DocumentWidget_(iDocumentWidget *d, int offset) { | |||
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | static void scrollTo_DocumentWidget_(iDocumentWidget *d, int documentY, iBool centered) { | 1115 | static void scrollTo_DocumentWidget_(iDocumentWidget *d, int documentY, iBool centered) { |
1116 | if (!hasSiteBanner_GmDocument(d->doc)) { | ||
1117 | documentY += d->pageMargin * gap_UI; | ||
1118 | } | ||
1116 | init_Anim(&d->scrollY, | 1119 | init_Anim(&d->scrollY, |
1117 | documentY - (centered ? documentBounds_DocumentWidget_(d).size.y / 2 | 1120 | documentY - (centered ? documentBounds_DocumentWidget_(d).size.y / 2 |
1118 | : lineHeight_Text(paragraph_FontId))); | 1121 | : lineHeight_Text(paragraph_FontId))); |
@@ -1538,28 +1541,43 @@ static const int homeRowKeys_[] = { | |||
1538 | 't', 'y', | 1541 | 't', 'y', |
1539 | }; | 1542 | }; |
1540 | 1543 | ||
1544 | static void updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumentWidget *d, | ||
1545 | iBool keepCenter) { | ||
1546 | /* Font changes (i.e., zooming) will keep the view centered, otherwise keep the top | ||
1547 | of the visible area fixed. */ | ||
1548 | const iGmRun *run = keepCenter ? middleRun_DocumentWidget_(d) : d->firstVisibleRun; | ||
1549 | const char * runLoc = (run ? run->text.start : NULL); | ||
1550 | int voffset = 0; | ||
1551 | if (!keepCenter && run) { | ||
1552 | /* Keep the first visible run visible at the same position. */ | ||
1553 | /* TODO: First *fully* visible run? */ | ||
1554 | voffset = visibleRange_DocumentWidget_(d).start - top_Rect(run->visBounds); | ||
1555 | } | ||
1556 | setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); | ||
1557 | if (runLoc && !keepCenter) { | ||
1558 | run = findRunAtLoc_GmDocument(d->doc, runLoc); | ||
1559 | if (run) { | ||
1560 | scrollTo_DocumentWidget_(d, | ||
1561 | top_Rect(run->visBounds) + | ||
1562 | lineHeight_Text(paragraph_FontId) + voffset, | ||
1563 | iFalse); | ||
1564 | } | ||
1565 | } | ||
1566 | else if (runLoc && keepCenter) { | ||
1567 | run = findRunAtLoc_GmDocument(d->doc, runLoc); | ||
1568 | if (run) { | ||
1569 | scrollTo_DocumentWidget_(d, mid_Rect(run->bounds).y, iTrue); | ||
1570 | } | ||
1571 | } | ||
1572 | } | ||
1573 | |||
1541 | static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { | 1574 | static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { |
1542 | iWidget *w = as_Widget(d); | 1575 | iWidget *w = as_Widget(d); |
1543 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { | 1576 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { |
1544 | const iBool isVerticalOnly = | ||
1545 | !argLabel_Command(cmd, "horiz") && argLabel_Command(cmd, "vert"); | ||
1546 | /* Alt/Option key may be involved in window size changes. */ | 1577 | /* Alt/Option key may be involved in window size changes. */ |
1547 | iChangeFlags(d->flags, showLinkNumbers_DocumentWidgetFlag, iFalse); | 1578 | iChangeFlags(d->flags, showLinkNumbers_DocumentWidgetFlag, iFalse); |
1548 | if (isVerticalOnly) { | 1579 | const iBool keepCenter = equal_Command(cmd, "font.changed"); |
1549 | scroll_DocumentWidget_(d, 0); /* prevent overscroll */ | 1580 | updateDocumentWidthRetainingScrollPosition_DocumentWidget_(d, keepCenter); |
1550 | } | ||
1551 | else { | ||
1552 | const iGmRun *mid = middleRun_DocumentWidget_(d); | ||
1553 | const char *midLoc = (mid ? mid->text.start : NULL); | ||
1554 | setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); | ||
1555 | scroll_DocumentWidget_(d, 0); | ||
1556 | if (midLoc) { | ||
1557 | mid = findRunAtLoc_GmDocument(d->doc, midLoc); | ||
1558 | if (mid) { | ||
1559 | scrollTo_DocumentWidget_(d, mid_Rect(mid->bounds).y, iTrue); | ||
1560 | } | ||
1561 | } | ||
1562 | } | ||
1563 | updateSideIconBuf_DocumentWidget_(d); | 1581 | updateSideIconBuf_DocumentWidget_(d); |
1564 | updateOutline_DocumentWidget_(d); | 1582 | updateOutline_DocumentWidget_(d); |
1565 | invalidate_DocumentWidget_(d); | 1583 | invalidate_DocumentWidget_(d); |
@@ -3398,7 +3416,7 @@ iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) { | |||
3398 | } | 3416 | } |
3399 | 3417 | ||
3400 | void updateSize_DocumentWidget(iDocumentWidget *d) { | 3418 | void updateSize_DocumentWidget(iDocumentWidget *d) { |
3401 | setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); | 3419 | updateDocumentWidthRetainingScrollPosition_DocumentWidget_(d, iFalse); |
3402 | resetWideRuns_DocumentWidget_(d); | 3420 | resetWideRuns_DocumentWidget_(d); |
3403 | updateSideIconBuf_DocumentWidget_(d); | 3421 | updateSideIconBuf_DocumentWidget_(d); |
3404 | updateOutline_DocumentWidget_(d); | 3422 | updateOutline_DocumentWidget_(d); |