3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS
11 * This file contains some utility functions for actually mutating
12 * the text contents of a document
18 #include "paragraph.h"
19 #include "lyxcursor.h"
20 #include "undo_funcs.h"
22 #include <boost/next_prior.hpp>
26 void transposeChars(LyXText & text, LyXCursor const & cursor)
28 ParagraphList::iterator tmppit = cursor.par();
30 setUndo(text.bv(), Undo::FINISH, tmppit, boost::next(tmppit));
32 pos_type tmppos = cursor.pos();
34 // First decide if it is possible to transpose at all
36 if (tmppos == 0 || tmppos == tmppit->size())
39 if (isDeletedText(*tmppit, tmppos - 1)
40 || isDeletedText(*tmppit, tmppos))
43 unsigned char c1 = tmppit->getChar(tmppos);
44 unsigned char c2 = tmppit->getChar(tmppos - 1);
46 // We should have an implementation that handles insets
47 // as well, but that will have to come later. (Lgb)
48 if (c1 == Paragraph::META_INSET || c2 == Paragraph::META_INSET)
51 bool const erased = tmppit->erase(tmppos - 1, tmppos + 1);
52 pos_type const ipos(erased ? tmppos - 1 : tmppos + 1);
54 tmppit->insertChar(ipos, c1);
55 tmppit->insertChar(ipos + 1, c2);
57 text.checkParagraph(tmppit, tmppos);