[escher/text_input] Fix reload and scroll after deleteSelectedText

This commit is contained in:
Léa Saviot
2019-10-11 11:09:39 +02:00
parent 20c761d3f0
commit 9c5843500a
3 changed files with 39 additions and 19 deletions

View File

@@ -84,6 +84,9 @@ void TextInput::ContentView::reloadRectFromPosition(const char * position, bool
}
void TextInput::ContentView::reloadRectFromAndToPositions(const char * start, const char * end) {
if (start == end) {
return;
}
KDRect startFrame = glyphFrameAtPosition(text(), start);
KDRect endFrame = glyphFrameAtPosition(text(), end);
bool onSameLine = startFrame.y() == endFrame.y();
@@ -132,6 +135,17 @@ void TextInput::scrollToCursor() {
scrollToContentRect(contentView()->cursorRect(), true);
}
void TextInput::deleteSelectedText() {
assert(!contentView()->selectionIsEmpty());
const char * previousSelectionStart = contentView()->selectionStart();
const char * previousSelectionEnd = contentView()->selectionEnd();
size_t removedLength = contentView()->deleteSelectedText();
if (previousSelectionEnd == contentView()->cursorLocation()) {
setCursorLocation(contentView()->cursorLocation() - removedLength);
}
contentView()->reloadRectFromPosition(previousSelectionStart, true);
}
bool TextInput::setCursorLocation(const char * location) {
assert(location != nullptr);
const char * adjustedLocation = maxCharPointer(location, text());