From 0ce73aa2c41435f75e6cda40c89bdf165523dfdb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Tue, 8 Aug 2006 13:34:02 +0000 Subject: [PATCH] Implement LFUN_INSET_DISSOLVE (bug 2201): * src/LyXAction.C: * src/lfuns.h: - add new lfun LFUN_INSET_DISSOLVE. * src/insets/insettext.C (void InsetText::doDispatch): - dissolve inset when hitting backspace in the very first or delete in the very last position of an inset. * src/text3.C (void LyXText::dispatch): (bool LyXText::getStatus): - implement new lfun LFUN_INSET_DISSOLVE. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14572 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXAction.C | 1 + src/insets/insettext.C | 41 +++++++++++++++++++++++++++++++++++++--- src/lfuns.h | 1 + src/text3.C | 43 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) 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: -- 2.39.5