diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index 6fbffd78a..1a7332127 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -211,10 +211,18 @@ void HistoryController::scrollToCell(int i, int j) { m_selectableTableView.scrollToCell(i, j); } -void HistoryController::historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY) { - /* Update the whole table as the height of the selected cell row might have - * changed. */ - m_selectableTableView.reloadData(); +bool HistoryController::calculationAtIndexToggles(int index) { + Context * context = App::app()->localContext(); + return index >= 0 && index < m_calculationStore->numberOfCalculations() && calculationAtIndex(index)->displayOutput(context) == Calculation::DisplayOutput::ExactAndApproximateToggle; +} + +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. */ + if ((type == SubviewType::Output || previousType == SubviewType::Output) && (calculationAtIndexToggles(selectedRow()) || calculationAtIndexToggles(previousSelectedCellY))) { + m_selectableTableView.reloadData(); + } + // Fill the selected cell and the previous selected cell because cells repartition might have changed *cell = static_cast(m_selectableTableView.selectedCell()); *previousCell = static_cast(m_selectableTableView.cellAtLocation(previousSelectedCellX, previousSelectedCellY)); diff --git a/apps/calculation/history_controller.h b/apps/calculation/history_controller.h index 56e9e5094..d0bed934e 100644 --- a/apps/calculation/history_controller.h +++ b/apps/calculation/history_controller.h @@ -35,7 +35,8 @@ private: int storeIndex(int i) { return numberOfRows() - i - 1; } Shared::ExpiringPointer calculationAtIndex(int i); CalculationSelectableTableView * selectableTableView(); - void historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY) override; + bool calculationAtIndexToggles(int index); + void historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY, SubviewType type, SubviewType previousType) override; constexpr static int k_maxNumberOfDisplayedRows = 5; CalculationSelectableTableView m_selectableTableView; HistoryViewCell m_calculationHistory[k_maxNumberOfDisplayedRows]; diff --git a/apps/calculation/history_view_cell.cpp b/apps/calculation/history_view_cell.cpp index e6fa2a706..410604eed 100644 --- a/apps/calculation/history_view_cell.cpp +++ b/apps/calculation/history_view_cell.cpp @@ -17,11 +17,16 @@ HistoryViewCellDataSource::HistoryViewCellDataSource() : m_selectedSubviewType(SubviewType::Output) {} void HistoryViewCellDataSource::setSelectedSubviewType(SubviewType subviewType, bool sameCell, int previousSelectedCellX, int previousSelectedCellY) { - SubviewType previousSubviewType = sameCell ? m_selectedSubviewType : SubviewType::None; - m_selectedSubviewType = subviewType; HistoryViewCell * selectedCell = nullptr; HistoryViewCell * previouslySelectedCell = nullptr; - historyViewCellDidChangeSelection(&selectedCell, &previouslySelectedCell, previousSelectedCellX, previousSelectedCellY); + SubviewType previousSubviewType = m_selectedSubviewType; + m_selectedSubviewType = subviewType; + /* We need to notify the whole table that the selection changed if it + * involves the selection/deselection of an output. Indeed, only them can + * trigger change in the displayed expressions. */ + historyViewCellDidChangeSelection(&selectedCell, &previouslySelectedCell, previousSelectedCellX, previousSelectedCellY, subviewType, previousSubviewType); + + previousSubviewType = sameCell ? previousSubviewType : SubviewType::None; if (selectedCell) { selectedCell->reloadSubviewHighlight(); selectedCell->cellDidSelectSubview(subviewType, previousSubviewType); diff --git a/apps/calculation/history_view_cell.h b/apps/calculation/history_view_cell.h index 5e236efab..42e59719c 100644 --- a/apps/calculation/history_view_cell.h +++ b/apps/calculation/history_view_cell.h @@ -25,7 +25,7 @@ private: * both the data source and the delegate will be the same controller, we * avoid keeping 2 pointers in HistoryViewCell. */ // It returns the selected cell at the end of the method - virtual void historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY) = 0; + virtual void historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY, SubviewType type, SubviewType previousType) = 0; SubviewType m_selectedSubviewType; };