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"
24 void transposeChars(LyXText & text, LyXCursor const & cursor)
26 Paragraph * tmppar = &*cursor.par();
28 setUndo(text.bv(), Undo::FINISH, tmppar, tmppar->next());
30 pos_type tmppos = cursor.pos();
32 // First decide if it is possible to transpose at all
34 if (tmppos == 0 || tmppos == tmppar->size())
37 if (isDeletedText(*tmppar, tmppos - 1)
38 || isDeletedText(*tmppar, tmppos))
41 unsigned char c1 = tmppar->getChar(tmppos);
42 unsigned char c2 = tmppar->getChar(tmppos - 1);
44 // We should have an implementation that handles insets
45 // as well, but that will have to come later. (Lgb)
46 if (c1 == Paragraph::META_INSET || c2 == Paragraph::META_INSET)
49 bool const erased = tmppar->erase(tmppos - 1, tmppos + 1);
50 pos_type const ipos(erased ? tmppos - 1 : tmppos + 1);
52 tmppar->insertChar(ipos, c1);
53 tmppar->insertChar(ipos + 1, c2);
55 text.checkParagraph(tmppar, tmppos);