mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[escher/text_input] Fix cursor position when deleting selection
This commit is contained in:
@@ -60,6 +60,7 @@ protected:
|
||||
|
||||
// Alignment
|
||||
void setAlignment(float horizontalAlignment, float verticalAlignment);
|
||||
float horizontalAlignment() const { return m_horizontalAlignment; }
|
||||
|
||||
// Reload
|
||||
void reloadRectFromPosition(const char * position, bool includeFollowingLines = false);
|
||||
|
||||
@@ -151,15 +151,19 @@ void TextInput::scrollToCursor() {
|
||||
}
|
||||
|
||||
void TextInput::deleteSelection() {
|
||||
assert(!contentView()->selectionIsEmpty());
|
||||
const char * previousSelectionStart = contentView()->selectionStart();
|
||||
const char * previousSelectionEnd = contentView()->selectionEnd();
|
||||
bool cursorIsAtEndOfSelection = previousSelectionEnd == contentView()->cursorLocation();
|
||||
size_t removedLength = contentView()->deleteSelection();
|
||||
if (cursorIsAtEndOfSelection) {
|
||||
setCursorLocation(contentView()->cursorLocation() - removedLength);
|
||||
ContentView * cv = contentView();
|
||||
assert(!cv->selectionIsEmpty());
|
||||
const float horizontalAlignment = cv->horizontalAlignment();
|
||||
if (horizontalAlignment == 0.0f) {
|
||||
cv->reloadRectFromPosition(cv->selectionStart(), true);
|
||||
}
|
||||
contentView()->reloadRectFromPosition(previousSelectionStart, true);
|
||||
bool cursorIsAtEndOfSelection = cv->selectionEnd() == cv->cursorLocation();
|
||||
size_t removedLength = cv->deleteSelection();
|
||||
if (cursorIsAtEndOfSelection) {
|
||||
setCursorLocation(cv->cursorLocation() - removedLength);
|
||||
}
|
||||
layoutSubviews(true); // Set the cursor frame by calling the subviews relayouting
|
||||
scrollToCursor();
|
||||
}
|
||||
|
||||
void TextInput::setAlignment(float horizontalAlignment, float verticalAlignment) {
|
||||
|
||||
Reference in New Issue
Block a user