Martin Vermeer wrote:
> (I remember though also having code to dissolve an inset when pressing
> Delete in last position.)
Trivial. See, here the extra effort in code already pays off.
> I don't like the name -- easily misunderstood. DISSOLVE or MELT would be
> better.
I don't care. I named it DISSOLVE to please Lars and you.
The attached patch also is improved in the way that it restores the cursor
position.
OK to go in trunk?
Jürgen
> > Jürgen
>
> - Martin
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_DISSOLVE, "inset-dissolve", 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,50 @@ 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_FORWARD: {
+ if (!cur.selection() && cur.depth() > 1
+ && cur.pit() == cur.lastpit()
+ && cur.pos() == cur.lastpos())
+ // Merge inset with owner
+ cmd = FuncRequest(LFUN_INSET_DISSOLVE);
+ text_.dispatch(cur, cmd);
+ break;
+ }
+
+ case LFUN_CHAR_DELETE_BACKWARD: {
+ if (cur.depth() > 1 && cur.pit() == 0 && cur.pos() == 0)
+ // Merge inset with owner
+ cmd = FuncRequest(LFUN_INSET_DISSOLVE);
+ 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_FORWARD:
+ 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,44 @@ void LyXText::dispatch(LCursor & cur, Fu
break;
}
+ case LFUN_INSET_DISSOLVE: {
+ recordUndo(cur);
+ cur.selHandle(false);
+ // save position
+ lyx::pos_type spos = cur.pos();
+ lyx::pit_type spit = cur.pit();
+ bool content = false;
+ if (cur.lastpit() != 0 || cur.lastpos() != 0) {
+ setCursor(cur, 0, 0);
+ cur.resetAnchor();
+ cur.pit() = cur.lastpit();
+ cur.pos() = cur.lastpos();
+ cur.setSelection();
+ copySelection(cur);
+ content = true;
+ }
+ cur.popLeft();
+ cur.resetAnchor();
+ // store cursor offset
+ if (spit == 0)
+ spos += cur.pos();
+ spit += cur.pit();
+ cur.pos()++;
+ cur.setSelection();
+ if (content) {
+ lyx::cap::replaceSelection(cur);
+ pasteSelection(cur, 0);
+ cur.clearSelection();
+ // restore position
+ cur.pit() = std::min(cur.lastpit(), spit);
+ cur.pos() = std::min(cur.lastpos(), spos);
+ cur.resetAnchor();
+ } else
+ cutSelection(cur, false, false);
+ needsUpdate = true;
+ break;
+ }
+
case LFUN_INSET_SETTINGS:
cur.inset().showInsetDialog(bv);
break;
@@ -1711,6 +1749,11 @@ bool LyXText::getStatus(LCursor & cur, F
break;
}
+ case LFUN_INSET_DISSOLVE: {
+ 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_DISSOLVE, // jspitzm 20060807
LFUN_LASTACTION // end of the table
};