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

View File

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