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.
This commit is contained in:
parent
8c1464822b
commit
8d9d1c60ec
62
xW/xW.cpp
62
xW/xW.cpp
|
@ -1301,6 +1301,32 @@ input_complete()
|
||||||
return true;
|
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
|
static boolean
|
||||||
input_wants(const MSG *message)
|
input_wants(const MSG *message)
|
||||||
{
|
{
|
||||||
|
@ -1332,34 +1358,18 @@ input_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
|
||||||
return lResult;
|
return lResult;
|
||||||
}
|
}
|
||||||
case WM_SYSCHAR:
|
case WM_SYSCHAR:
|
||||||
{
|
|
||||||
auto b = buffer_by_name(g.buffer_current);
|
|
||||||
if (!b)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// TODO(p): Emacs-style cursor movement shortcuts.
|
// TODO(p): Emacs-style cursor movement shortcuts.
|
||||||
switch (wParam) {
|
switch (wParam) {
|
||||||
case 'p':
|
case 'p':
|
||||||
{
|
if (input_up())
|
||||||
if (b->history_at < 1)
|
return 0;
|
||||||
break;
|
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;
|
|
||||||
}
|
|
||||||
case 'n':
|
case 'n':
|
||||||
{
|
if (input_down())
|
||||||
if (b->history_at >= b->history.size())
|
return 0;
|
||||||
break;
|
break;
|
||||||
input_set_contents(++b->history_at == b->history.size()
|
|
||||||
? b->input
|
|
||||||
: b->history.at(b->history_at));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case WM_KEYDOWN:
|
case WM_KEYDOWN:
|
||||||
{
|
{
|
||||||
HWND scrollable = IsWindowVisible(g.hwndBufferLog)
|
HWND scrollable = IsWindowVisible(g.hwndBufferLog)
|
||||||
|
@ -1367,6 +1377,14 @@ input_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
|
||||||
: g.hwndBuffer;
|
: g.hwndBuffer;
|
||||||
|
|
||||||
switch (wParam) {
|
switch (wParam) {
|
||||||
|
case VK_UP:
|
||||||
|
if (input_up())
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
case VK_DOWN:
|
||||||
|
if (input_down())
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
case VK_PRIOR:
|
case VK_PRIOR:
|
||||||
SendMessage(scrollable, EM_SCROLL, SB_PAGEUP, 0);
|
SendMessage(scrollable, EM_SCROLL, SB_PAGEUP, 0);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue