summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ui/documentwidget.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index cef1275b..604192c5 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -1716,6 +1716,48 @@ static iBool processPlayerEvents_DocumentWidget_(iDocumentWidget *d, const SDL_E
1716 return iFalse; 1716 return iFalse;
1717} 1717}
1718 1718
1719static size_t linkOrdinalFromKey_(int key) {
1720 if (key >= '1' && key <= '9') {
1721 return key - '1';
1722 }
1723 if (key < 'a' || key > 'z') {
1724 return iInvalidPos;
1725 }
1726 int ord = key - 'a' + 9;
1727#if defined (iPlatformApple)
1728 /* Skip keys that would conflict with default system shortcuts: hide, minimize, quit, close. */
1729 if (key == 'h' || key == 'm' || key == 'q' || key == 'w') {
1730 return iInvalidPos;
1731 }
1732 if (key > 'h') ord--;
1733 if (key > 'm') ord--;
1734 if (key > 'q') ord--;
1735 if (key > 'w') ord--;
1736#endif
1737 return ord;
1738}
1739
1740static iChar linkOrdinalChar_(size_t ord) {
1741 if (ord < 9) {
1742 return 0x278a + ord;
1743 }
1744#if defined (iPlatformApple)
1745 if (ord < 9 + 22) {
1746 int key = 'a' + ord - 9;
1747 if (key >= 'h') key++;
1748 if (key >= 'm') key++;
1749 if (key >= 'q') key++;
1750 if (key >= 'w') key++;
1751 return 0x24b6 + key - 'a';
1752 }
1753#else
1754 if (ord < 9 + 26) {
1755 return 0x24b6 + ord - 9;
1756 }
1757#endif
1758 return 0;
1759}
1760
1719static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *ev) { 1761static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *ev) {
1720 iWidget *w = as_Widget(d); 1762 iWidget *w = as_Widget(d);
1721 if (ev->type == SDL_USEREVENT && ev->user.code == command_UserEventCode) { 1763 if (ev->type == SDL_USEREVENT && ev->user.code == command_UserEventCode) {
@@ -1746,12 +1788,12 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1746 } 1788 }
1747 } 1789 }
1748 if (ev->type == SDL_KEYDOWN) { 1790 if (ev->type == SDL_KEYDOWN) {
1749 const int mods = keyMods_Sym(ev->key.keysym.mod); 1791 const int key = ev->key.keysym.sym;
1750 const int key = ev->key.keysym.sym;
1751 if ((d->flags & showLinkNumbers_DocumentWidgetFlag) && 1792 if ((d->flags & showLinkNumbers_DocumentWidgetFlag) &&
1752 ((key >= '1' && key <= '9') || (key >= 'a' && key <= 'z'))) { 1793 ((key >= '1' && key <= '9') || (key >= 'a' && key <= 'z'))) {
1753 const size_t ord = isdigit(key) ? key - SDLK_1 : (key - 'a' + 9); 1794 const size_t ord = linkOrdinalFromKey_(key);
1754 iConstForEach(PtrArray, i, &d->visibleLinks) { 1795 iConstForEach(PtrArray, i, &d->visibleLinks) {
1796 if (ord == iInvalidPos) break;
1755 const iGmRun *run = i.ptr; 1797 const iGmRun *run = i.ptr;
1756 if (run->flags & decoration_GmRunFlag && 1798 if (run->flags & decoration_GmRunFlag &&
1757 visibleLinkOrdinal_DocumentWidget_(d, run->linkId) == ord) { 1799 visibleLinkOrdinal_DocumentWidget_(d, run->linkId) == ord) {
@@ -2160,8 +2202,8 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
2160 else { 2202 else {
2161 if (d->showLinkNumbers && run->linkId && run->flags & decoration_GmRunFlag) { 2203 if (d->showLinkNumbers && run->linkId && run->flags & decoration_GmRunFlag) {
2162 const size_t ord = visibleLinkOrdinal_DocumentWidget_(d->widget, run->linkId); 2204 const size_t ord = visibleLinkOrdinal_DocumentWidget_(d->widget, run->linkId);
2163 if (ord < 9 + 26) { 2205 const iChar ordChar = linkOrdinalChar_(ord);
2164 const iChar ordChar = ord < 9 ? 0x278a + ord : (0x24b6 + ord - 9); 2206 if (ordChar) {
2165 drawString_Text(run->font, 2207 drawString_Text(run->font,
2166 init_I2(d->viewPos.x - gap_UI / 3, visPos.y), 2208 init_I2(d->viewPos.x - gap_UI / 3, visPos.y),
2167 fg, 2209 fg,