Skip to content

Commit

Permalink
Fix textentryscreen copypasting
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Jun 24, 2018
1 parent 65bfade commit 3962e55
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 35 deletions.
19 changes: 19 additions & 0 deletions src/InputFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,21 @@ void InputFilter::UpdateMouseWheel(float _fZ)
m_MouseCoords.fZ = _fZ;
}

bool InputFilter::IsKBKeyPressed(DeviceButton k) const
{
return INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, k));
}

bool InputFilter::IsControlPressed() const
{
return IsKBKeyPressed(KEY_LCTRL) || IsKBKeyPressed(KEY_RCTRL);
}

bool InputFilter::IsShiftPressed() const
{
return IsKBKeyPressed(KEY_LSHIFT) || IsKBKeyPressed(KEY_RSHIFT);
}

// lua start
#include "LuaBinding.h"

Expand Down Expand Up @@ -506,12 +521,16 @@ class LunaInputFilter: public Luna<InputFilter>
lua_pushboolean(L, INPUTFILTER->IsBeingPressed(DeviceInput(device, button)));
return 1;
}
DEFINE_METHOD(IsShiftPressed, IsShiftPressed());
DEFINE_METHOD(IsControlPressed, IsControlPressed());
LunaInputFilter()
{
ADD_METHOD(GetMouseX);
ADD_METHOD(GetMouseY);
ADD_METHOD(GetMouseWheel);
ADD_METHOD(IsBeingPressed);
ADD_METHOD(IsShiftPressed);
ADD_METHOD(IsControlPressed);
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/InputFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class InputFilter

// If aButtonState is NULL, use the last reported state.
bool IsBeingPressed( const DeviceInput &di, const DeviceInputList *pButtonState = nullptr ) const;
bool IsKBKeyPressed(DeviceButton k) const;
bool IsControlPressed() const;
bool IsShiftPressed() const;
float GetSecsHeld( const DeviceInput &di, const DeviceInputList *pButtonState = nullptr ) const;
float GetLevel( const DeviceInput &di, const DeviceInputList *pButtonState = nullptr ) const;
RString GetButtonComment( const DeviceInput &di ) const;
Expand Down
41 changes: 6 additions & 35 deletions src/ScreenTextEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ScreenPrompt.h"
#include "ScreenTextEntry.h"
#include "ThemeManager.h"
#include "InputFilter.h"
#include "arch/ArchHooks/ArchHooks.h" // HOOKS->GetClipboard()

static const char* g_szKeys[NUM_KeyboardRow][KEYS_PER_ROW] =
Expand Down Expand Up @@ -413,41 +414,8 @@ void ScreenTextEntry::Update( float fDelta )

bool ScreenTextEntry::Input( const InputEventPlus &input )
{
static bool bLCtrl = false, bRCtrl = false;
if( IsTransitioning() )
return false;

// bLCtrl and bRCtl are whether their respective Ctrl keys are held
// We update them here.
if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_LCTRL) )
{
switch( input.type )
{
case IET_FIRST_PRESS:
bLCtrl = true;
break;
case IET_RELEASE:
bLCtrl = false;
break;
default:
break;
}
}

if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_RCTRL) )
{
switch( input.type )
{
case IET_FIRST_PRESS:
bRCtrl = true;
break;
case IET_RELEASE:
bRCtrl = false;
break;
default:
break;
}
}

bool bHandled = false;
if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_BACK) )
Expand All @@ -466,7 +434,9 @@ bool ScreenTextEntry::Input( const InputEventPlus &input )
{
wchar_t c = INPUTMAN->DeviceInputToChar(input.DeviceI,true);
// Detect Ctrl+V
if( ( c == L'v' || c == L'V' ) && ( bLCtrl || bRCtrl ) )
auto ctrlPressed = INPUTFILTER->IsControlPressed();
auto vPressed = input.DeviceI.button == KEY_CV || input.DeviceI.button == KEY_Cv;
if(vPressed && ctrlPressed)
{
TryAppendToAnswer( HOOKS->GetClipboard() );

Expand All @@ -476,7 +446,8 @@ bool ScreenTextEntry::Input( const InputEventPlus &input )
else if( c >= L' ' )
{
// todo: handle caps lock -aj
TryAppendToAnswer( WStringToRString(wstring()+c) );
auto str = WStringToRString(wstring() + c);
TryAppendToAnswer( str );

TextEnteredDirectly();
bHandled = true;
Expand Down

0 comments on commit 3962e55

Please sign in to comment.