From 4813d3ae41d97b3aef04e4e59633c4579777abd7 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Sun, 12 Jul 2009 13:31:05 +0000 Subject: [PATCH] branch: Fix bug #4952: Multiple cells pasting fails if cells are selected. When the clipboard contains a tabular selection, dirty_tabular_stack_ is true. However, it is set to false when the user clears a selection (without copying). After this (mostly accidental) action, pasting the tabular contents goes wrong. So, we only clear the dirty_tabular_stack_ flag when a 'real' copy to clipboard has been made. see r29717, r29718, r29719 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@30499 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CutAndPaste.cpp | 6 +++++- src/insets/InsetTabular.cpp | 40 +++++++++++++++++++++++++------------ status.16x | 3 +++ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index c740c269bf..384f854a2d 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -744,7 +744,11 @@ void copySelectionToStack(Cursor const & cur, CutStack & cutstack) copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(), pos, cur.selEnd().pos(), cur.buffer().params().documentClassPtr(), cutstack); - dirtyTabularStack(false); + + // Reset the dirty_tabular_stack_ flag only when something + // is copied to the clipboard (not to the selectionBuffer). + if (&cutstack == &theCuts) + dirtyTabularStack(false); } if (cur.inMathed()) { diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index cd74aa532b..a81f37413d 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -3604,8 +3604,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) cur.recordUndoInset(DELETE_UNDO); cutSelection(cur); } - } - else + } else cell(cur.idx())->dispatch(cur, cmd); break; @@ -3664,7 +3663,8 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_PASTE: if (!tabularStackDirty()) { - cell(cur.idx())->dispatch(cur, cmd); + if (!cur.selIsMultiCell()) + cell(cur.idx())->dispatch(cur, cmd); break; } if (theClipboard().isInternal() || @@ -4004,15 +4004,22 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, return true; case LFUN_PASTE: - if (cur.selIsMultiCell()) { - status.setEnabled(false); - status.message(_("You cannot paste into a multicell selection.")); + if (tabularStackDirty() && theClipboard().isInternal()) { + if (cur.selIsMultiCell()) { + row_type rs, re; + col_type cs, ce; + getSelection(cur, rs, re, cs, ce); + if (paste_tabular && paste_tabular->column_info.size() == ce - cs + 1 + && paste_tabular->row_info.size() == re - rs + 1) + status.setEnabled(true); + else { + status.setEnabled(false); + status.message(_("Selection size should match clipboard content.")); + } + } else + status.setEnabled(true); return true; } - if (tabularStackDirty() && theClipboard().isInternal()) { - status.setEnabled(true); - return true; - } return cell(cur.idx())->getStatus(cur, cmd, status); case LFUN_INSET_MODIFY: @@ -4844,8 +4851,15 @@ bool InsetTabular::pasteClipboard(Cursor & cur) { if (!paste_tabular) return false; - col_type const actcol = tabular.cellColumn(cur.idx()); - row_type const actrow = tabular.cellRow(cur.idx()); + col_type actcol = tabular.cellColumn(cur.idx()); + row_type actrow = tabular.cellRow(cur.idx()); + + if (cur.selIsMultiCell()) { + row_type re; + col_type ce; + getSelection(cur, actrow, re, actcol, ce); + } + for (row_type r1 = 0, r2 = actrow; r1 < paste_tabular->row_info.size() && r2 < tabular.row_info.size(); ++r1, ++r2) { @@ -4853,7 +4867,7 @@ bool InsetTabular::pasteClipboard(Cursor & cur) c1 < paste_tabular->column_info.size() && c2 < tabular.column_info.size(); ++c1, ++c2) { if (paste_tabular->isPartOfMultiColumn(r1, c1) && - tabular.isPartOfMultiColumn(r2, c2)) + tabular.isPartOfMultiColumn(r2, c2)) continue; if (paste_tabular->isPartOfMultiColumn(r1, c1)) { --c2; diff --git a/status.16x b/status.16x index 5214b2abcc..b6d25884e0 100644 --- a/status.16x +++ b/status.16x @@ -192,6 +192,9 @@ What's new - Fix the toggling of the outline-button on the toolbar when closing the outliner with the 'x' (bug 3918). +- Fix the pasting of multiple cells in a table when a range is selected + (bug 4952). + * DOCUMENTATION AND LOCALIZATION