From: John Levon Date: Wed, 2 Apr 2003 00:51:46 +0000 (+0000) Subject: move transposeChars X-Git-Tag: 1.6.10~17086 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3566eaa4066d301374376696d98e8d5b09873e8a;p=features.git move transposeChars git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6676 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index f7fd4809e6..ceb8c4a3cb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2003-04-02 John Levon + + * lyxtext.h: + * text.C: + * Makefile.am: + * text_funcs.h: + * text_funcs.C: make transposeChars a free function + + * lyxrow_funcs.C: remove wrong comment + 2003-04-01 Lars Gullik Bjønnes * lyxtext.h: adjust diff --git a/src/Makefile.am b/src/Makefile.am index ae921568aa..264fcd1741 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -211,6 +211,8 @@ lyx_SOURCES = \ text.C \ text2.C \ text3.C \ + text_funcs.C \ + text_funcs.h \ toc.C \ toc.h \ trans.C \ diff --git a/src/lyxrow_funcs.C b/src/lyxrow_funcs.C index 0e857444c8..897377de20 100644 --- a/src/lyxrow_funcs.C +++ b/src/lyxrow_funcs.C @@ -22,8 +22,6 @@ bool isParEnd(LyXText const & lt, RowList::iterator rit) } -// It seems that this is only used in LyXText, it -// perhaps this function should be moved into LyXText. (Lgb) pos_type lastPos(LyXText const & lt, RowList::iterator rit) { if (rit->par()->empty()) diff --git a/src/lyxtext.h b/src/lyxtext.h index f55b9833bb..9b5acd10d0 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -405,8 +405,6 @@ public: }; /// Change the case of the word at cursor position. void changeCase(TextCase action); - /// - void transposeChars(); /// void toggleInset(); diff --git a/src/text.C b/src/text.C index 2a7c7cc445..b0d6183723 100644 --- a/src/text.C +++ b/src/text.C @@ -2411,41 +2411,6 @@ void LyXText::changeCase(LyXText::TextCase action) } -void LyXText::transposeChars() -{ - Paragraph * tmppar = cursor.par(); - - setUndo(bv(), Undo::FINISH, tmppar, tmppar->next()); - - pos_type tmppos = cursor.pos(); - - // First decide if it is possible to transpose at all - - if (tmppos == 0 || tmppos == tmppar->size()) - return; - - if (isDeletedText(*tmppar, tmppos - 1) - || isDeletedText(*tmppar, tmppos)) - return; - - unsigned char c1 = tmppar->getChar(tmppos); - unsigned char c2 = tmppar->getChar(tmppos - 1); - - // 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; - - bool const erased = tmppar->erase(tmppos - 1, tmppos + 1); - pos_type const ipos(erased ? tmppos - 1 : tmppos + 1); - - tmppar->insertChar(ipos, c1); - tmppar->insertChar(ipos + 1, c2); - - checkParagraph(tmppar, tmppos); -} - - void LyXText::Delete() { // this is a very easy implementation diff --git a/src/text3.C b/src/text3.C index 12adb07c32..ddcfe77eb0 100644 --- a/src/text3.C +++ b/src/text3.C @@ -35,6 +35,7 @@ #include "insets/insetcommand.h" #include "insets/insetnewline.h" #include "undo_funcs.h" +#include "text_funcs.h" #include #include @@ -1014,7 +1015,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) case LFUN_TRANSPOSE_CHARS: update(); - transposeChars(); + transposeChars(*this, cursor); if (inset_owner) bv->updateInset(inset_owner); update(); diff --git a/src/text_funcs.C b/src/text_funcs.C new file mode 100644 index 0000000000..74c8dfd0ef --- /dev/null +++ b/src/text_funcs.C @@ -0,0 +1,56 @@ +/** + * \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ønnes + * \author John Levon + * + * Full author contact details are available in file CREDITS + * + * This file contains some utility functions for actually mutating + * the text contents of a document + */ + +#include + +#include "lyxtext.h" +#include "paragraph.h" +#include "lyxcursor.h" +#include "undo_funcs.h" + +using lyx::pos_type; + +void transposeChars(LyXText & text, LyXCursor const & cursor) +{ + Paragraph * tmppar = cursor.par(); + + setUndo(text.bv(), Undo::FINISH, tmppar, tmppar->next()); + + pos_type tmppos = cursor.pos(); + + // First decide if it is possible to transpose at all + + if (tmppos == 0 || tmppos == tmppar->size()) + return; + + if (isDeletedText(*tmppar, tmppos - 1) + || isDeletedText(*tmppar, tmppos)) + return; + + unsigned char c1 = tmppar->getChar(tmppos); + unsigned char c2 = tmppar->getChar(tmppos - 1); + + // 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; + + bool const erased = tmppar->erase(tmppos - 1, tmppos + 1); + pos_type const ipos(erased ? tmppos - 1 : tmppos + 1); + + tmppar->insertChar(ipos, c1); + tmppar->insertChar(ipos + 1, c2); + + text.checkParagraph(tmppar, tmppos); +} diff --git a/src/text_funcs.h b/src/text_funcs.h new file mode 100644 index 0000000000..8ae6df785f --- /dev/null +++ b/src/text_funcs.h @@ -0,0 +1,25 @@ +/** + * \file text_funcs.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Lars Gullik Bjønnes + * \author John Levon + * + * Full author contact details are available in file CREDITS + * + * This file contains some utility functions for actually mutating + * the text contents of a document + */ + +#ifndef TEXT_FUNCS_H +#define TEXT_FUNCS_H + +#include + +class LyXText; +class LyXCursor; + +void transposeChars(LyXText & text, LyXCursor const & cursor); + +#endif // TEXT_FUNCS_H