diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index b1783c10c..0b78c8952 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -133,7 +133,7 @@ bool EditableWidget::handleText(char text) if(tryInsertChar(text, _caretPos)) { - _caretPos++; + setCaretPos(_caretPos + 1); sendCommand(EditableWidget::kChangedCmd, 0, _id); setDirty(); return true; @@ -291,7 +291,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod) { // Put caret at last difference myUndoHandler->lastDiff(_editString, oldString); - _caretPos = myUndoHandler->lastDiff(_editString, oldString); + setCaretPos(myUndoHandler->lastDiff(_editString, oldString)); _selectSize = 0; sendCommand(EditableWidget::kChangedCmd, key, _id); } @@ -342,22 +342,7 @@ void EditableWidget::drawCaretSelection() if (!_editable || !isVisible() || !_boss->isVisible() || !_hasFocus) return; - if(_caretEnabled) - { - FBSurface& s = _boss->dialog().surface(); - const Common::Rect& editRect = getEditRect(); - int x = editRect.x(); - int y = editRect.y(); - x += getCaretOffset(); - - x += _x; - y += _y; - - s.vLine(x, y + 2, y + editRect.h() - 2, kTextColorHi); - s.vLine(x-1, y + 2, y + editRect.h() - 2, kTextColorHi); - clearDirty(); - } - + // Draw the selection if(_selectSize) { FBSurface& s = _boss->dialog().surface(); @@ -393,6 +378,24 @@ void EditableWidget::drawCaretSelection() s.drawString(_font, text, x, y + 1, w, h, kTextColorInv, TextAlign::Left, 0, false); } + + // Draw the caret + if(_caretEnabled ^ (_selectSize != 0)) + { + FBSurface& s = _boss->dialog().surface(); + const Common::Rect& editRect = getEditRect(); + int x = editRect.x(); + int y = editRect.y(); + ColorId color = _caretEnabled ? kTextColorHi : kTextColorInv; + + x += getCaretOffset(); + x += _x; + y += _y; + + s.vLine(x, y + 1, y + editRect.h() - 3, color); + s.vLine(x - 1, y + 1, y + editRect.h() - 3, color); + clearDirty(); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -401,6 +404,9 @@ bool EditableWidget::setCaretPos(int newPos) assert(newPos >= 0 && newPos <= int(_editString.size())); _caretPos = newPos; + _caretTimer = 0; + _caretEnabled = true; + return adjustOffset(); } @@ -410,6 +416,8 @@ bool EditableWidget::moveCaretPos(int direction) if(setCaretPos(_caretPos + direction)) { _selectSize -= direction; + _caretTimer = 0; + _caretEnabled = true; return true; } return false; @@ -487,6 +495,7 @@ bool EditableWidget::killChar(int direction, bool addEdit) { myUndoHandler->endChars(_editString); _editString.erase(_caretPos, 1); + setCaretPos(_caretPos); if(addEdit) myUndoHandler->doo(_editString); @@ -591,7 +600,7 @@ bool EditableWidget::moveWord(int direction, bool select) if(select) _selectSize++; } - _caretPos = currentPos; + setCaretPos(currentPos); handled = true; } else if(direction == +1) // move to first character of next word @@ -610,7 +619,7 @@ bool EditableWidget::moveWord(int direction, bool select) if(select) _selectSize--; } - _caretPos = currentPos; + setCaretPos(currentPos); handled = true; } @@ -665,6 +674,7 @@ bool EditableWidget::killSelectedText(bool addEdit) _selectSize = -_selectSize; } _editString.erase(_caretPos, _selectSize); + setCaretPos(_caretPos); _selectSize = 0; if(addEdit) myUndoHandler->doo(_editString); @@ -724,7 +734,7 @@ bool EditableWidget::pasteSelectedText() _editString.insert(_caretPos, buf.str()); // position cursor at the end of pasted text - _caretPos += int(buf.str().length()); + setCaretPos(_caretPos + int(buf.str().length())); if(selected || !pasted.empty()) {