+ wxRichTextCtrl* rtc = buffer->GetRichTextCtrl();
+
+ wxPosition position = GetFocusedCell();
+ int focusCol = position.GetCol();
+ int focusRow = position.GetRow();
+ if (focusCol >= startCol && focusCol < (startCol+noCols))
+ {
+ // Deleting a focused cell causes a segfault later when laying out, due to GetFocusedObject() returning an invalid object
+ if ((startCol + noCols) < m_colCount)
+ {
+ // There are more columns after the one(s) to be deleted, so set focus in the first of them
+ rtc->SetFocusObject(GetCell(focusRow, startCol + noCols));
+ }
+ else
+ {
+ // Otherwise set focus in the preceding column
+ rtc->SetFocusObject(GetCell(focusRow, startCol - 1));
+ }
+ }
+