2003-04-02 00:51:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file text_funcs.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
|
*
|
|
|
|
|
* This file contains some utility functions for actually mutating
|
2003-04-09 09:15:20 +00:00
|
|
|
|
* the text contents of a document
|
2003-04-02 00:51:46 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "paragraph.h"
|
|
|
|
|
#include "lyxcursor.h"
|
|
|
|
|
#include "undo_funcs.h"
|
|
|
|
|
|
2003-04-15 19:31:45 +00:00
|
|
|
|
#include <boost/next_prior.hpp>
|
|
|
|
|
|
2003-04-02 00:51:46 +00:00
|
|
|
|
using lyx::pos_type;
|
|
|
|
|
|
|
|
|
|
void transposeChars(LyXText & text, LyXCursor const & cursor)
|
|
|
|
|
{
|
2003-04-15 19:31:45 +00:00
|
|
|
|
ParagraphList::iterator tmppit = cursor.par();
|
2003-04-02 00:51:46 +00:00
|
|
|
|
|
2003-05-23 10:33:40 +00:00
|
|
|
|
setUndo(text.bv(), Undo::FINISH, tmppit);
|
2003-04-02 00:51:46 +00:00
|
|
|
|
|
|
|
|
|
pos_type tmppos = cursor.pos();
|
|
|
|
|
|
|
|
|
|
// First decide if it is possible to transpose at all
|
|
|
|
|
|
2003-04-15 19:31:45 +00:00
|
|
|
|
if (tmppos == 0 || tmppos == tmppit->size())
|
2003-04-02 00:51:46 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2003-04-15 19:31:45 +00:00
|
|
|
|
if (isDeletedText(*tmppit, tmppos - 1)
|
|
|
|
|
|| isDeletedText(*tmppit, tmppos))
|
2003-04-02 00:51:46 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2003-04-15 19:31:45 +00:00
|
|
|
|
unsigned char c1 = tmppit->getChar(tmppos);
|
|
|
|
|
unsigned char c2 = tmppit->getChar(tmppos - 1);
|
2003-04-02 00:51:46 +00:00
|
|
|
|
|
|
|
|
|
// We should have an implementation that handles insets
|
|
|
|
|
// as well, but that will have to come later. (Lgb)
|
|
|
|
|
if (c1 == Paragraph::META_INSET || c2 == Paragraph::META_INSET)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-04-15 19:31:45 +00:00
|
|
|
|
bool const erased = tmppit->erase(tmppos - 1, tmppos + 1);
|
2003-04-02 00:51:46 +00:00
|
|
|
|
pos_type const ipos(erased ? tmppos - 1 : tmppos + 1);
|
|
|
|
|
|
2003-04-15 19:31:45 +00:00
|
|
|
|
tmppit->insertChar(ipos, c1);
|
|
|
|
|
tmppit->insertChar(ipos + 1, c2);
|
2003-04-02 00:51:46 +00:00
|
|
|
|
|
2003-04-15 19:31:45 +00:00
|
|
|
|
text.checkParagraph(tmppit, tmppos);
|
2003-04-02 00:51:46 +00:00
|
|
|
|
}
|