From 96c7d84633ecc6ba46d2c71136c36ea3769606c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 26 Jun 2020 17:47:52 +0200 Subject: [PATCH] [apps/calculation] Factorize code to avoid selecting ellipsis on cell where ellipsis is not displayed --- apps/calculation/history_controller.cpp | 17 ++++++++++------- apps/calculation/history_controller.h | 1 + apps/calculation/history_view_cell.h | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index 41037c3f6..667c8b14c 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -128,10 +128,6 @@ bool HistoryController::handleEvent(Ion::Events::Event event) { return true; } m_selectableTableView.selectCellAtLocation(0, focusRow > 0 ? focusRow - 1 : 0); - HistoryViewCell * selectedCell = static_cast(m_selectableTableView.selectedCell()); - if (subviewType == SubviewType::Ellipsis && selectedCell->additionalInformationType() == Calculation::AdditionalInformationType::None) { - subviewType = SubviewType::Output; - } setSelectedSubviewType(subviewType, true, 0, selectedRow()); return true; } @@ -168,9 +164,6 @@ void HistoryController::tableViewDidChangeSelectionAndDidScroll(SelectableTableV if (selectedCell && !selectedCell->displaysSingleLine()) { nextSelectedSubviewType = previousSelectedCellY < selectedRow() ? SubviewType::Input : SubviewType::Output; } - if (nextSelectedSubviewType == SubviewType::Ellipsis && selectedCell->additionalInformationType() == Calculation::AdditionalInformationType::None) { - nextSelectedSubviewType = SubviewType::Output; - } setSelectedSubviewType(nextSelectedSubviewType, false, previousSelectedCellX, previousSelectedCellY); } // The selectedCell may change during setSelectedSubviewType @@ -227,6 +220,16 @@ bool HistoryController::calculationAtIndexToggles(int index) { return index >= 0 && index < m_calculationStore->numberOfCalculations() && calculationAtIndex(index)->displayOutput(context) == Calculation::DisplayOutput::ExactAndApproximateToggle; } + +void HistoryController::setSelectedSubviewType(SubviewType subviewType, bool sameCell, int previousSelectedX, int previousSelectedY) { + // Avoid selecting non-displayed ellipsis + HistoryViewCell * selectedCell = static_cast(m_selectableTableView.selectedCell()); + if (subviewType == SubviewType::Ellipsis && selectedCell && selectedCell->additionalInformationType() == Calculation::AdditionalInformationType::None) { + subviewType = SubviewType::Output; + } + HistoryViewCellDataSource::setSelectedSubviewType(subviewType, sameCell, previousSelectedX, previousSelectedY); +} + void HistoryController::historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY, SubviewType type, SubviewType previousType) { /* If the selection change triggers the toggling of the outputs, we update * the whole table as the height of the selected cell row might have changed. */ diff --git a/apps/calculation/history_controller.h b/apps/calculation/history_controller.h index 64d75755c..021a0e876 100644 --- a/apps/calculation/history_controller.h +++ b/apps/calculation/history_controller.h @@ -31,6 +31,7 @@ public: void willDisplayCellForIndex(HighlightCell * cell, int index) override; KDCoordinate rowHeight(int j) override; int typeAtLocation(int i, int j) override; + void setSelectedSubviewType(SubviewType subviewType, bool sameCell, int previousSelectedX = -1, int previousSelectedY = -1) override; void tableViewDidChangeSelectionAndDidScroll(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection = false) override; private: int storeIndex(int i) { return numberOfRows() - i - 1; } diff --git a/apps/calculation/history_view_cell.h b/apps/calculation/history_view_cell.h index c949afe79..7bddbe434 100644 --- a/apps/calculation/history_view_cell.h +++ b/apps/calculation/history_view_cell.h @@ -18,7 +18,7 @@ public: Ellipsis = 3 }; HistoryViewCellDataSource() : m_selectedSubviewType(SubviewType::Output) {} - void setSelectedSubviewType(SubviewType subviewType, bool sameCell, int previousSelectedX = -1, int previousSelectedY = -1); + virtual void setSelectedSubviewType(SubviewType subviewType, bool sameCell, int previousSelectedX = -1, int previousSelectedY = -1); SubviewType selectedSubviewType() const { return m_selectedSubviewType; } private: /* This method should belong to a delegate instead of a data source but as