Skip to content

Commit 52361bd

Browse files
committed
* Add support for UP arrow when inside a channel, for editing messages.
Issue mentioned: #222
1 parent 5fa4458 commit 52361bd

5 files changed

Lines changed: 83 additions & 7 deletions

File tree

src/resource.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@
528528
#define ID_DUMMYPOPUP_OPENPROXYLINK 1107
529529
#define ID_DUMMYPOPUP_COPYPROXYLINK1108 1108
530530
#define ID_DUMMYPOPUP_OPENPROXYLINK1109 1109
531+
#define IDA_EDIT_LAST_MESSAGE 1110
531532
#define IDR_MAIN_ACCELS 1201
532533
#define IDA_SEARCH 1301
533534
#define IDA_QUICKSWITCHER 1302
@@ -551,7 +552,7 @@
551552
#ifdef APSTUDIO_INVOKED
552553
#ifndef APSTUDIO_READONLY_SYMBOLS
553554
#define _APS_NEXT_RESOURCE_VALUE 106
554-
#define _APS_NEXT_COMMAND_VALUE 1110
555+
#define _APS_NEXT_COMMAND_VALUE 1112
555556
#define _APS_NEXT_CONTROL_VALUE 918
556557
#define _APS_NEXT_SYMED_VALUE 40000
557558
#endif

src/resource.rc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,12 +1444,6 @@ IDC_CLICKER CURSOR "../res/cursors/cur_clicker.cur"
14441444

14451445
IDR_MAIN_ACCELS ACCELERATORS
14461446
BEGIN
1447-
"V", IDA_PASTE, VIRTKEY, CONTROL, NOINVERT
1448-
"K", IDA_QUICKSWITCHER, VIRTKEY, CONTROL, NOINVERT
1449-
"F", IDA_SEARCH, VIRTKEY, CONTROL, NOINVERT
1450-
VK_PRIOR, IDA_PAGE_UP, VIRTKEY, NOINVERT
1451-
VK_NEXT, IDA_PAGE_DOWN, VIRTKEY, NOINVERT
1452-
"A", IDA_SELECT_ALL, VIRTKEY, CONTROL, NOINVERT
14531447
"1", IDA_GUILD_0, VIRTKEY, CONTROL, NOINVERT
14541448
"2", IDA_GUILD_1, VIRTKEY, CONTROL, NOINVERT
14551449
"3", IDA_GUILD_2, VIRTKEY, CONTROL, NOINVERT
@@ -1460,6 +1454,13 @@ BEGIN
14601454
"8", IDA_GUILD_7, VIRTKEY, CONTROL, NOINVERT
14611455
"9", IDA_GUILD_8, VIRTKEY, CONTROL, NOINVERT
14621456
"0", IDA_GUILD_9, VIRTKEY, CONTROL, NOINVERT
1457+
VK_NEXT, IDA_PAGE_DOWN, VIRTKEY, NOINVERT
1458+
VK_PRIOR, IDA_PAGE_UP, VIRTKEY, NOINVERT
1459+
"V", IDA_PASTE, VIRTKEY, CONTROL, NOINVERT
1460+
"K", IDA_QUICKSWITCHER, VIRTKEY, CONTROL, NOINVERT
1461+
"F", IDA_SEARCH, VIRTKEY, CONTROL, NOINVERT
1462+
"A", IDA_SELECT_ALL, VIRTKEY, CONTROL, NOINVERT
1463+
VK_UP, IDA_EDIT_LAST_MESSAGE, VIRTKEY, NOINVERT
14631464
END
14641465

14651466

src/windows/Main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,11 @@ LRESULT HandleCommand(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
696696
g_pMessageEditor->SelectAll();
697697
break;
698698
}
699+
case IDA_EDIT_LAST_MESSAGE:
700+
{
701+
g_pMessageList->EditLastMessage();
702+
break;
703+
}
699704
case IDA_GUILD_0:
700705
case IDA_GUILD_1:
701706
case IDA_GUILD_2:

src/windows/MessageList.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,6 +3059,47 @@ void MessageList::PaintBackground(HDC hdc, RECT& paintRect, RECT& rcClient)
30593059
}
30603060
}
30613061

3062+
bool MessageList::IsMessageVisible(Snowflake sf)
3063+
{
3064+
// TODO: deduplicate this. Part of this is also in Paint()
3065+
RECT rect = {};
3066+
GetClientRect(m_hwnd, &rect);
3067+
int windowHeight = rect.bottom - rect.top;
3068+
int ScrollHeight = 0;
3069+
SCROLLINFO si;
3070+
si.cbSize = sizeof(si);
3071+
si.fMask = SIF_POS | SIF_RANGE;
3072+
ri::GetScrollInfo(m_hwnd, SB_VERT, &si);
3073+
ScrollHeight = si.nPos;
3074+
3075+
RECT msgRect = rect;
3076+
msgRect.top -= ScrollHeight;
3077+
3078+
if (m_total_height < windowHeight && !m_bIsTopDown) {
3079+
msgRect.top += windowHeight - m_total_height;
3080+
}
3081+
3082+
msgRect.bottom = msgRect.top;
3083+
3084+
for (std::list<MessageItem>::iterator iter = m_messages.begin();
3085+
iter != m_messages.end();
3086+
++iter)
3087+
{
3088+
bool isActionMessage = IsActionMessage(iter->m_msg->m_type);
3089+
bool needUpdate = false;
3090+
3091+
msgRect.bottom = msgRect.top + iter->m_height;
3092+
iter->m_rect = msgRect;
3093+
3094+
bool bDraw = msgRect.top <= rect.bottom && msgRect.bottom > rect.top;
3095+
3096+
if (iter->m_msg->m_snowflake == sf)
3097+
return bDraw;
3098+
}
3099+
3100+
return false;
3101+
}
3102+
30623103
void MessageList::Paint(HDC hdc, RECT& paintRect)
30633104
{
30643105
RECT rect = {};
@@ -4650,6 +4691,31 @@ void MessageList::OnPageDown()
46504691
SendMessage(m_hwnd, WM_VSCROLL, SB_PAGEDOWN, 0);
46514692
}
46524693

4694+
void MessageList::EditLastMessage()
4695+
{
4696+
Profile* profile = GetDiscordInstance()->GetProfile();
4697+
Snowflake sf = 0;
4698+
4699+
for (auto iter = m_messages.rbegin(); iter != m_messages.rend(); ++iter)
4700+
{
4701+
if (iter->m_msg->m_author_snowflake != profile->m_snowflake)
4702+
continue;
4703+
4704+
sf = iter->m_msg->m_snowflake;
4705+
break;
4706+
}
4707+
4708+
if (!sf) {
4709+
DbgPrintW("Your last message isn't loaded!");
4710+
return;
4711+
}
4712+
4713+
if (!IsMessageVisible(sf))
4714+
SendToMessage(sf, false, false);
4715+
4716+
SendMessage(g_Hwnd, WM_STARTEDITING, 0, (LPARAM) &sf);
4717+
}
4718+
46534719
bool MessageList::ShouldStartNewChain(Snowflake prevAuthor, time_t prevTime, int prevPlaceInChain, MessageType::eType prevType, const std::string& prevAuthorName, const std::string& prevAuthorAvatar, const MessageItem& item, bool ifChainTooLongToo)
46544720
{
46554721
if (m_bManagedByOwner)

src/windows/MessageList.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ class MessageList
524524
bool ShouldBeDateGap(time_t oldTime, time_t newTime);
525525
void OnPageUp();
526526
void OnPageDown();
527+
void EditLastMessage();
527528

528529
// TODO: Wouldn't it be more sane to have a pointer to the last message item, or something?
529530
bool ShouldStartNewChain(Snowflake prevAuthor, time_t prevTime, int prevPlaceInChain, MessageType::eType prevType, const std::string& prevAuthorName, const std::string& prevAuthorAvatar, const MessageItem& item, bool ifChainTooLongToo);
@@ -568,6 +569,8 @@ class MessageList
568569
void HandleRightClickMenuCommandMessage(int command, MessageItem* pMsg);
569570
void HandleRightClickMenuCommandInteractable(int command, MessageItem* pMsg);
570571

572+
bool IsMessageVisible(Snowflake sf);
573+
571574
HMENU GetMenuForMessage(MessageItem* pRCMsg);
572575
HMENU GetMenuForInteractable(MessageItem* pRCMsg, size_t index);
573576
HMENU GetMenuForAttachment(MessageItem* pRCMsg, size_t index);

0 commit comments

Comments
 (0)