[escher/text_field] Fix cut event text deletion

If there is a Cut event and the text field is edited but there is no
selection, the text is not stored in the clipboard but it was still
deleted.
This commit is contained in:
Léa Saviot
2020-01-13 11:17:44 +01:00
parent 66cf4ed83f
commit 2fea9d61b6
2 changed files with 6 additions and 4 deletions

View File

@@ -91,7 +91,7 @@ private:
bool privateHandleMoveEvent(Ion::Events::Event event);
bool privateHandleSelectEvent(Ion::Events::Event event);
virtual void removeWholeText();
void storeInClipboard() const;
bool storeInClipboard() const;
TextFieldDelegate * m_delegate;
};

View File

@@ -358,8 +358,7 @@ bool TextField::privateHandleEvent(Ion::Events::Event event) {
return true;
}
if (event == Ion::Events::Copy || event == Ion::Events::Cut) {
storeInClipboard();
if (event == Ion::Events::Cut) {
if (storeInClipboard() && event == Ion::Events::Cut) {
if (!m_contentView.selectionIsEmpty()) {
deleteSelection();
} else {
@@ -542,11 +541,14 @@ void TextField::removeWholeText() {
reloadScroll();
}
void TextField::storeInClipboard() const {
bool TextField::storeInClipboard() const {
if (!isEditing()) {
Clipboard::sharedClipboard()->store(text());
return true;
} else if (!m_contentView.selectionIsEmpty()) {
const char * start = m_contentView.selectionStart();
Clipboard::sharedClipboard()->store(start, m_contentView.selectionEnd() - start);
return true;
}
return false;
}