From 767d1654cc25ca741f46fc0fd29b493fb292c798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 22 Jan 2020 17:12:00 +0100 Subject: [PATCH] [apps/calculation] HistoryViewCell: select the right expression of output when coming from ellipsis subview --- apps/calculation/history_controller.cpp | 8 ++++---- apps/calculation/history_view_cell.cpp | 19 ++++++++++++------- apps/calculation/history_view_cell.h | 7 ++++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index aa5a71bae..6fbffd78a 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -157,13 +157,13 @@ void HistoryController::tableViewDidChangeSelection(SelectableTableView * t, int return; } if (previousSelectedCellY == -1) { - setSelectedSubviewType(SubviewType::Output, previousSelectedCellX, previousSelectedCellY); + setSelectedSubviewType(SubviewType::Output, false, previousSelectedCellX, previousSelectedCellY); } else if (selectedRow() < previousSelectedCellY) { - setSelectedSubviewType(SubviewType::Output, previousSelectedCellX, previousSelectedCellY); + setSelectedSubviewType(SubviewType::Output, false, previousSelectedCellX, previousSelectedCellY); } else if (selectedRow() > previousSelectedCellY) { - setSelectedSubviewType(SubviewType::Input, previousSelectedCellX, previousSelectedCellY); + setSelectedSubviewType(SubviewType::Input, false, previousSelectedCellX, previousSelectedCellY); } else if (selectedRow() == -1) { - setSelectedSubviewType(SubviewType::Input, previousSelectedCellX, previousSelectedCellY); + setSelectedSubviewType(SubviewType::Input, false, previousSelectedCellX, previousSelectedCellY); } HistoryViewCell * selectedCell = (HistoryViewCell *)(t->selectedCell()); if (selectedCell == nullptr) { diff --git a/apps/calculation/history_view_cell.cpp b/apps/calculation/history_view_cell.cpp index 69713ffe3..f64901ff2 100644 --- a/apps/calculation/history_view_cell.cpp +++ b/apps/calculation/history_view_cell.cpp @@ -16,14 +16,15 @@ static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { retur HistoryViewCellDataSource::HistoryViewCellDataSource() : m_selectedSubviewType(SubviewType::Output) {} -void HistoryViewCellDataSource::setSelectedSubviewType(SubviewType subviewType, int previousSelectedCellX, int previousSelectedCellY) { +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); if (selectedCell) { selectedCell->reloadSubviewHighlight(); - selectedCell->cellDidSelectSubview(subviewType); + selectedCell->cellDidSelectSubview(subviewType, previousSubviewType); } if (previouslySelectedCell) { previouslySelectedCell->cellDidSelectSubview(SubviewType::Input); @@ -95,11 +96,15 @@ void HistoryViewCell::reloadScroll() { m_scrollableOutputView.reloadScroll(); } -void HistoryViewCell::reloadOutputSelection() { +void HistoryViewCell::reloadOutputSelection(HistoryViewCellDataSource::SubviewType previousType) { /* Select the right output according to the calculation display output. This * will reload the scroll to display the selected output. */ if (m_calculationDisplayOutput == Calculation::DisplayOutput::ExactAndApproximate) { - m_scrollableOutputView.setSelectedSubviewPosition(Shared::ScrollableTwoExpressionsView::SubviewPosition::Center); + m_scrollableOutputView.setSelectedSubviewPosition( + previousType == HistoryViewCellDataSource::SubviewType::Ellipsis ? + Shared::ScrollableTwoExpressionsView::SubviewPosition::Right : + Shared::ScrollableTwoExpressionsView::SubviewPosition::Center + ); } else { assert((m_calculationDisplayOutput == Calculation::DisplayOutput::ApproximateOnly) || (m_calculationDisplayOutput == Calculation::DisplayOutput::ExactAndApproximateToggle) @@ -108,10 +113,10 @@ void HistoryViewCell::reloadOutputSelection() { } } -void HistoryViewCell::cellDidSelectSubview(HistoryViewCellDataSource::SubviewType type) { +void HistoryViewCell::cellDidSelectSubview(HistoryViewCellDataSource::SubviewType type, HistoryViewCellDataSource::SubviewType previousType) { // Init output selection if (type == HistoryViewCellDataSource::SubviewType::Output) { - reloadOutputSelection(); + reloadOutputSelection(previousType); } // Update m_calculationExpanded @@ -284,7 +289,7 @@ bool HistoryViewCell::handleEvent(Ion::Events::Event event) { assert(event == Ion::Events::Left); otherSubviewType = HistoryViewCellDataSource::SubviewType::Output; } - m_dataSource->setSelectedSubviewType(otherSubviewType); + m_dataSource->setSelectedSubviewType(otherSubviewType, true); CalculationSelectableTableView * tableView = (CalculationSelectableTableView *)parentResponder(); tableView->scrollToSubviewOfTypeOfCellAtLocation(otherSubviewType, tableView->selectedColumn(), tableView->selectedRow()); Container::activeApp()->setFirstResponder(this); diff --git a/apps/calculation/history_view_cell.h b/apps/calculation/history_view_cell.h index dc56c9237..5e236efab 100644 --- a/apps/calculation/history_view_cell.h +++ b/apps/calculation/history_view_cell.h @@ -12,12 +12,13 @@ class HistoryViewCell; class HistoryViewCellDataSource { public: enum class SubviewType { + None, Input, Output, Ellipsis }; HistoryViewCellDataSource(); - void setSelectedSubviewType(SubviewType subviewType, int previousSelectedX = -1, int previousSelectedY = -1); + void setSelectedSubviewType(SubviewType subviewType, bool sameCell, int previousSelectedX = -1, int previousSelectedY = -1); SubviewType selectedSubviewType() { return m_selectedSubviewType; } private: /* This method should belong to a delegate instead of a data source but as @@ -31,7 +32,7 @@ private: class HistoryViewCell : public ::EvenOddCell, public Responder { public: HistoryViewCell(Responder * parentResponder = nullptr); - void cellDidSelectSubview(HistoryViewCellDataSource::SubviewType type); + void cellDidSelectSubview(HistoryViewCellDataSource::SubviewType type, HistoryViewCellDataSource::SubviewType previousType = HistoryViewCellDataSource::SubviewType::None); void setEven(bool even) override; void setHighlighted(bool highlight) override; void reloadSubviewHighlight(); @@ -52,7 +53,7 @@ public: private: constexpr static KDCoordinate k_resultWidth = 80; void reloadScroll(); - void reloadOutputSelection(); + void reloadOutputSelection(HistoryViewCellDataSource::SubviewType previousType); bool displayedEllipsis() const; uint32_t m_calculationCRC32; Calculation::DisplayOutput m_calculationDisplayOutput;