mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Handle orphaned bibitems
Fixes #7160
(cherry picked from commit 96e4001d01
)
This commit is contained in:
parent
c614d81e8d
commit
8556d65279
@ -3648,32 +3648,43 @@ bool Paragraph::allowEmpty() const
|
|||||||
|
|
||||||
bool Paragraph::brokenBiblio() const
|
bool Paragraph::brokenBiblio() const
|
||||||
{
|
{
|
||||||
// there is a problem if there is no bibitem at position 0 or
|
// There is a problem if there is no bibitem at position 0 in
|
||||||
// if there is another bibitem in the paragraph.
|
// paragraphs that need one, if there is another bibitem in the
|
||||||
return d->layout_->labeltype == LABEL_BIBLIO
|
// paragraph or if this paragraph is not supposed to have
|
||||||
|
// a bibitem inset at all.
|
||||||
|
return ((d->layout_->labeltype == LABEL_BIBLIO
|
||||||
&& (d->insetlist_.find(BIBITEM_CODE) != 0
|
&& (d->insetlist_.find(BIBITEM_CODE) != 0
|
||||||
|| d->insetlist_.find(BIBITEM_CODE, 1) > 0);
|
|| d->insetlist_.find(BIBITEM_CODE, 1) > 0))
|
||||||
|
|| (d->layout_->labeltype != LABEL_BIBLIO
|
||||||
|
&& d->insetlist_.find(BIBITEM_CODE) != -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Paragraph::fixBiblio(Buffer const & buffer)
|
int Paragraph::fixBiblio(Buffer const & buffer)
|
||||||
{
|
{
|
||||||
// FIXME: What about the case where paragraph is not BIBLIO
|
|
||||||
// but there is an InsetBibitem?
|
|
||||||
// FIXME: when there was already an inset at 0, the return value is 1,
|
// FIXME: when there was already an inset at 0, the return value is 1,
|
||||||
// which does not tell whether another inset has been remove; the
|
// which does not tell whether another inset has been remove; the
|
||||||
// cursor cannot be correctly updated.
|
// cursor cannot be correctly updated.
|
||||||
|
|
||||||
if (d->layout_->labeltype != LABEL_BIBLIO)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
bool const track_changes = buffer.params().track_changes;
|
bool const track_changes = buffer.params().track_changes;
|
||||||
int bibitem_pos = d->insetlist_.find(BIBITEM_CODE);
|
int bibitem_pos = d->insetlist_.find(BIBITEM_CODE);
|
||||||
bool const hasbibitem0 = bibitem_pos == 0;
|
|
||||||
|
|
||||||
|
// The case where paragraph is not BIBLIO
|
||||||
|
if (d->layout_->labeltype != LABEL_BIBLIO) {
|
||||||
|
if (bibitem_pos == -1)
|
||||||
|
// No InsetBibitem => OK
|
||||||
|
return 0;
|
||||||
|
// There is an InsetBibitem: remove it!
|
||||||
|
d->insetlist_.release(bibitem_pos);
|
||||||
|
eraseChar(bibitem_pos, track_changes);
|
||||||
|
return (bibitem_pos == 0) ? -1 : -bibitem_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool const hasbibitem0 = bibitem_pos == 0;
|
||||||
if (hasbibitem0) {
|
if (hasbibitem0) {
|
||||||
bibitem_pos = d->insetlist_.find(BIBITEM_CODE, 1);
|
bibitem_pos = d->insetlist_.find(BIBITEM_CODE, 1);
|
||||||
// There was an InsetBibitem at pos 0, and no other one => OK
|
// There was an InsetBibitem at pos 0,
|
||||||
|
// and no other one => OK
|
||||||
if (bibitem_pos == -1)
|
if (bibitem_pos == -1)
|
||||||
return 0;
|
return 0;
|
||||||
// there is a bibitem at the 0 position, but since
|
// there is a bibitem at the 0 position, but since
|
||||||
@ -3688,7 +3699,7 @@ int Paragraph::fixBiblio(Buffer const & buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We need to create an inset at the beginning
|
// We need to create an inset at the beginning
|
||||||
Inset * inset = 0;
|
Inset * inset = nullptr;
|
||||||
if (bibitem_pos > 0) {
|
if (bibitem_pos > 0) {
|
||||||
// there was one somewhere in the paragraph, let's move it
|
// there was one somewhere in the paragraph, let's move it
|
||||||
inset = d->insetlist_.release(bibitem_pos);
|
inset = d->insetlist_.release(bibitem_pos);
|
||||||
|
@ -369,8 +369,9 @@ bool TextMetrics::redoParagraph(pit_type const pit)
|
|||||||
// FIXME: This check ought to be done somewhere else. It is the reason
|
// FIXME: This check ought to be done somewhere else. It is the reason
|
||||||
// why text_ is not const. But then, where else to do it?
|
// why text_ is not const. But then, where else to do it?
|
||||||
// Well, how can you end up with either (a) a biblio environment that
|
// Well, how can you end up with either (a) a biblio environment that
|
||||||
// has no InsetBibitem or (b) a biblio environment with more than one
|
// has no InsetBibitem, (b) a biblio environment with more than one
|
||||||
// InsetBibitem? I think the answer is: when paragraphs are merged;
|
// InsetBibitem or (c) a paragraph that has a bib item but is no biblio
|
||||||
|
// environment? I think the answer is: when paragraphs are merged;
|
||||||
// when layout is set; when material is pasted.
|
// when layout is set; when material is pasted.
|
||||||
if (par.brokenBiblio()) {
|
if (par.brokenBiblio()) {
|
||||||
Cursor & cur = const_cast<Cursor &>(bv_->cursor());
|
Cursor & cur = const_cast<Cursor &>(bv_->cursor());
|
||||||
|
Loading…
Reference in New Issue
Block a user