mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Reimplement message history
This commit is contained in:
parent
921379a4cc
commit
d14a5f8067
3 changed files with 60 additions and 16 deletions
|
@ -84,7 +84,10 @@ Rectangle {
|
||||||
TimelineManager.timeline.input.send();
|
TimelineManager.timeline.input.send();
|
||||||
textArea.clear();
|
textArea.clear();
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
}
|
} else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_P)
|
||||||
|
textArea.text = TimelineManager.timeline.input.previousText();
|
||||||
|
else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_N)
|
||||||
|
textArea.text = TimelineManager.timeline.input.nextText();
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
|
|
|
@ -119,39 +119,77 @@ InputBar::updateState(int selectionStart_, int selectionEnd_, int cursorPosition
|
||||||
else
|
else
|
||||||
startTyping();
|
startTyping();
|
||||||
|
|
||||||
|
if (text_ != text()) {
|
||||||
|
if (history_.empty())
|
||||||
|
history_.push_front(text_);
|
||||||
|
else
|
||||||
|
history_.front() = text_;
|
||||||
|
history_index_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
selectionStart = selectionStart_;
|
selectionStart = selectionStart_;
|
||||||
selectionEnd = selectionEnd_;
|
selectionEnd = selectionEnd_;
|
||||||
cursorPosition = cursorPosition_;
|
cursorPosition = cursorPosition_;
|
||||||
text = text_;
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
InputBar::text() const
|
||||||
|
{
|
||||||
|
if (history_index_ < history_.size())
|
||||||
|
return history_.at(history_index_);
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
InputBar::previousText()
|
||||||
|
{
|
||||||
|
history_index_++;
|
||||||
|
if (history_index_ >= INPUT_HISTORY_SIZE)
|
||||||
|
history_index_ = INPUT_HISTORY_SIZE;
|
||||||
|
else if (text().isEmpty())
|
||||||
|
history_index_--;
|
||||||
|
|
||||||
|
return text();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
InputBar::nextText()
|
||||||
|
{
|
||||||
|
history_index_--;
|
||||||
|
if (history_index_ >= INPUT_HISTORY_SIZE)
|
||||||
|
history_index_ = 0;
|
||||||
|
|
||||||
|
return text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
InputBar::send()
|
InputBar::send()
|
||||||
{
|
{
|
||||||
if (text.trimmed().isEmpty())
|
if (text().trimmed().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (history_.size() == INPUT_HISTORY_SIZE)
|
if (text().startsWith('/')) {
|
||||||
history_.pop_back();
|
int command_end = text().indexOf(' ');
|
||||||
history_.push_front(text);
|
|
||||||
history_index_ = 0;
|
|
||||||
|
|
||||||
if (text.startsWith('/')) {
|
|
||||||
int command_end = text.indexOf(' ');
|
|
||||||
if (command_end == -1)
|
if (command_end == -1)
|
||||||
command_end = text.size();
|
command_end = text().size();
|
||||||
auto name = text.mid(1, command_end - 1);
|
auto name = text().mid(1, command_end - 1);
|
||||||
auto args = text.mid(command_end + 1);
|
auto args = text().mid(command_end + 1);
|
||||||
if (name.isEmpty() || name == "/") {
|
if (name.isEmpty() || name == "/") {
|
||||||
message(args);
|
message(args);
|
||||||
} else {
|
} else {
|
||||||
command(name, args);
|
command(name, args);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message(text);
|
message(text());
|
||||||
}
|
}
|
||||||
|
|
||||||
nhlog::ui()->debug("Send: {}", text.toStdString());
|
nhlog::ui()->debug("Send: {}", text().toStdString());
|
||||||
|
|
||||||
|
if (history_.size() == INPUT_HISTORY_SIZE)
|
||||||
|
history_.pop_back();
|
||||||
|
history_.push_front("");
|
||||||
|
history_index_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -30,6 +30,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
QString text() const;
|
||||||
|
QString previousText();
|
||||||
|
QString nextText();
|
||||||
|
|
||||||
void send();
|
void send();
|
||||||
void paste(bool fromMouse);
|
void paste(bool fromMouse);
|
||||||
void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text);
|
void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text);
|
||||||
|
@ -84,7 +88,6 @@ private:
|
||||||
QTimer typingRefresh_;
|
QTimer typingRefresh_;
|
||||||
QTimer typingTimeout_;
|
QTimer typingTimeout_;
|
||||||
TimelineModel *room;
|
TimelineModel *room;
|
||||||
QString text;
|
|
||||||
std::deque<QString> history_;
|
std::deque<QString> history_;
|
||||||
std::size_t history_index_ = 0;
|
std::size_t history_index_ = 0;
|
||||||
int selectionStart = 0, selectionEnd = 0, cursorPosition = 0;
|
int selectionStart = 0, selectionEnd = 0, cursorPosition = 0;
|
||||||
|
|
Loading…
Reference in a new issue