Change editing so that going up or down from a code or quote a para will be added if one doesn't exist so that the block can te typed around

This commit is contained in:
James Graham
2026-01-08 19:23:50 +00:00
parent d0abfe60f9
commit d64e6fc206
4 changed files with 40 additions and 7 deletions

View File

@@ -3,6 +3,7 @@
#include "chatkeyhelper.h"
#include "chatbarcache.h"
#include "chattextitemhelper.h"
#include "clipboard.h"
#include "neochatroom.h"
@@ -58,11 +59,6 @@ bool ChatKeyHelper::up(Qt::KeyboardModifiers modifiers)
return true;
}
if (textItem->isEmpty()) {
room->editLastMessage();
return true;
}
if (textItem->isCompleting) {
Q_EMIT unhandledUp(true);
return true;

View File

@@ -40,6 +40,9 @@ public:
*/
QPointer<ChatTextItemHelper> textItem;
/**
* @brief handle the given key and modifiers.
*/
Q_INVOKABLE bool handleKey(Qt::Key key, Qt::KeyboardModifiers modifiers);
Q_SIGNALS:

View File

@@ -4,6 +4,7 @@
#include "chatbarmessagecontentmodel.h"
#include <QTextDocumentFragment>
#include <qlogging.h>
#include "chatbarcache.h"
#include "chatkeyhelper.h"
@@ -133,13 +134,17 @@ void ChatBarMessageContentModel::connectKeyHelper()
if (isCompleting) {
return;
}
setFocusRow(m_currentFocusComponent.row() - 1);
if (!m_room->editCache()->isEditing() && m_currentFocusComponent.row() <= 0 && focusedTextItem()->isEmpty()) {
m_room->editLastMessage();
return;
}
handleBlockTransition(true);
});
connect(m_keyHelper, &ChatKeyHelper::unhandledDown, this, [this](bool isCompleting) {
if (isCompleting) {
return;
}
setFocusRow(m_currentFocusComponent.row() + 1);
handleBlockTransition(false);
});
connect(m_keyHelper, &ChatKeyHelper::unhandledDelete, this, [this]() {
const auto currentRow = m_currentFocusComponent.row();
@@ -460,6 +465,33 @@ void ChatBarMessageContentModel::removeComponent(ChatTextItemHelper *textItem)
}
}
void ChatBarMessageContentModel::handleBlockTransition(bool up)
{
const auto currentRow = m_currentFocusComponent.row();
const auto insertRow = currentRow + (up ? 0 : 1);
const auto atEdge = up ? currentRow <= 0 : currentRow >= rowCount() - 1;
const auto notText = focusType() != MessageComponentType::Text;
if (atEdge && notText) {
insertComponent(insertRow, MessageComponentType::Text);
setFocusRow(insertRow);
return;
}
const auto nextRow = currentRow + (up ? -1 : 1);
const auto nextNotText = m_components[nextRow].type != MessageComponentType::Text;
if (notText && nextNotText) {
insertComponent(insertRow, MessageComponentType::Text);
setFocusRow(insertRow);
return;
}
const auto currentItemEmptyText = focusedTextItem()->isEmpty() && focusType() == MessageComponentType::Text;
setFocusRow(nextRow);
if (currentItemEmptyText && !atEdge) {
removeComponent(currentRow);
}
}
void ChatBarMessageContentModel::updateCache() const
{
if (m_type == ChatBarType::None || !m_room) {

View File

@@ -111,6 +111,8 @@ private:
ComponentIt removeComponent(ComponentIt it);
void removeComponent(ChatTextItemHelper *textItem);
void handleBlockTransition(bool up);
void updateCache() const;
QString messageText() const;