RandomAccessList: new swap() method for swapping two elements without any copy.

LFUN_PARAGRAPH_MOVE_UP and LFUN_PARAGRAPH_MOVE_DOWN: use that.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30958 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2009-08-09 19:51:12 +00:00
parent 8c053ea10c
commit 1a27aaca77
2 changed files with 11 additions and 2 deletions

View File

@ -554,7 +554,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
pit_type const pit = cur.pit();
recUndo(cur, pit, pit + 1);
cur.finishUndo();
swap(pars_[pit], pars_[pit + 1]);
pars_.swap(pit, pit + 1);
cur.buffer()->updateLabels();
needsUpdate = true;
++cur.pit();
@ -565,7 +565,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
pit_type const pit = cur.pit();
recUndo(cur, pit - 1, pit);
cur.finishUndo();
swap(pars_[pit], pars_[pit - 1]);
pars_.swap(pit, pit - 1);
cur.buffer()->updateLabels();
--cur.pit();
needsUpdate = true;

View File

@ -246,6 +246,15 @@ public:
return it;
}
void swap(size_t i, size_t j)
{
size_t const p = max(i, j);
size_t const q = min(i, j);
container_.splice(iterCont_[p], container_, iterCont_[q]);
container_.splice(iterCont_[q], container_, iterCont_[p]);
recreateVector();
}
void swap(RandomAccessList & x)
{
std::swap(container_, x.container_);