mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-21 14:50:44 +01:00
[apps/calculation] HistoryViewCell: when reloading the entire table due
to a cell selection, the cell used for the selected row might change. We thereby have to update the selected cell once the table has been reloaded. This fixes the following bug: add 5 times the calculation "12.2". Go up, the selected expression is the left one instead of the right one.
This commit is contained in:
committed by
LeaNumworks
parent
6a5708a562
commit
f3c6aab669
@@ -112,13 +112,12 @@ void HistoryController::tableViewDidChangeSelection(SelectableTableView * t, int
|
||||
if (withinTemporarySelection || previousSelectedCellY == selectedRow()) {
|
||||
return;
|
||||
}
|
||||
HistoryViewCell * cell = static_cast<HistoryViewCell *>(t->selectedCell());
|
||||
if (previousSelectedCellY == -1) {
|
||||
setSelectedSubviewType(SubviewType::Output, cell);
|
||||
setSelectedSubviewType(SubviewType::Output);
|
||||
} else if (selectedRow() < previousSelectedCellY) {
|
||||
setSelectedSubviewType(SubviewType::Output, cell);
|
||||
setSelectedSubviewType(SubviewType::Output);
|
||||
} else if (selectedRow() > previousSelectedCellY) {
|
||||
setSelectedSubviewType(SubviewType::Input, cell);
|
||||
setSelectedSubviewType(SubviewType::Input);
|
||||
}
|
||||
HistoryViewCell * selectedCell = (HistoryViewCell *)(t->selectedCell());
|
||||
if (selectedCell == nullptr) {
|
||||
@@ -166,10 +165,12 @@ void HistoryController::scrollToCell(int i, int j) {
|
||||
m_selectableTableView.scrollToCell(i, j);
|
||||
}
|
||||
|
||||
void HistoryController::historyViewCellDidChangeSelection() {
|
||||
HistoryViewCell * HistoryController::historyViewCellDidChangeSelection() {
|
||||
/* Update the whole table as the height of the selected cell row might have
|
||||
* changed. */
|
||||
m_selectableTableView.reloadData();
|
||||
// Return the selected cell if one
|
||||
return static_cast<HistoryViewCell *>(m_selectableTableView.selectedCell());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
int storeIndex(int i) { return numberOfRows() - i - 1; }
|
||||
Shared::ExpiringPointer<Calculation> calculationAtIndex(int i);
|
||||
CalculationSelectableTableView * selectableTableView();
|
||||
void historyViewCellDidChangeSelection() override;
|
||||
HistoryViewCell * historyViewCellDidChangeSelection() override;
|
||||
constexpr static int k_maxNumberOfDisplayedRows = 5;
|
||||
CalculationSelectableTableView m_selectableTableView;
|
||||
HistoryViewCell m_calculationHistory[k_maxNumberOfDisplayedRows];
|
||||
|
||||
@@ -15,13 +15,13 @@ static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { retur
|
||||
HistoryViewCellDataSource::HistoryViewCellDataSource() :
|
||||
m_selectedSubviewType(SubviewType::Output) {}
|
||||
|
||||
void HistoryViewCellDataSource::setSelectedSubviewType(SubviewType subviewType, HistoryViewCell * cell) {
|
||||
void HistoryViewCellDataSource::setSelectedSubviewType(SubviewType subviewType) {
|
||||
m_selectedSubviewType = subviewType;
|
||||
HistoryViewCell * cell = historyViewCellDidChangeSelection();
|
||||
if (cell) {
|
||||
cell->setHighlighted(cell->isHighlighted());
|
||||
cell->cellDidSelectSubview(subviewType);
|
||||
}
|
||||
historyViewCellDidChangeSelection();
|
||||
}
|
||||
|
||||
/* HistoryViewCell */
|
||||
@@ -185,7 +185,7 @@ bool HistoryViewCell::handleEvent(Ion::Events::Event event) {
|
||||
if ((event == Ion::Events::Down && m_dataSource->selectedSubviewType() == HistoryViewCellDataSource::SubviewType::Input) ||
|
||||
(event == Ion::Events::Up && m_dataSource->selectedSubviewType() == HistoryViewCellDataSource::SubviewType::Output)) {
|
||||
HistoryViewCellDataSource::SubviewType otherSubviewType = m_dataSource->selectedSubviewType() == HistoryViewCellDataSource::SubviewType::Input ? HistoryViewCellDataSource::SubviewType::Output : HistoryViewCellDataSource::SubviewType::Input;
|
||||
m_dataSource->setSelectedSubviewType(otherSubviewType, this);
|
||||
m_dataSource->setSelectedSubviewType(otherSubviewType);
|
||||
CalculationSelectableTableView * tableView = (CalculationSelectableTableView *)parentResponder();
|
||||
tableView->scrollToSubviewOfTypeOfCellAtLocation(otherSubviewType, tableView->selectedColumn(), tableView->selectedRow());
|
||||
Container::activeApp()->setFirstResponder(this);
|
||||
|
||||
@@ -17,13 +17,14 @@ public:
|
||||
Output
|
||||
};
|
||||
HistoryViewCellDataSource();
|
||||
void setSelectedSubviewType(SubviewType subviewType, HistoryViewCell * cell = nullptr);
|
||||
void setSelectedSubviewType(SubviewType subviewType);
|
||||
SubviewType selectedSubviewType() { return m_selectedSubviewType; }
|
||||
private:
|
||||
/* This method should belong to a delegate instead of a data source but as
|
||||
* both the data source and the delegate will be the same controller, we
|
||||
* avoid keeping 2 pointers in HistoryViewCell. */
|
||||
virtual void historyViewCellDidChangeSelection() = 0;
|
||||
// It returns the selected cell at the end of the method
|
||||
virtual HistoryViewCell * historyViewCellDidChangeSelection() = 0;
|
||||
SubviewType m_selectedSubviewType;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user