Martin Vermeer wrote:
> I didn't bother to save it properly
It's in the archieves:
http://www.mail-archive.com/lyx-devel%40lists.lyx.org/msg84275.html
However, I prefer the attached. A bit more code, but cleaner. And I think it's
worth to reserve an lfun for it.
Opinions?
Jürgen
Index: src/LyXAction.C
===================================================================
--- src/LyXAction.C (Revision 14551)
+++ src/LyXAction.C (Arbeitskopie)
@@ -329,6 +329,7 @@ void LyXAction::init()
{ LFUN_DIALOG_DISCONNECT_INSET, "dialog-disconnect-inset", Noop },
{ LFUN_INSET_APPLY, "inset-apply", Noop },
{ LFUN_INSET_INSERT, "inset-insert", Noop },
+ { LFUN_INSET_MERGE, "inset-merge", Noop },
{ LFUN_INSET_MODIFY, "", Noop },
{ LFUN_INSET_DIALOG_UPDATE, "", Noop },
{ LFUN_INSET_SETTINGS, "inset-settings", ReadOnly },
Index: src/insets/insettext.C
===================================================================
--- src/insets/insettext.C (Revision 14551)
+++ src/insets/insettext.C (Arbeitskopie)
@@ -22,6 +22,7 @@
#include "dispatchresult.h"
#include "errorlist.h"
#include "funcrequest.h"
+#include "FuncStatus.h"
#include "gettext.h"
#include "intl.h"
#include "LColor.h"
@@ -263,16 +264,39 @@ void InsetText::forceParagraphsToDefault
void InsetText::doDispatch(LCursor & cur, FuncRequest & cmd)
{
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
- << " [ cmd.action = " << cmd.action << ']' << endl;
+ << " [ cmd.action = "
+ << cmd.action << ']' << endl;
setViewCache(&cur.bv());
- text_.dispatch(cur, cmd);
+
+ switch (cmd.action) {
+
+ case LFUN_CHAR_DELETE_BACKWARD: {
+ if (cur.depth() > 1 && cur.pit() == 0 && cur.pos() == 0)
+ // Merge inset with owner
+ cmd = FuncRequest(LFUN_INSET_MERGE);
+ text_.dispatch(cur, cmd);
+ break;
+ }
+
+ default:
+ text_.dispatch(cur, cmd);
+ break;
+ }
}
bool InsetText::getStatus(LCursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
- return text_.getStatus(cur, cmd, status);
+ switch (cmd.action) {
+
+ case LFUN_CHAR_DELETE_BACKWARD:
+ status.enabled(true);
+ return true;
+
+ default:
+ return text_.getStatus(cur, cmd, status);
+ }
}
Index: src/text3.C
===================================================================
--- src/text3.C (Revision 14551)
+++ src/text3.C (Arbeitskopie)
@@ -705,6 +705,29 @@ void LyXText::dispatch(LCursor & cur, Fu
break;
}
+ case LFUN_INSET_MERGE: {
+ recordUndo(cur);
+ cur.selHandle(false);
+ setCursor(cur, 0, 0);
+ if (cur.lastpit() == 0 && cur.lastpos() == 0) {
+ cur.popLeft();
+ cur.resetAnchor();
+ cur.pos()++;
+ cur.setSelection();
+ cutSelection(cur, false, false);
+ } else {
+ cur.resetAnchor();
+ cur.pit() = cur.lastpit();
+ cur.pos() = cur.lastpos();
+ cur.setSelection();
+ copySelection(cur);
+ cmd = FuncRequest(LFUN_PASTE);
+ cur.undispatched();
+ }
+ needsUpdate = true;
+ break;
+ }
+
case LFUN_INSET_SETTINGS:
cur.inset().showInsetDialog(bv);
break;
@@ -1711,6 +1734,11 @@ bool LyXText::getStatus(LCursor & cur, F
break;
}
+ case LFUN_INSET_MERGE: {
+ enable = &cur.inset() && cur.inTexted();
+ break;
+ }
+
case LFUN_WORD_DELETE_FORWARD:
case LFUN_WORD_DELETE_BACKWARD:
case LFUN_LINE_DELETE:
Index: src/lfuns.h
===================================================================
--- src/lfuns.h (Revision 14551)
+++ src/lfuns.h (Arbeitskopie)
@@ -367,6 +367,7 @@ enum kb_action {
// 280
LFUN_MATH_BIGDELIM,
LFUN_CLIPBOARD_PASTE,
+ LFUN_INSET_MERGE, // jspitzm 20060807
LFUN_LASTACTION // end of the table
};