diff --git a/src/ChangeLog b/src/ChangeLog index f4a56ee131..00cb2d34cc 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-07-14 Juergen Spitzmueller + + * bufferview_funcs.[Ch]: introduce function replaceSelection() + * text3.C: use it to delete selections in some cases + (bugs 441, 673, 702, 954). 2003-07-14 André Pönitz diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 9f86aeed3f..f272f618f4 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -414,4 +414,15 @@ void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall) } } + +// deletes a selection during an insertion +void replaceSelection(LyXText * lt) +{ + if (lt->selection.set()) { + lt->update(); + lt->cutSelection(true, false); + lt->update(); + } +} + }; // namespace bv_funcs diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index 455c67d8be..4d5fb1267e 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -86,7 +86,8 @@ extern string const currentState(BufferView *); /// extern void toggleAndShow(BufferView *, LyXFont const &, bool toggleall = true); - +/// replace selection with insertion +extern void replaceSelection(LyXText * lt); }; // namespace bv_funcs #endif diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 44aa7244dc..d8f1c33ad1 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,4 +1,9 @@ +2003-07-14 Juergen Spitzmueller + + * insettext.C: use bufferview_funcs->replaceSelection() + to delete selections in some cases (bugs 441, 673, 702, 954). + 2003-07-14 André Pönitz * insettext.C (draw): use slimmed down rowpainter interface diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 7c40d59692..4e2d22fa9b 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -14,6 +14,7 @@ #include "buffer.h" #include "BufferView.h" +#include "bufferview_funcs.h" #include "CutAndPaste.h" #include "debug.h" #include "dimension.h" @@ -71,6 +72,7 @@ using std::pair; using std::for_each; using namespace lyx::support; +using namespace bv_funcs; using lyx::pos_type; using lyx::textclass_type; @@ -1151,6 +1153,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd) } } + replaceSelection(bv->getLyXText()); size_t sel_index = 0; string const & arg = cmd.argument; if (isStrUnsignedInt(arg)) { @@ -1171,6 +1174,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd) result = DISPATCHED; break; } + replaceSelection(bv->getLyXText()); text_.breakParagraph(paragraphs, 0); updwhat = CURSOR | FULL; updflag = true; @@ -1181,6 +1185,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd) result = DISPATCHED; break; } + replaceSelection(bv->getLyXText()); text_.breakParagraph(paragraphs, 1); updwhat = CURSOR | FULL; updflag = true; @@ -1192,6 +1197,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd) break; } + replaceSelection(bv->getLyXText()); text_.insertInset(new InsetNewline); updwhat = CURSOR | CURSOR_PAR; updflag = true; diff --git a/src/text3.C b/src/text3.C index e4cf6deba6..a99d1d4ba6 100644 --- a/src/text3.C +++ b/src/text3.C @@ -20,6 +20,7 @@ #include "debug.h" #include "bufferparams.h" #include "buffer.h" +#include "bufferview_funcs.h" #include "ParagraphParameters.h" #include "gettext.h" #include "factory.h" @@ -44,6 +45,7 @@ #include using namespace lyx::support; +using namespace bv_funcs; using std::endl; using std::find; @@ -369,6 +371,7 @@ void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind) { lt->update(); InsetSpecialChar * new_inset = new InsetSpecialChar(kind); + replaceSelection(lt); if (!bv->insertInset(new_inset)) delete new_inset; else @@ -723,7 +726,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) if (cursor.pos() <= body) break; - bv->beforeChange(this); + replaceSelection(bv->getLyXText()); insertInset(new InsetNewline); update(); setCursor(cursor.par(), cursor.pos()); @@ -833,7 +836,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) break; case LFUN_BREAKPARAGRAPH: - bv->beforeChange(this); + replaceSelection(bv->getLyXText()); breakParagraph(bv->buffer()->paragraphs, 0); update(); selection.cursor = cursor; @@ -842,7 +845,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) break; case LFUN_BREAKPARAGRAPHKEEPLAYOUT: - bv->beforeChange(this); + replaceSelection(bv->getLyXText()); breakParagraph(bv->buffer()->paragraphs, 1); update(); selection.cursor = cursor; @@ -855,7 +858,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) // indentation and add a "defskip" at the top. // Otherwise, do the same as LFUN_BREAKPARAGRAPH. LyXCursor cur = cursor; - bv->beforeChange(this); + replaceSelection(bv->getLyXText()); if (cur.pos() == 0) { if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) { setParagraph( @@ -1028,10 +1031,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) case LFUN_PASTE: { cmd.message(_("Paste")); - // clear the selection - bv->toggleSelection(); - clearSelection(); - update(); + replaceSelection(bv->getLyXText()); size_t sel_index = 0; string const & arg = cmd.argument; if (isStrUnsignedInt(arg)) { @@ -1200,6 +1200,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) } case LFUN_QUOTE: { + replaceSelection(bv->getLyXText()); ParagraphList::iterator pit = cursor.par(); lyx::pos_type pos = cursor.pos(); char c; @@ -1221,6 +1222,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) } case LFUN_DATE_INSERT: { + replaceSelection(bv->getLyXText()); time_t now_time_t = time(NULL); struct tm * now_tm = localtime(&now_time_t); setlocale(LC_TIME, "");