improved keyboard copy/paste selection

This commit is contained in:
thrust26 2020-11-04 14:31:21 +01:00
parent c6093a8d6f
commit 6a19bd66f9
2 changed files with 24 additions and 8 deletions

View File

@ -257,6 +257,7 @@ bool EditableWidget::handleShiftKeys(StellaKey key)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EditableWidget::handleNormalKeys(StellaKey key)
{
bool selectMode = false;
bool handled = true;
switch(key)
@ -264,7 +265,7 @@ bool EditableWidget::handleNormalKeys(StellaKey key)
case KBDK_LSHIFT:
case KBDK_RSHIFT:
// stay in select mode
handled = false;
selectMode = _selectSize;
break;
case KBDK_RETURN:
@ -291,12 +292,16 @@ bool EditableWidget::handleNormalKeys(StellaKey key)
break;
case KBDK_LEFT:
if(_caretPos > 0)
if (_selectSize)
handled = setCaretPos(selectStartPos());
else if(_caretPos > 0)
handled = setCaretPos(_caretPos - 1);
break;
case KBDK_RIGHT:
if(_caretPos < int(_editString.size()))
if(_selectSize)
handled = setCaretPos(selectEndPos());
else if(_caretPos < int(_editString.size()))
handled = setCaretPos(_caretPos + 1);
break;
@ -309,14 +314,14 @@ bool EditableWidget::handleNormalKeys(StellaKey key)
break;
default:
killSelectedText();
handled = false;
}
if(handled)
{
setDirty();
if(!selectMode)
_selectSize = 0;
}
return handled;
}
@ -370,7 +375,7 @@ void EditableWidget::drawSelection()
int w = editRect.w();
int h = editRect.h();
int wt = int(text.length()) * _font.getMaxCharWidth() + 1;
int dx = selectPos() * _font.getMaxCharWidth() - _editScrollOffset;
int dx = selectStartPos() * _font.getMaxCharWidth() - _editScrollOffset;
if(dx < 0)
{
@ -611,7 +616,7 @@ const string EditableWidget::selectString() const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int EditableWidget::selectPos()
int EditableWidget::selectStartPos()
{
if(_selectSize < 0)
return _caretPos + _selectSize;
@ -619,6 +624,16 @@ int EditableWidget::selectPos()
return _caretPos;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int EditableWidget::selectEndPos()
{
if(_selectSize > 0)
return _caretPos + _selectSize;
else
return _caretPos;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EditableWidget::killSelectedText()
{

View File

@ -96,7 +96,8 @@ class EditableWidget : public Widget, public CommandSender
bool moveWord(int direction, bool select);
bool killSelectedText();
int selectPos();
int selectStartPos();
int selectEndPos();
// Clipboard
void cutSelectedText();
void copySelectedText();