Allow for HOME/END key to move viewport when cursor cannot move
This commit is contained in:
parent
1ca06d94bc
commit
e30c601f41
3 changed files with 23 additions and 18 deletions
|
|
@ -4,6 +4,7 @@
|
|||
**---------------------------------------------------------------------------
|
||||
** Copyright 1998-2006 Randy Heit
|
||||
** Copyright 2010-2020 Christoph Oelckers
|
||||
** Copyright 2017-2025 GZDoom Maintainers and Contributors
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -31,11 +32,12 @@
|
|||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#include "c_commandbuffer.h"
|
||||
#include "v_draw.h"
|
||||
#include "v_2ddrawer.h"
|
||||
#include "v_font.h"
|
||||
#include "utf8.h"
|
||||
#include "v_2ddrawer.h"
|
||||
#include "v_draw.h"
|
||||
#include "v_font.h"
|
||||
|
||||
FCommandBuffer CmdLine;
|
||||
|
||||
|
|
@ -155,18 +157,23 @@ void FCommandBuffer::MakeStartPosGood()
|
|||
}
|
||||
}
|
||||
|
||||
void FCommandBuffer::CursorStart()
|
||||
bool FCommandBuffer::CursorStart()
|
||||
{
|
||||
bool moved = CursorPos != 0;
|
||||
CursorPos = 0;
|
||||
StartPos = 0;
|
||||
CursorPosCells = 0;
|
||||
StartPosCells = 0;
|
||||
return moved;
|
||||
}
|
||||
|
||||
void FCommandBuffer::CursorEnd()
|
||||
bool FCommandBuffer::CursorEnd()
|
||||
{
|
||||
CursorPos = (unsigned)Text.length();
|
||||
unsigned len = Text.length();
|
||||
bool moved = CursorPos != len;
|
||||
CursorPos = len;
|
||||
MakeStartPosGood();
|
||||
return moved;
|
||||
}
|
||||
|
||||
void FCommandBuffer::CursorLeft()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "zstring.h"
|
||||
|
||||
struct FCommandBuffer
|
||||
|
|
@ -31,8 +33,8 @@ public:
|
|||
unsigned CalcCellSize(unsigned length);
|
||||
unsigned CharsForCells(unsigned cellin, bool *overflow);
|
||||
void MakeStartPosGood();
|
||||
void CursorStart();
|
||||
void CursorEnd();
|
||||
bool CursorStart();
|
||||
bool CursorEnd();
|
||||
|
||||
private:
|
||||
void MoveCursorLeft()
|
||||
|
|
|
|||
|
|
@ -135,6 +135,9 @@ CUSTOM_CVAR(Float, con_alpha, 0.75f, CVAR_ARCHIVE)
|
|||
if (self > 1.f) self = 1.f;
|
||||
}
|
||||
|
||||
CUSTOM_CVARD(Bool, con_quick_home_end, true, CVAR_ARCHIVE, "Use HOME/END keys to scroll when cursor is at start/end of line already")
|
||||
{}
|
||||
|
||||
// Show developer messages if true.
|
||||
CUSTOM_CVAR(Int, developer, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
|
|
@ -862,25 +865,19 @@ static bool C_HandleKey (event_t *ev, FCommandBuffer &buffer)
|
|||
break;
|
||||
|
||||
case GK_HOME:
|
||||
if (ev->data3 & (GKM_CTRL|GKM_SHIFT))
|
||||
if ((ev->data3 & (GKM_CTRL|GKM_SHIFT))
|
||||
|| (!buffer.CursorStart() && con_quick_home_end)) // Try to move cursor to start of line
|
||||
{ // Move to top of console buffer
|
||||
RowAdjust = top_row;
|
||||
}
|
||||
else
|
||||
{ // Move cursor to start of line
|
||||
buffer.CursorStart();
|
||||
}
|
||||
break;
|
||||
|
||||
case GK_END:
|
||||
if (ev->data3 & (GKM_CTRL|GKM_SHIFT))
|
||||
if ((ev->data3 & (GKM_CTRL|GKM_SHIFT))
|
||||
|| (!buffer.CursorEnd() && con_quick_home_end)) // Try to move cursor to end of line
|
||||
{ // Move to bottom of console buffer
|
||||
RowAdjust = 0;
|
||||
}
|
||||
else
|
||||
{ // Move cursor to end of line
|
||||
buffer.CursorEnd();
|
||||
}
|
||||
break;
|
||||
|
||||
case GK_LEFT:
|
||||
|
|
@ -1204,4 +1201,3 @@ CCMD(toggleconsole)
|
|||
{
|
||||
C_ToggleConsole();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue