[apps] Probability: fix bug; in calculation controller, when reloading cells after editing textfield, do not reload selection (it corrupts the responder chain if the first reponder was a modal view for ex)

This commit is contained in:
Émilie Feral
2018-01-23 15:10:13 +01:00
committed by EmilieNumworks
parent 126212e25b
commit 5d8256435e
3 changed files with 18 additions and 18 deletions

View File

@@ -206,7 +206,11 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int
bool CalculationController::textFieldDidHandleEvent(::TextField * textField, Ion::Events::Event event, bool returnValue, bool textHasChanged) {
if (returnValue && textHasChanged) {
m_selectableTableView.reloadData(); //TODO: optimize with reloadCell at index?
/* We do not reload the responder because the first responder might be the
* toolbox (or the variable box) and reloading the responder would corrupt
* the first responder. */
bool shouldUpdateFirstResponder = app()->firstResponder() == textField;
m_selectableTableView.reloadData(shouldUpdateFirstResponder);
}
return returnValue;
}

View File

@@ -27,12 +27,12 @@ public:
int selectedColumn();
void selectRow(int j);
void selectColumn(int i);
void reloadData(bool reloadSelection = true);
void reloadData(bool setFirstResponder = true);
virtual bool handleEvent(Ion::Events::Event event) override;
virtual void didEnterResponderChain(Responder * previousFirstResponder) override;
virtual void willExitResponderChain(Responder * nextFirstResponder) override;
void deselectTable();
bool selectCellAtLocation(int i, int j);
bool selectCellAtLocation(int i, int j, bool setFirstResponder = true);
HighlightCell * selectedCell();
protected:
SelectableTableViewDataSource * m_selectionDataSource;

View File

@@ -29,22 +29,18 @@ void SelectableTableView::selectColumn(int i) {
m_selectionDataSource->selectColumn(i);
}
void SelectableTableView::reloadData(bool reloadSelection) {
void SelectableTableView::reloadData(bool setFirstResponder) {
int col = selectedColumn();
int row = selectedRow();
if (reloadSelection) {
deselectTable();
/* FIXME: The problem with calling deselectTable is that at this point in time
* the datasource's model is very likely to have changed. Therefore it's
* rather complicated to get a pointer to the currently selected cell (in
* order to deselect it). */
/* As a workaround, datasources can reset the highlighted state in their
* willDisplayCell callback. */
}
deselectTable();
/* FIXME: The problem with calling deselectTable is that at this point in time
* the datasource's model is very likely to have changed. Therefore it's
* rather complicated to get a pointer to the currently selected cell (in
* order to deselect it). */
/* As a workaround, datasources can reset the highlighted state in their
* willDisplayCell callback. */
TableView::layoutSubviews();
if (reloadSelection) {
selectCellAtLocation(col, row);
}
selectCellAtLocation(col, row, setFirstResponder);
}
void SelectableTableView::didEnterResponderChain(Responder * previousFirstResponder) {
@@ -70,7 +66,7 @@ void SelectableTableView::deselectTable() {
}
}
bool SelectableTableView::selectCellAtLocation(int i, int j) {
bool SelectableTableView::selectCellAtLocation(int i, int j, bool setFirstResponder) {
if (i < 0 || i >= dataSource()->numberOfColumns()) {
return false;
}
@@ -89,7 +85,7 @@ bool SelectableTableView::selectCellAtLocation(int i, int j) {
if (cell) {
cell->setHighlighted(true);
// Update first responder
if (i != previousX || j != previousY) {
if ((i != previousX || j != previousY) && setFirstResponder) {
if (cell->responder()) {
app()->setFirstResponder(cell->responder());
} else {