using lyx::pos_type;
-// this is a minibuffer
-
-namespace {
-
-char minibuffer_char;
-LyXFont minibuffer_font;
-InsetOld * minibuffer_inset;
-
-} // namespace anon
-
-
Paragraph::Paragraph()
: pimpl_(new Paragraph::Pimpl(this))
{
}
-void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
-{
- minibuffer_char = getChar(pos);
- minibuffer_font = getFontSettings(bparams, pos);
- minibuffer_inset = 0;
- if (minibuffer_char == Paragraph::META_INSET) {
- if (getInset(pos)) {
- // the inset is not in a paragraph anymore
- minibuffer_inset = insetlist.release(pos);
- minibuffer_inset->parOwner(0);
- } else {
- minibuffer_inset = 0;
- minibuffer_char = ' ';
- // This reflects what GetInset() does (ARRae)
- }
- }
-}
-
-
-bool Paragraph::insertFromMinibuffer(pos_type pos)
-{
- if (minibuffer_char == Paragraph::META_INSET) {
- if (!insetAllowed(minibuffer_inset->lyxCode()))
- return false;
- insertInset(pos, minibuffer_inset, minibuffer_font);
- } else {
- LyXFont f = minibuffer_font;
- if (!checkInsertChar(f))
- return false;
- insertChar(pos, minibuffer_char, f);
- }
- return true;
-}
-
-
-// end of minibuffer
-
-
void Paragraph::eraseIntern(lyx::pos_type pos)
{
pimpl_->eraseIntern(pos);
using std::ostream;
+namespace {
+
+bool moveItem(Paragraph & from, Paragraph & to,
+ BufferParams const & params, pos_type i, pos_type j)
+{
+ char const tmpchar = from.getChar(i);
+ LyXFont tmpfont = from.getFontSettings(params, i);
+
+ if (tmpchar == Paragraph::META_INSET) {
+ InsetOld * tmpinset = 0;
+ if (from.getInset(i)) {
+ // the inset is not in a paragraph anymore
+ tmpinset = from.insetlist.release(i);
+ tmpinset->parOwner(0);
+ }
+
+ if (!to.insetAllowed(tmpinset->lyxCode()))
+ return false;
+ to.insertInset(j, tmpinset, tmpfont);
+ } else {
+ if (!to.checkInsertChar(tmpfont))
+ return false;
+ to.insertChar(j, tmpchar, tmpfont);
+ }
+ return true;
+}
+
+}
+
+
void breakParagraph(BufferParams const & bparams,
ParagraphList & paragraphs,
ParagraphList::iterator par,
pos_type j = pos;
for (; i <= pos_end; ++i) {
- Change::Type change(par->lookupChange(i));
- par->cutIntoMinibuffer(bparams, i);
- if (tmp->insertFromMinibuffer(j - pos)) {
+ Change::Type change = par->lookupChange(i);
+ if (moveItem(*par, *tmp, bparams, i, j - pos)) {
tmp->setChange(j - pos, change);
++j;
}
}
- for (i = pos_end; i >= pos; --i) {
+
+ for (i = pos_end; i >= pos; --i)
par->eraseIntern(i);
- }
}
if (pos)
// paragraph
pos_type pos_end = par->size() - 1;
- for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
- par->cutIntoMinibuffer(bparams, i);
- if (tmp->insertFromMinibuffer(j - pos))
+ for (pos_type i = pos, j = pos; i <= pos_end; ++i)
+ if (moveItem(*par, *tmp, bparams, i, j - pos))
++j;
- }
- for (pos_type k = pos_end; k >= pos; --k) {
+ for (pos_type k = pos_end; k >= pos; --k)
par->erase(k);
- }
}
}
pos_type pos_insert = par->size();
// ok, now copy the paragraph
- for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
- the_next->cutIntoMinibuffer(bparams, i);
- if (par->insertFromMinibuffer(pos_insert + j))
+ for (pos_type i = 0, j = 0; i <= pos_end; ++i)
+ if (moveItem(*the_next, *par, bparams, i, pos_insert + j))
++j;
- }
paragraphs.erase(the_next);
}