From 9398c5004ca33a4db20b3bd420ca4193234287f6 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Tue, 11 Oct 2022 17:58:49 +0200 Subject: [PATCH] Reintroduce selectionStart, selectionEnd --- src/chatdocumenthandler.cpp | 30 ++++++++++++++++++++++++++++++ src/chatdocumenthandler.h | 13 +++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/chatdocumenthandler.cpp b/src/chatdocumenthandler.cpp index 4b8a07809..300d3ab53 100644 --- a/src/chatdocumenthandler.cpp +++ b/src/chatdocumenthandler.cpp @@ -242,3 +242,33 @@ CompletionModel *ChatDocumentHandler::completionModel() const { return m_completionModel; } + +int ChatDocumentHandler::selectionStart() const +{ + return m_selectionStart; +} + +void ChatDocumentHandler::setSelectionStart(int position) +{ + if (position == m_selectionStart) { + return; + } + + m_selectionStart = position; + Q_EMIT selectionStartChanged(); +} + +int ChatDocumentHandler::selectionEnd() const +{ + return m_selectionEnd; +} + +void ChatDocumentHandler::setSelectionEnd(int position) +{ + if (position == m_selectionEnd) { + return; + } + + m_selectionEnd = position; + Q_EMIT selectionEndChanged(); +} diff --git a/src/chatdocumenthandler.h b/src/chatdocumenthandler.h index 4147760d9..bba636236 100644 --- a/src/chatdocumenthandler.h +++ b/src/chatdocumenthandler.h @@ -20,6 +20,9 @@ class ChatDocumentHandler : public QObject Q_OBJECT Q_PROPERTY(QQuickTextDocument *document READ document WRITE setDocument NOTIFY documentChanged) Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) + Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) + Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) + Q_PROPERTY(CompletionModel *completionModel READ completionModel NOTIFY completionModelChanged) Q_PROPERTY(NeoChatRoom *room READ room NOTIFY roomChanged) @@ -42,6 +45,12 @@ public: [[nodiscard]] int cursorPosition() const; void setCursorPosition(int position); + [[nodiscard]] int selectionStart() const; + void setSelectionStart(int position); + + [[nodiscard]] int selectionEnd() const; + void setSelectionEnd(int position); + [[nodiscard]] NeoChatRoom *room() const; void setRoom(NeoChatRoom *room); @@ -54,6 +63,8 @@ Q_SIGNALS: void cursorPositionChanged(); void roomChanged(); void completionModelChanged(); + void selectionStartChanged(); + void selectionEndChanged(); private: int completionStartIndex() const; @@ -64,6 +75,8 @@ private: bool completionVisible = false; int m_cursorPosition; + int m_selectionStart; + int m_selectionEnd; SyntaxHighlighter *m_highlighter = nullptr;