mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
fix bug 2758:
* src/Paragraph.cpp: - make sure removed bibitems (inside a par) are restored correctly (in pos 0). * src/Text.{cpp,h} (handleBibitems): - new member, used by erase and backspace. * src/Text3.cpp (getStatus): - allow inserting of bibitems only in pos 0. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18304 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
bd2338b353
commit
a8010a4dc6
@ -2603,12 +2603,34 @@ bool Paragraph::checkBiblio(bool track_changes)
|
||||
&& getChar(0) == Paragraph::META_INSET
|
||||
&& insetlist.begin()->inset->lyxCode() == Inset::BIBITEM_CODE;
|
||||
|
||||
docstring oldkey;
|
||||
docstring oldlabel;
|
||||
|
||||
// remove bibitems in pos != 0
|
||||
// restore them later in pos 0 if necessary
|
||||
// (e.g. if a user inserts contents _before_ the item)
|
||||
InsetList::const_iterator it = insetlist.begin();
|
||||
InsetList::const_iterator end = insetlist.end();
|
||||
for (; it != end; ++it)
|
||||
if (it->inset->lyxCode() == Inset::BIBITEM_CODE
|
||||
&& it->pos > 0) {
|
||||
InsetBibitem * olditem = static_cast<InsetBibitem *>(it->inset);
|
||||
oldkey = olditem->getParam("key");
|
||||
oldlabel = olditem->getParam("label");
|
||||
eraseChar(it->pos, track_changes);
|
||||
}
|
||||
|
||||
if (hasbibitem)
|
||||
return false;
|
||||
|
||||
InsetBibitem * inset(new InsetBibitem(InsetCommandParams("bibitem")));
|
||||
// restore values of previously deleted item in this par.
|
||||
if (!oldkey.empty())
|
||||
inset->setParam("key", oldkey);
|
||||
if (!oldlabel.empty())
|
||||
inset->setParam("label", oldlabel);
|
||||
insertInset(0, static_cast<Inset *>(inset),
|
||||
Change(track_changes ? Change::INSERTED : Change::UNCHANGED));
|
||||
Change(track_changes ? Change::INSERTED : Change::UNCHANGED));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
36
src/Text.cpp
36
src/Text.cpp
@ -1170,6 +1170,38 @@ void Text::changeCase(Cursor & cur, Text::TextCase action)
|
||||
}
|
||||
|
||||
|
||||
bool Text::handleBibitems(Cursor & cur)
|
||||
{
|
||||
if (cur.paragraph().layout()->labeltype != LABEL_BIBLIO)
|
||||
return false;
|
||||
// if a bibitem is deleted, merge with previous paragraph
|
||||
// if this is a bibliography item as well
|
||||
if (cur.pos() == 0) {
|
||||
BufferParams const & bufparams = cur.buffer().params();
|
||||
Paragraph const & par = cur.paragraph();
|
||||
Cursor prevcur = cur;
|
||||
if (cur.pit() > 0) {
|
||||
--prevcur.pit();
|
||||
prevcur.pos() = prevcur.lastpos();
|
||||
}
|
||||
Paragraph const & prevpar = prevcur.paragraph();
|
||||
if (cur.pit() > 0 && par.layout() == prevpar.layout()) {
|
||||
recordUndo(cur, Undo::ATOMIC, prevcur.pit());
|
||||
mergeParagraph(bufparams, cur.text()->paragraphs(),
|
||||
prevcur.pit());
|
||||
updateLabels(cur.buffer());
|
||||
setCursorIntern(cur, prevcur.pit(), prevcur.pos());
|
||||
cur.updateFlags(Update::Force);
|
||||
// if not, reset the paragraph to default
|
||||
} else
|
||||
cur.paragraph().layout(
|
||||
bufparams.getTextClass().defaultLayout());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Text::erase(Cursor & cur)
|
||||
{
|
||||
BOOST_ASSERT(this == cur.text());
|
||||
@ -1200,6 +1232,8 @@ bool Text::erase(Cursor & cur)
|
||||
}
|
||||
}
|
||||
|
||||
needsUpdate |= handleBibitems(cur);
|
||||
|
||||
if (needsUpdate) {
|
||||
// Make sure the cursor is correct. Is this really needed?
|
||||
// No, not really... at least not here!
|
||||
@ -1298,6 +1332,8 @@ bool Text::backspace(Cursor & cur)
|
||||
if (cur.pos() == cur.lastpos())
|
||||
setCurrentFont(cur);
|
||||
|
||||
needsUpdate |= handleBibitems(cur);
|
||||
|
||||
// A singlePar update is not enough in this case.
|
||||
// cur.updateFlags(Update::Force);
|
||||
setCursor(cur.top(), cur.pit(), cur.pos());
|
||||
|
@ -387,6 +387,8 @@ private:
|
||||
// At cursor position 0, try to merge the paragraph with the one before it.
|
||||
// Ignore change tracking, i.e., physically remove the end-of-par character
|
||||
bool backspacePos0(Cursor & cur);
|
||||
/// handle the case where bibitems were deleted
|
||||
bool handleBibitems(Cursor & cur);
|
||||
|
||||
///
|
||||
void deleteWordForward(Cursor & cur);
|
||||
|
@ -1654,7 +1654,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
return true;
|
||||
|
||||
case LFUN_BIBITEM_INSERT:
|
||||
enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO);
|
||||
enable = (cur.paragraph().layout()->labeltype == LABEL_BIBLIO
|
||||
&& cur.pos() == 0);
|
||||
break;
|
||||
|
||||
case LFUN_DIALOG_SHOW_NEW_INSET:
|
||||
|
Loading…
Reference in New Issue
Block a user