diff --git a/src/LyXAction.C b/src/LyXAction.C index b420559653..b03658c038 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -328,6 +328,7 @@ void LyXAction::init() { LFUN_DIALOG_HIDE, "dialog-hide", Noop }, { LFUN_DIALOG_DISCONNECT_INSET, "dialog-disconnect-inset", Noop }, { LFUN_INSET_APPLY, "inset-apply", Noop }, + { LFUN_INSET_DISSOLVE, "inset-dissolve", Noop }, { LFUN_INSET_INSERT, "inset-insert", Noop }, { LFUN_INSET_MODIFY, "", Noop }, { LFUN_INSET_DIALOG_UPDATE, "", Noop }, diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 8bcc58ef48..f6e5a6ae8d 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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(LCursor & cur) 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); + } } diff --git a/src/lfuns.h b/src/lfuns.h index c286ed6e96..8c0b79608b 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -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 }; diff --git a/src/text3.C b/src/text3.C index f2c952590b..7b26d02eb8 100644 --- a/src/text3.C +++ b/src/text3.C @@ -705,6 +705,44 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) 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, FuncRequest const & cmd, 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: