mirror of https://github.com/OpenTTD/OpenTTD
Fix: Reverse left/right keypress when editing RTL text. (#12711)
When editing RTL text, pressing left should increment instead of decrement the character position to move left, and vice versa.pull/12650/head
parent
f87c6990b0
commit
5fefe0b61f
|
@ -322,6 +322,40 @@ void Textbuf::UpdateMarkedText()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move to previous character position.
|
||||||
|
* @param what Move ITER_CHARACTER or ITER_WORD.
|
||||||
|
* @return true iff able to move.
|
||||||
|
*/
|
||||||
|
bool Textbuf::MovePrev(StringIterator::IterType what)
|
||||||
|
{
|
||||||
|
if (this->caretpos == 0) return false;
|
||||||
|
|
||||||
|
size_t pos = this->char_iter->Prev(what);
|
||||||
|
if (pos == StringIterator::END) return true;
|
||||||
|
|
||||||
|
this->caretpos = static_cast<uint16_t>(pos);
|
||||||
|
this->UpdateCaretPosition();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move to next character position.
|
||||||
|
* @param what Move ITER_CHARACTER or ITER_WORD.
|
||||||
|
* @return true iff able to move.
|
||||||
|
*/
|
||||||
|
bool Textbuf::MoveNext(StringIterator::IterType what)
|
||||||
|
{
|
||||||
|
if (this->caretpos >= this->bytes - 1) return false;
|
||||||
|
|
||||||
|
size_t pos = this->char_iter->Next(what);
|
||||||
|
if (pos == StringIterator::END) return true;
|
||||||
|
|
||||||
|
this->caretpos = static_cast<uint16_t>(pos);
|
||||||
|
this->UpdateCaretPosition();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle text navigation with arrow keys left/right.
|
* Handle text navigation with arrow keys left/right.
|
||||||
* This defines where the caret will blink and the next character interaction will occur
|
* This defines where the caret will blink and the next character interaction will occur
|
||||||
|
@ -333,26 +367,14 @@ bool Textbuf::MovePos(uint16_t keycode)
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case WKC_LEFT:
|
case WKC_LEFT:
|
||||||
case WKC_CTRL | WKC_LEFT: {
|
case WKC_CTRL | WKC_LEFT: {
|
||||||
if (this->caretpos == 0) break;
|
auto move_type = (keycode & WKC_CTRL) != 0 ? StringIterator::ITER_WORD : StringIterator::ITER_CHARACTER;
|
||||||
|
return (_current_text_dir == TD_LTR) ? this->MovePrev(move_type) : this->MoveNext(move_type);
|
||||||
size_t pos = this->char_iter->Prev(keycode & WKC_CTRL ? StringIterator::ITER_WORD : StringIterator::ITER_CHARACTER);
|
|
||||||
if (pos == StringIterator::END) return true;
|
|
||||||
|
|
||||||
this->caretpos = (uint16_t)pos;
|
|
||||||
this->UpdateCaretPosition();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case WKC_RIGHT:
|
case WKC_RIGHT:
|
||||||
case WKC_CTRL | WKC_RIGHT: {
|
case WKC_CTRL | WKC_RIGHT: {
|
||||||
if (this->caretpos >= this->bytes - 1) break;
|
auto move_type = (keycode & WKC_CTRL) != 0 ? StringIterator::ITER_WORD : StringIterator::ITER_CHARACTER;
|
||||||
|
return (_current_text_dir == TD_LTR) ? this->MoveNext(move_type) : this->MovePrev(move_type);
|
||||||
size_t pos = this->char_iter->Next(keycode & WKC_CTRL ? StringIterator::ITER_WORD : StringIterator::ITER_CHARACTER);
|
|
||||||
if (pos == StringIterator::END) return true;
|
|
||||||
|
|
||||||
this->caretpos = (uint16_t)pos;
|
|
||||||
this->UpdateCaretPosition();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case WKC_HOME:
|
case WKC_HOME:
|
||||||
|
|
|
@ -72,6 +72,9 @@ private:
|
||||||
|
|
||||||
bool CanDelChar(bool backspace);
|
bool CanDelChar(bool backspace);
|
||||||
|
|
||||||
|
bool MovePrev(StringIterator::IterType what);
|
||||||
|
bool MoveNext(StringIterator::IterType what);
|
||||||
|
|
||||||
void DeleteText(uint16_t from, uint16_t to, bool update);
|
void DeleteText(uint16_t from, uint16_t to, bool update);
|
||||||
|
|
||||||
void UpdateStringIter();
|
void UpdateStringIter();
|
||||||
|
|
Loading…
Reference in New Issue