From b7b75a86ec08566731fe49fa83cd04b397d1a8ea Mon Sep 17 00:00:00 2001 From: Jason Edmeades Date: Tue, 30 Apr 2002 21:17:34 +0000 Subject: [PATCH] - Added f8 (history retrieval from partial command) support - Delete key deletes current character - Ctrl + end deletes to end of line - Ctrl + right stopped before the word itself --- win32/editline.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/win32/editline.c b/win32/editline.c index fd56de1c1ad..8a6ace4d3de 100644 --- a/win32/editline.c +++ b/win32/editline.c @@ -239,8 +239,8 @@ static int WCEL_GetLeftWordTransition(WCEL_Context* ctx, int ofs) static int WCEL_GetRightWordTransition(WCEL_Context* ctx, int ofs) { ofs++; - while (ofs <= ctx->len && !WCEL_iswalnum(ctx->line[ofs])) ofs++; while (ofs <= ctx->len && WCEL_iswalnum(ctx->line[ofs])) ofs++; + while (ofs <= ctx->len && !WCEL_iswalnum(ctx->line[ofs])) ofs++; return min(ofs, ctx->len); } @@ -296,6 +296,46 @@ static void WCEL_MoveToHist(WCEL_Context* ctx, int idx) } } +static void WCEL_FindPrevInHist(WCEL_Context* ctx) +{ + int startPos = ctx->histPos; + WCHAR* data; + int len, oldofs; + + if (ctx->histPos && ctx->histPos == ctx->histSize) { + startPos--; + ctx->histPos--; + } + + do { + data = WCEL_GetHistory(ctx, ctx->histPos); + + if (ctx->histPos) ctx->histPos--; + else ctx->histPos = (ctx->histSize-1); + + len = lstrlenW(data) + 1; + if ((len >= ctx->ofs) && + (memcmp(ctx->line, data, ctx->ofs * sizeof(WCHAR)) == 0)) { + + /* need to clean also the screen if new string is shorter than old one */ + WCEL_DeleteString(ctx, 0, ctx->len); + + if (WCEL_Grow(ctx, len)) + { + oldofs = ctx->ofs; + ctx->ofs = 0; + WCEL_InsertString(ctx, data); + ctx->ofs = oldofs; + SetConsoleCursorPosition(ctx->hConOut, WCEL_GetCoord(ctx, ctx->ofs)); + HeapFree(GetProcessHeap(), 0, data); + return; + } + } + } while (ctx->histPos != startPos); + + return; +} + /* ==================================================================== * * basic edition functions @@ -537,6 +577,13 @@ static KeyEntry StdKeyMap[] = { 0, NULL } }; +static KeyEntry Win32ExtraStdKeyMap[] = +{ + {/*VK_F8*/ 0x77, WCEL_FindPrevInHist }, + { 0, NULL } +}; + + static KeyEntry EmacsKeyMapCtrl[] = { { CTRL('@'), WCEL_SetMark }, @@ -617,6 +664,7 @@ static KeyEntry Win32KeyMapExtended[] = {/*VK_END*/ 0x23, WCEL_MoveToEnd }, {/*VK_UP*/ 0x26, WCEL_MoveToPrevHist }, {/*VK_DOWN*/ 0x28, WCEL_MoveToNextHist }, + {/*VK_DEL*/ 0x2e, WCEL_FindPrevInHist /*L_DeleteCurrChar*/ }, { 0, NULL } }; @@ -624,12 +672,14 @@ static KeyEntry Win32KeyMapCtrlExtended[] = { {/*VK_LEFT*/ 0x25, WCEL_MoveToLeftWord }, {/*VK_RIGHT*/0x27, WCEL_MoveToRightWord }, + {/*VK_END*/ 0x23, WCEL_KillToEndOfLine }, { 0, NULL } }; KeyMap Win32KeyMap[] = { {0x00000000, 1, StdKeyMap}, + {0x00000000, 0, Win32ExtraStdKeyMap}, {0x00000100, 0, Win32KeyMapExtended}, {0x00000104, 0, Win32KeyMapCtrlExtended}, {0x00000108, 0, Win32KeyMapCtrlExtended},