summaryrefslogtreecommitdiff
path: root/xW/xW.cpp
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-07-27 16:33:36 +0200
committerPřemysl Eric Janouch <p@janouch.name>2023-07-27 16:35:54 +0200
commit8d9d1c60ecf2e757731ae03c045b7ea905732905 (patch)
treeb30a436320000d57f4178111ca00ef1803c98d06 /xW/xW.cpp
parent8c1464822bd35440f1802bf5ec64e4518aa17e67 (diff)
downloadxK-8d9d1c60ecf2e757731ae03c045b7ea905732905.tar.gz
xK-8d9d1c60ecf2e757731ae03c045b7ea905732905.tar.xz
xK-8d9d1c60ecf2e757731ae03c045b7ea905732905.zip
xW: make Up/Down go through input history
The input field isn't multiline, so this doesn't pose an issue. Otherwise, we'd have to check if we're on the top line first.
Diffstat (limited to 'xW/xW.cpp')
-rw-r--r--xW/xW.cpp62
1 files changed, 40 insertions, 22 deletions
diff --git a/xW/xW.cpp b/xW/xW.cpp
index 2eb2f53..e35fec2 100644
--- a/xW/xW.cpp
+++ b/xW/xW.cpp
@@ -1301,6 +1301,32 @@ input_complete()
return true;
}
+static bool
+input_up()
+{
+ auto b = buffer_by_name(g.buffer_current);
+ if (!b || b->history_at < 1)
+ return false;
+
+ if (b->history_at == b->history.size())
+ b->input = window_get_text(g.hwndInput);
+ input_set_contents(b->history.at(--b->history_at));
+ return true;
+}
+
+static bool
+input_down()
+{
+ auto b = buffer_by_name(g.buffer_current);
+ if (!b || b->history_at >= b->history.size())
+ return false;
+
+ input_set_contents(++b->history_at == b->history.size()
+ ? b->input
+ : b->history.at(b->history_at));
+ return true;
+}
+
static boolean
input_wants(const MSG *message)
{
@@ -1332,34 +1358,18 @@ input_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
return lResult;
}
case WM_SYSCHAR:
- {
- auto b = buffer_by_name(g.buffer_current);
- if (!b)
- break;
-
// TODO(p): Emacs-style cursor movement shortcuts.
switch (wParam) {
case 'p':
- {
- if (b->history_at < 1)
- break;
- if (b->history_at == b->history.size())
- b->input = window_get_text(g.hwndInput);
- input_set_contents(b->history.at(--b->history_at));
- return 0;
- }
+ if (input_up())
+ return 0;
+ break;
case 'n':
- {
- if (b->history_at >= b->history.size())
- break;
- input_set_contents(++b->history_at == b->history.size()
- ? b->input
- : b->history.at(b->history_at));
- return 0;
- }
+ if (input_down())
+ return 0;
+ break;
}
break;
- }
case WM_KEYDOWN:
{
HWND scrollable = IsWindowVisible(g.hwndBufferLog)
@@ -1367,6 +1377,14 @@ input_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
: g.hwndBuffer;
switch (wParam) {
+ case VK_UP:
+ if (input_up())
+ return 0;
+ break;
+ case VK_DOWN:
+ if (input_down())
+ return 0;
+ break;
case VK_PRIOR:
SendMessage(scrollable, EM_SCROLL, SB_PAGEUP, 0);
return 0;