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:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "chatkeyhelper.h"
|
#include "chatkeyhelper.h"
|
||||||
|
|
||||||
|
#include "chatbarcache.h"
|
||||||
#include "chattextitemhelper.h"
|
#include "chattextitemhelper.h"
|
||||||
#include "clipboard.h"
|
#include "clipboard.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
@@ -58,11 +59,6 @@ bool ChatKeyHelper::up(Qt::KeyboardModifiers modifiers)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textItem->isEmpty()) {
|
|
||||||
room->editLastMessage();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textItem->isCompleting) {
|
if (textItem->isCompleting) {
|
||||||
Q_EMIT unhandledUp(true);
|
Q_EMIT unhandledUp(true);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
QPointer<ChatTextItemHelper> textItem;
|
QPointer<ChatTextItemHelper> textItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief handle the given key and modifiers.
|
||||||
|
*/
|
||||||
Q_INVOKABLE bool handleKey(Qt::Key key, Qt::KeyboardModifiers modifiers);
|
Q_INVOKABLE bool handleKey(Qt::Key key, Qt::KeyboardModifiers modifiers);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "chatbarmessagecontentmodel.h"
|
#include "chatbarmessagecontentmodel.h"
|
||||||
|
|
||||||
#include <QTextDocumentFragment>
|
#include <QTextDocumentFragment>
|
||||||
|
#include <qlogging.h>
|
||||||
|
|
||||||
#include "chatbarcache.h"
|
#include "chatbarcache.h"
|
||||||
#include "chatkeyhelper.h"
|
#include "chatkeyhelper.h"
|
||||||
@@ -133,13 +134,17 @@ void ChatBarMessageContentModel::connectKeyHelper()
|
|||||||
if (isCompleting) {
|
if (isCompleting) {
|
||||||
return;
|
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) {
|
connect(m_keyHelper, &ChatKeyHelper::unhandledDown, this, [this](bool isCompleting) {
|
||||||
if (isCompleting) {
|
if (isCompleting) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setFocusRow(m_currentFocusComponent.row() + 1);
|
handleBlockTransition(false);
|
||||||
});
|
});
|
||||||
connect(m_keyHelper, &ChatKeyHelper::unhandledDelete, this, [this]() {
|
connect(m_keyHelper, &ChatKeyHelper::unhandledDelete, this, [this]() {
|
||||||
const auto currentRow = m_currentFocusComponent.row();
|
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
|
void ChatBarMessageContentModel::updateCache() const
|
||||||
{
|
{
|
||||||
if (m_type == ChatBarType::None || !m_room) {
|
if (m_type == ChatBarType::None || !m_room) {
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ private:
|
|||||||
ComponentIt removeComponent(ComponentIt it);
|
ComponentIt removeComponent(ComponentIt it);
|
||||||
void removeComponent(ChatTextItemHelper *textItem);
|
void removeComponent(ChatTextItemHelper *textItem);
|
||||||
|
|
||||||
|
void handleBlockTransition(bool up);
|
||||||
|
|
||||||
void updateCache() const;
|
void updateCache() const;
|
||||||
QString messageText() const;
|
QString messageText() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user