[escher/text_input] Fix selection algorithm

There was a glitch when :
** are the selected glyphs and | is the cursor

12345678
234567|8    then Shift+up
    **
This commit is contained in:
Léa Saviot
2019-10-11 10:09:19 +02:00
parent e98b67634d
commit 73b1f7da20
2 changed files with 14 additions and 9 deletions

View File

@@ -549,9 +549,9 @@ void TextArea::ContentView::moveCursorGeo(int deltaX, int deltaY) {
}
void TextArea::selectUpDown(bool up) {
const char * currentCursorLocation = contentView()->cursorLocation();
const char * previousCursorLocation = contentView()->cursorLocation();
contentView()->moveCursorGeo(0, up ? -1 : 1);
const char * newCursorLocation = contentView()->cursorLocation();
contentView()->addSelection(up ? newCursorLocation : currentCursorLocation, up ? currentCursorLocation : newCursorLocation);
contentView()->addSelection(up ? newCursorLocation : previousCursorLocation, up ? previousCursorLocation : newCursorLocation);
scrollToCursor();
}

View File

@@ -26,11 +26,6 @@ KDRect TextInput::ContentView::cursorRect() {
}
void TextInput::ContentView::addSelection(const char * left, const char * right) {
if ((left == m_selectionStart && right <= m_selectionEnd)
|| (right == m_selectionEnd && left >= m_selectionStart))
{
return;
}
bool emptySelection = selectionIsEmpty();
if (emptySelection) {
m_selectionStart = left;
@@ -40,10 +35,20 @@ void TextInput::ContentView::addSelection(const char * left, const char * right)
} else if (right == m_selectionStart) {
m_selectionStart = left;
} else if (right == m_selectionEnd) {
m_selectionEnd = left;
if (left >= m_selectionStart) {
m_selectionEnd = left;
} else {
m_selectionEnd = m_selectionStart;
m_selectionStart = left;
}
} else {
assert(left == m_selectionStart);
m_selectionStart = right;
if (right <= m_selectionEnd) {
m_selectionStart = right;
} else {
m_selectionStart = m_selectionEnd;
m_selectionEnd = right;
}
}
reloadRectFromAndToPositions(left, right);
if (m_selectionStart == m_selectionEnd) {