I do not think the analysis is correct. The real problem is that saveSelection is not prepared (like most of our cut-and-paste mechanism) to handle multi-cell selections.
How come my analysis is incorrect? We are talking about the same thing. I said: saveSelection can not handle this case so I do not call it. You said: let me disable this case in saveSelection. I actually said: saveSelection should not be called in this case. Because when cur is undispatched with cmd=LFUN_FINISHED_RIGHT, further processing is planned. The problem is actually that LFUN_FINISHED_RIGHT is NOT processed in InsetTabular.cpp. This is my solution2 that I was too lazy to pursue. The attached patch combines our patches, and handles LFUN_FINISHED_RIGHT. With this patch, saveSelection() saves the correct selection. Your patch is not triggered but can be put there anyway, just to be safe. Cheers, Bo
Index: src/insets/InsetTabular.cpp =================================================================== --- src/insets/InsetTabular.cpp (revision 18698) +++ src/insets/InsetTabular.cpp (working copy) @@ -3265,7 +3265,11 @@ cell(cur.idx())->dispatch(cur, cmd); if (!cur.result().dispatched()) { isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur); - if (cmd.action == LFUN_CHAR_FORWARD_SELECT) + // The second case happens when LFUN_CHAR_FORWARD_SELECT + // is called, but the cursor is undispatched with cmd modified + // to LFUN_FINISHED_RIGHT (e.g. a case in bug 3782) + if (cmd.action == LFUN_CHAR_FORWARD_SELECT || + cmd.action == LFUN_FINISHED_RIGHT) saveSelection(cur); if (sl == cur.top()) cmd = FuncRequest(LFUN_FINISHED_RIGHT); Index: src/CutAndPaste.cpp =================================================================== --- src/CutAndPaste.cpp (revision 18698) +++ src/CutAndPaste.cpp (working copy) @@ -607,6 +607,10 @@ if (!cur.selection()) return; + // copySelection can not yet handle the case of cross idx selection + if (cur.selBegin().idx() != cur.selEnd().idx()) + return; + if (cur.inTexted()) { Text * text = cur.text(); BOOST_ASSERT(text); Index: src/Text3.cpp =================================================================== --- src/Text3.cpp (revision 18698) +++ src/Text3.cpp (working copy) @@ -457,8 +457,7 @@ && cur.boundary() == oldBoundary) { cur.undispatched(); cmd = FuncRequest(LFUN_FINISHED_RIGHT); - } - if (cur.selection()) + } else if (cur.selection()) saveSelection(cur); break;