first, the bugs I noticed in both old and new code :
1) attached file : selection the multicolumn cell, then press up. the topright cell is not selected. 2) TableExamples.lyx - the minipage is screwed ! Now, my patch. 1) 1x1 entire table selections work perfectly. 2) more spreadsheet like feel 3) visible single-cell selection 4) cleaner code (useful later on for adding the handles) 5) with this code, I can't see a user-visible reason for the dummy cursor position ... Juergen ? Others are welcome to try it ... thanks john -- "Faced with the prospect of rereading this book, I would rather have my brains ripped out by a plastic fork." - Charles Cooper on "Business at the Speed of Thought"
#LyX 1.2 created this file. For more info see http://www.lyx.org/ \lyxformat 220 \textclass article \language english \inputencoding auto \fontscheme default \graphics default \paperfontsize default \spacing single \papersize Default \paperpackage a4 \use_geometry 0 \use_amsmath 0 \use_natbib 0 \use_numerical_citations 0 \paperorientation portrait \secnumdepth 3 \tocdepth 3 \paragraph_separation skip \defskip medskip \quotes_language english \quotes_times 2 \papercolumns 1 \papersides 1 \paperpagestyle default \layout Standard \begin_inset Tabular <lyxtabular version="2" rows="5" columns="5"> <features rotate="false" islongtable="false" endhead="0" endfirsthead="0" endfoot="0" endlastfoot="0"> <column alignment="center" valignment="top" leftline="true" rightline="false" width="" special=""> <column alignment="center" valignment="top" leftline="true" rightline="false" width="" special=""> <column alignment="center" valignment="top" leftline="true" rightline="false" width="" special=""> <column alignment="center" valignment="top" leftline="true" rightline="false" width="" special=""> <column alignment="center" valignment="top" leftline="true" rightline="true" width="" special=""> <row topline="true" bottomline="true" newpage="false"> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard a \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard b \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard c \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard d \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard e \end_inset </cell> </row> <row topline="true" bottomline="false" newpage="false"> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard g \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard f \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard e \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> </row> <row topline="true" bottomline="false" newpage="false"> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard h \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard egreg \end_inset </cell> </row> <row topline="true" bottomline="false" newpage="false"> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard gergre \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard rggre \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard gregerg \end_inset </cell> </row> <row topline="true" bottomline="true" newpage="false"> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard gregreg \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard gre \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard rgreg \end_inset </cell> </row> </lyxtabular> \end_inset \layout Standard \begin_inset Tabular <lyxtabular version="2" rows="5" columns="5"> <features rotate="false" islongtable="false" endhead="0" endfirsthead="0" endfoot="0" endlastfoot="0"> <column alignment="center" valignment="top" leftline="true" rightline="false" width="" special=""> <column alignment="center" valignment="top" leftline="true" rightline="false" width="" special=""> <column alignment="center" valignment="top" leftline="true" rightline="false" width="" special=""> <column alignment="center" valignment="top" leftline="true" rightline="false" width="" special=""> <column alignment="center" valignment="top" leftline="true" rightline="true" width="" special=""> <row topline="true" bottomline="true" newpage="false"> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> </row> <row topline="true" bottomline="false" newpage="false"> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="2" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> </row> <row topline="true" bottomline="false" newpage="false"> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="2" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="2" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> </row> <row topline="true" bottomline="false" newpage="false"> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> </row> <row topline="true" bottomline="true" newpage="false"> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special=""> \begin_inset Text \layout Standard \end_inset </cell> </row> </lyxtabular> \end_inset \the_end
Index: src/insets/insettabular.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.h,v retrieving revision 1.79 diff -u -r1.79 insettabular.h --- src/insets/insettabular.h 2001/11/28 16:09:25 1.79 +++ src/insets/insettabular.h 2001/12/06 03:03:08 @@ -269,12 +269,18 @@ void removeTabularRow(); /// bool hasSelection() const { - return sel_cell_start != sel_cell_end; + return has_selection; } /// void clearSelection() const { - sel_cell_start = sel_cell_end = 0; + sel_cell_start = sel_cell_end = 0; + has_selection = false; } + void setSelection(int start, int end) const { + sel_cell_start = start; + sel_cell_end = end; + has_selection = true; + } /// bool activateCellInset(BufferView *, int x = 0, int y = 0, int button = 0, @@ -316,9 +322,11 @@ mutable unsigned int inset_x; /// mutable unsigned int inset_y; - /// + /// true if a set of cells are selected + mutable bool has_selection; + /// the starting cell selection nr mutable int sel_cell_start; - /// + /// the ending cell selection nr mutable int sel_cell_end; /// mutable int actcell; Index: src/insets/insettabular.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v retrieving revision 1.149 diff -u -r1.149 insettabular.C --- src/insets/insettabular.C 2001/12/05 08:04:18 1.149 +++ src/insets/insettabular.C 2001/12/06 03:03:12 @@ -134,7 +134,7 @@ // for now make it always display as display() inset // just for test!!! the_locking_inset = 0; - locked = no_selection = false; + locked = false; oldcell = -1; actrow = actcell = 0; clearSelection(); @@ -150,10 +150,10 @@ { tabular.reset(new LyXTabular(this, *(tab.tabular), same_id)); the_locking_inset = 0; - locked = no_selection = false; + locked = false; oldcell = -1; actrow = actcell = 0; - sel_cell_start = sel_cell_end = 0; + clearSelection(); need_update = INIT; in_update = false; in_reset_pos = false; @@ -296,11 +296,11 @@ cx = nx + tabular->GetBeginningOfTextInCell(cell); if (first_visible_cell < 0) first_visible_cell = cell; - if (hasSelection()) + if (hasSelection()) { drawCellSelection(pain, nx, baseline, i, j, cell); + } - tabular->GetCellInset(cell)->draw(bv, font, baseline, cx, - cleared); + tabular->GetCellInset(cell)->draw(bv, font, baseline, +cx, cleared); drawCellLines(pain, nx, baseline, i, cell); nx += tabular->GetWidthOfColumn(cell); ++cell; @@ -448,6 +448,7 @@ void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline, int row, int column, int cell) const { + lyx::Assert(hasSelection()); int cs = tabular->column_of_cell(sel_cell_start); int ce = tabular->column_of_cell(sel_cell_end); if (cs > ce) { @@ -534,7 +535,7 @@ inset_x = 0; inset_y = 0; setPos(bv, x, y); - sel_cell_start = sel_cell_end = actcell; + clearSelection(); finishUndo(); if (insetHit(bv, x, y) && (button != 3)) { activateCellInsetAbs(bv, x, y, button); @@ -558,7 +559,7 @@ actcell = 0; else actcell = tabular->GetNumberOfCells() - 1; - sel_cell_start = sel_cell_end = actcell; + clearSelection(); resetPos(bv); finishUndo(); } @@ -571,11 +572,10 @@ the_locking_inset = 0; } hideInsetCursor(bv); - no_selection = false; oldcell = -1; locked = false; if (scroll(false) || hasSelection()) { - sel_cell_start = sel_cell_end = 0; + clearSelection(); if (scroll(false)) { scroll(bv, 0.0F); } @@ -593,8 +593,9 @@ } if (need_update < what) // only set this if it has greater update need_update = what; - if ((what == INIT) && hasSelection()) + if ((what == INIT) && hasSelection()) { clearSelection(); + } // Dirty Cast! (Lgb) if (need_update != NONE) { bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty); @@ -716,8 +717,6 @@ updateLocal(bv, SELECTION, false); } - no_selection = false; - int const ocell = actcell; int const orow = actrow; @@ -725,7 +724,7 @@ setPos(bv, x, y); if (actrow != orow) updateLocal(bv, NONE, false); - sel_cell_start = sel_cell_end = actcell; + clearSelection(); if (button == 3) { if ((ocell != actcell) && the_locking_inset) { the_locking_inset->insetUnlock(bv); @@ -783,7 +782,6 @@ button); return; } - no_selection = false; } @@ -796,17 +794,18 @@ button); return; } - if (!no_selection) { - hideInsetCursor(bv); - int const old_cell = actcell; - - setPos(bv, x, y); - sel_cell_end = actcell; - if (sel_cell_end != old_cell) - updateLocal(bv, SELECTION, false); - showInsetCursor(bv); + + hideInsetCursor(bv); + int const old_cell = actcell; + + setPos(bv, x, y); + if (!hasSelection()) { + setSelection(actcell, actcell); + } else { + setSelection(sel_cell_start, actcell); } - no_selection = false; + updateLocal(bv, SELECTION, false); + showInsetCursor(bv); } @@ -826,7 +825,6 @@ // We need to save the value of the_locking_inset as the call to // the_locking_inset->LocalDispatch might unlock it. old_locking_inset = the_locking_inset; - no_selection = false; UpdatableInset::RESULT result = UpdatableInset::localDispatch(bv, action, arg); if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) { @@ -855,7 +853,7 @@ moveNextCell(bv, old_locking_inset != 0); else movePrevCell(bv, old_locking_inset != 0); - sel_cell_start = sel_cell_end = actcell; + clearSelection(); if (hs) updateLocal(bv, SELECTION, false); if (!the_locking_inset) { @@ -898,65 +896,96 @@ result=DISPATCHED; switch (action) { // --- Cursor Movements ---------------------------------- - case LFUN_RIGHTSEL: - if (tabular->IsLastCellInRow(actcell)) + case LFUN_RIGHTSEL: { + int const start = hasSelection() ? sel_cell_start : actcell; + if (tabular->IsLastCellInRow(actcell)) { + setSelection(start, actcell); break; - moveRight(bv, false); - sel_cell_end = actcell; + } + + int end = actcell; + // if we are starting a selection, only select + // the current cell at the beginning + if (hasSelection()) { + moveRight(bv, false); + end = actcell; + } + setSelection(start, end); updateLocal(bv, SELECTION, false); break; + } case LFUN_RIGHT: result = moveRight(bv); - sel_cell_start = sel_cell_end = actcell; + clearSelection(); if (hs) updateLocal(bv, SELECTION, false); break; - case LFUN_LEFTSEL: - if (tabular->IsFirstCellInRow(actcell)) + case LFUN_LEFTSEL: { + int const start = hasSelection() ? sel_cell_start : actcell; + if (tabular->IsFirstCellInRow(actcell)) { + setSelection(start, actcell); break; - moveLeft(bv, false); - sel_cell_end = actcell; + } + + int end = actcell; + // if we are starting a selection, only select + // the current cell at the beginning + if (hasSelection()) { + moveLeft(bv, false); + end = actcell; + } + setSelection(start, end); updateLocal(bv, SELECTION, false); break; + } case LFUN_LEFT: result = moveLeft(bv); - sel_cell_start = sel_cell_end = actcell; + clearSelection(); if (hs) updateLocal(bv, SELECTION, false); break; - case LFUN_DOWNSEL: - { + case LFUN_DOWNSEL: { + int const start = hasSelection() ? sel_cell_start : actcell; int const ocell = actcell; - moveDown(bv, false); + // if we are starting a selection, only select + // the current cell at the beginning + if (hasSelection()) { + moveDown(bv, false); + } if ((ocell == sel_cell_end) || (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell))) - sel_cell_end = tabular->GetCellBelow(sel_cell_end); + setSelection(start, tabular->GetCellBelow(sel_cell_end)); else - sel_cell_end = tabular->GetLastCellBelow(sel_cell_end); + setSelection(start, tabular->GetLastCellBelow(sel_cell_end)); updateLocal(bv, SELECTION, false); } break; case LFUN_DOWN: result = moveDown(bv, old_locking_inset != 0); - sel_cell_start = sel_cell_end = actcell; - if (hs) + clearSelection(); + if (hs) { updateLocal(bv, SELECTION, false); + } break; - case LFUN_UPSEL: - { + case LFUN_UPSEL: { + int const start = hasSelection() ? sel_cell_start : actcell; int const ocell = actcell; - moveUp(bv, false); + // if we are starting a selection, only select + // the current cell at the beginning + if (hasSelection()) { + moveUp(bv, false); + } if ((ocell == sel_cell_end) || (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell))) - sel_cell_end = tabular->GetCellAbove(sel_cell_end); + setSelection(start, tabular->GetCellAbove(sel_cell_end)); else - sel_cell_end = tabular->GetLastCellAbove(sel_cell_end); + setSelection(start, tabular->GetLastCellAbove(sel_cell_end)); updateLocal(bv, SELECTION, false); } break; case LFUN_UP: result = moveUp(bv, old_locking_inset != 0); - sel_cell_start = sel_cell_end = actcell; + clearSelection(); if (hs) updateLocal(bv, SELECTION, false); break; @@ -1585,8 +1614,7 @@ bool selectall) { if (selectall) { - sel_cell_start = 0; - sel_cell_end = tabular->GetNumberOfCells() - 1; + setSelection(0, tabular->GetNumberOfCells() - 1); } if (hasSelection()) { setUndo(bv, Undo::EDIT, @@ -1884,7 +1912,7 @@ } tabular->SetMultiColumn(s_start, s_end - s_start + 1); actcell = s_start; - sel_cell_end = sel_cell_start; + clearSelection(); updateLocal(bv, INIT, true); break; } @@ -2485,17 +2513,22 @@ void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const { - srow = tabular->row_of_cell(sel_cell_start); - erow = tabular->row_of_cell(sel_cell_end); - if (srow > erow) - swap(srow, erow); - - scol = tabular->column_of_cell(sel_cell_start); - ecol = tabular->column_of_cell(sel_cell_end); - if (scol > ecol) - swap(scol, ecol); - else - ecol = tabular->right_column_of_cell(sel_cell_end); + int const start = hasSelection() ? sel_cell_start : actcell; + int const end = hasSelection() ? sel_cell_end : actcell; + + srow = tabular->row_of_cell(start); + erow = tabular->row_of_cell(end); + if (srow > erow) { + swap(srow, erow); + } + + scol = tabular->column_of_cell(start); + ecol = tabular->column_of_cell(end); + if (scol > ecol) { + swap(scol, ecol); + } else { + ecol = tabular->right_column_of_cell(end); + } }