2003-05-01 Lars Gullik Bj�nnes <larsbj@gullik.net>

* CutAndPaste.C (pasteSelection): more clean up, user proper
ParagraphList functions for pasteing.

* ParagraphList.C (insert): new function, three arg insert


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6911 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-05-01 14:45:04 +00:00
parent e81ff24dcc
commit 2668764493
4 changed files with 43 additions and 31 deletions

View File

@ -1,5 +1,14 @@
2003-05-01 Lars Gullik Bjønnes <larsbj@gullik.net> 2003-05-01 Lars Gullik Bjønnes <larsbj@gullik.net>
* CutAndPaste.C (pasteSelection): more clean up, user proper
ParagraphList functions for pasteing.
* ParagraphList.C (insert): new function, three arg insert
2003-05-01 Lars Gullik Bjønnes <larsbj@gullik.net>
* ParagraphList.C (insert): new function, three arg insert
* CutAndPaste.C (pasteSelection): work on the simple_cut_clone, * CutAndPaste.C (pasteSelection): work on the simple_cut_clone,
not on paragraphs. not on paragraphs.

View File

@ -225,7 +225,7 @@ CutAndPaste::pasteSelection(ParagraphList & pars,
// at level 0. // at level 0.
if ((int(tmpbuf->params().depth()) + depth_delta) < 0) if ((int(tmpbuf->params().depth()) + depth_delta) < 0)
depth_delta = 0; depth_delta = 0;
// set the right depth so that we are not too deep or shallow. // Set the right depth so that we are not too deep or shallow.
tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta); tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta);
if (tmpbuf->params().depth() > max_depth) if (tmpbuf->params().depth() > max_depth)
tmpbuf->params().depth(max_depth); tmpbuf->params().depth(max_depth);
@ -258,12 +258,6 @@ CutAndPaste::pasteSelection(ParagraphList & pars,
// the cursor paragraph. // the cursor paragraph.
simple_cut_clone.begin()->makeSameLayout(*pit); simple_cut_clone.begin()->makeSameLayout(*pit);
// Find the end of the buffer.
// FIXME: change this to end() - 1
ParagraphList::iterator lastbuffer = simple_cut_clone.begin();
while (boost::next(lastbuffer) != simple_cut_clone.end())
++lastbuffer;
bool paste_the_end = false; bool paste_the_end = false;
// Open the paragraph for inserting the buf // Open the paragraph for inserting the buf
@ -278,42 +272,40 @@ CutAndPaste::pasteSelection(ParagraphList & pars,
ParagraphList::iterator endpit = boost::next(boost::next(pit)); ParagraphList::iterator endpit = boost::next(boost::next(pit));
// Paste it! // Paste it!
lastbuffer->next(pit->next());
pit->next()->previous(&*lastbuffer);
pit->next(&*simple_cut_clone.begin()); ParagraphList::iterator past_pit = boost::next(pit);
simple_cut_clone.begin()->previous(&*pit); // It is possible that std::list::splice also could be used here.
pars.insert(past_pit,
simple_cut_clone.begin(), simple_cut_clone.end());
ParagraphList::iterator last_paste = boost::prior(past_pit);
if (boost::next(pit) == lastbuffer) // If we only inserted one paragraph.
lastbuffer = pit; if (boost::next(pit) == last_paste)
last_paste = pit;
mergeParagraph(current_view->buffer()->params, pars, pit); mergeParagraph(current_view->buffer()->params, pars, pit);
// Store the new cursor position. // Store the new cursor position.
pit = lastbuffer; pit = last_paste;
pos = lastbuffer->size(); pos = last_paste->size();
// Maybe some pasting. // Maybe some pasting.
if (boost::next(lastbuffer) != simple_cut_clone.end() && paste_the_end) { if (boost::next(last_paste) != simple_cut_clone.end() &&
if (boost::next(lastbuffer)->hasSameLayout(*lastbuffer)) { paste_the_end) {
if (boost::next(last_paste)->hasSameLayout(*last_paste)) {
mergeParagraph(current_view->buffer()->params, pars, mergeParagraph(current_view->buffer()->params, pars,
lastbuffer); last_paste);
} else if (!boost::next(lastbuffer)->size()) { } else if (boost::next(last_paste)->empty()) {
boost::next(lastbuffer)->makeSameLayout(*lastbuffer); boost::next(last_paste)->makeSameLayout(*last_paste);
mergeParagraph(current_view->buffer()->params, pars, mergeParagraph(current_view->buffer()->params, pars,
lastbuffer); last_paste);
} else if (!lastbuffer->size()) { } else if (last_paste->empty()) {
lastbuffer->makeSameLayout(*boost::next(lastbuffer)); last_paste->makeSameLayout(*boost::next(last_paste));
mergeParagraph(current_view->buffer()->params, pars, mergeParagraph(current_view->buffer()->params, pars,
lastbuffer); last_paste);
} else } else
boost::next(lastbuffer)->stripLeadingSpaces(); boost::next(last_paste)->stripLeadingSpaces();
} }
#if 1
// For the time beeing we must do this to avoid deleting the
// newly pasted paragraphs.
simple_cut_clone.set(0);
#endif
return make_pair(PitPosPair(pit, pos), endpit); return make_pair(PitPosPair(pit, pos), endpit);
} }

View File

@ -158,6 +158,15 @@ ParagraphList::insert(ParagraphList::iterator it, Paragraph * par)
} }
void ParagraphList::insert(iterator pos, iterator beg, iterator end)
{
for (; beg != end; ++beg) {
insert(pos, new Paragraph(*beg, false));
}
}
void ParagraphList::assign(iterator beg, iterator end) void ParagraphList::assign(iterator beg, iterator end)
{ {
clear(); clear();

View File

@ -53,6 +53,8 @@ public:
/// ///
iterator insert(iterator it, Paragraph * par); iterator insert(iterator it, Paragraph * par);
/// ///
void insert(iterator pos, iterator beg, iterator end);
///
void assign(iterator beg, iterator end); void assign(iterator beg, iterator end);
/// ///
void clear(); void clear();