mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-23 03:18:49 +03:00
Move the cursor to the start/end of the text before we move up/down in history
fixes #166
This commit is contained in:
parent
af5663b6bc
commit
caf5b70994
1 changed files with 18 additions and 2 deletions
|
@ -87,22 +87,38 @@ FilteredTextEdit::keyPressEvent(QKeyEvent *event)
|
||||||
case Qt::Key_Up: {
|
case Qt::Key_Up: {
|
||||||
auto initial_cursor = textCursor();
|
auto initial_cursor = textCursor();
|
||||||
QTextEdit::keyPressEvent(event);
|
QTextEdit::keyPressEvent(event);
|
||||||
if (textCursor() == initial_cursor &&
|
|
||||||
|
if (textCursor() == initial_cursor && textCursor().atStart() &&
|
||||||
history_index_ + 1 < working_history_.size()) {
|
history_index_ + 1 < working_history_.size()) {
|
||||||
++history_index_;
|
++history_index_;
|
||||||
setPlainText(working_history_[history_index_]);
|
setPlainText(working_history_[history_index_]);
|
||||||
moveCursor(QTextCursor::End);
|
moveCursor(QTextCursor::End);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move to the start of the text if there aren't any lines to move up to.
|
||||||
|
if (textCursor() == initial_cursor) {
|
||||||
|
initial_cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
|
||||||
|
setTextCursor(initial_cursor);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Qt::Key_Down: {
|
case Qt::Key_Down: {
|
||||||
auto initial_cursor = textCursor();
|
auto initial_cursor = textCursor();
|
||||||
QTextEdit::keyPressEvent(event);
|
QTextEdit::keyPressEvent(event);
|
||||||
if (textCursor() == initial_cursor && history_index_ > 0) {
|
|
||||||
|
if (textCursor() == initial_cursor && textCursor().atEnd() && history_index_ > 0) {
|
||||||
--history_index_;
|
--history_index_;
|
||||||
setPlainText(working_history_[history_index_]);
|
setPlainText(working_history_[history_index_]);
|
||||||
moveCursor(QTextCursor::End);
|
moveCursor(QTextCursor::End);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move to the end of the text if there aren't any lines to move down to.
|
||||||
|
if (textCursor() == initial_cursor) {
|
||||||
|
initial_cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor, 1);
|
||||||
|
setTextCursor(initial_cursor);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue