From 551172aed3f759afb4a552cc8ab66e127e6505b5 Mon Sep 17 00:00:00 2001 From: "G.K.MacGregor" Date: Sun, 2 May 2021 13:05:49 +0100 Subject: [PATCH] Keep selection position valid if nothing selected --- document.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/document.h b/document.h index b98264c..f542827 100644 --- a/document.h +++ b/document.h @@ -69,12 +69,12 @@ public: void cursorLeft(bool shiftKey=false); void cursorRight(bool shiftKey=false); void moveCursor(int, int, bool selectionInProgress=false); - int selectionTopRow() const { return qMin(m_selectionCornerRow, m_cursorRow); } + int selectionTopRow() const { return m_selectionCornerRow == -1 ? m_cursorRow : qMin(m_selectionCornerRow, m_cursorRow); } int selectionBottomRow() const { return qMax(m_selectionCornerRow, m_cursorRow); } - int selectionLeftColumn() const { return qMin(m_selectionCornerColumn, m_cursorColumn); } + int selectionLeftColumn() const { return m_selectionCornerColumn == -1 ? m_cursorColumn : qMin(m_selectionCornerColumn, m_cursorColumn); } int selectionRightColumn() const { return qMax(m_selectionCornerColumn, m_cursorColumn); } - int selectionWidth() const { return selectionRightColumn() - selectionLeftColumn() + 1; } - int selectionHeight() const { return selectionBottomRow() - selectionTopRow() + 1; } + int selectionWidth() const { return m_selectionCornerColumn == -1 ? 1 : selectionRightColumn() - selectionLeftColumn() + 1; } + int selectionHeight() const { return m_selectionCornerRow == -1 ? 1 : selectionBottomRow() - selectionTopRow() + 1; } bool selectionActive() const { return m_selectionSubPage == currentSubPage(); } void setSelectionCorner(int, int); void setSelection(int, int, int, int);