]> git.lyx.org Git - features.git/commitdiff
last Friday's text*.C -> text_func shuffle
authorAndré Pönitz <poenitz@gmx.net>
Tue, 1 Jul 2003 11:51:20 +0000 (11:51 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 1 Jul 2003 11:51:20 +0000 (11:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7225 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView_pimpl.C
src/ChangeLog
src/lyxtext.h
src/support/types.h
src/text.C
src/text2.C
src/text3.C
src/text_funcs.C
src/text_funcs.h
src/textcursor.h

index 9088f5c681f236a03e43f726106beb93304d1569..e2892808d5d2cced7a3f62df0910de98dea93b9a 100644 (file)
@@ -1259,7 +1259,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                        // FIXME
                        if (arg.size() > 100 || arg.empty()) {
                                // Get word or selection
-                               bv_->getLyXText()->selectWordWhenUnderCursor(LyXText::WHOLE_WORD);
+                               bv_->getLyXText()->selectWordWhenUnderCursor(lyx::WHOLE_WORD);
                                arg = bv_->getLyXText()->selectionAsString(buffer_, false);
                                // FIXME: where is getLyXText()->unselect(bv_) ?
                        }
index 82bc7260709e0d3b7c2673944a70bf19a4087925..0ecef408649bf0c838fc1783c3b1a96029429e99 100644 (file)
@@ -1,3 +1,14 @@
+
+2003-07-01  André Pönitz  <poenitz@gmx.net>
+
+       * text.C:
+       * text2.C:
+       * text3.C:
+       * text_funcs.[Ch]:
+       * textcursor.h:
+       * lyxtext.h: shuffle pure paragraph/cursor related cursor movement from
+         text*.C to text_func.C
+
 2003-07-01  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * introduce namespace lyx::support
index 2acca6d6d4a464529f799e3eb3969990eb683fe9..eb5f55fcb86033556045f7341a6d3ab2f8dec95c 100644 (file)
@@ -54,21 +54,6 @@ public:
                REFRESH_AREA = 2
        };
 
-       ///
-       enum word_location {
-               // the word around the cursor, only if the cursor is
-               //not at a boundary
-               WHOLE_WORD_STRICT,
-               // the word around the cursor
-               WHOLE_WORD,
-               /// the word begining from the cursor position
-               PARTIAL_WORD,
-               /// the word around the cursor or before the cursor
-               PREVIOUS_WORD,
-               /// the next word (not yet used)
-               NEXT_WORD
-       };
-
        /// Constructor
        LyXText(BufferView *);
        /// sets inset as owner
@@ -279,9 +264,9 @@ public:
        void clearSelection();
 
        /// select the word we need depending on word_location
-       void getWord(LyXCursor & from, LyXCursor & to, word_location const);
+       void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
        /// just selects the word the cursor is in
-       void selectWord(word_location loc);
+       void selectWord(lyx::word_location loc);
        /// returns the inset at cursor (if it exists), 0 otherwise
        Inset * getInset() const;
 
@@ -362,7 +347,7 @@ public:
        ///
        void backspace();
        ///
-       bool selectWordWhenUnderCursor(word_location);
+       bool selectWordWhenUnderCursor(lyx::word_location);
        ///
        enum TextCase {
                ///
@@ -451,8 +436,6 @@ public:
 private:
        ///
        mutable RowList rowlist_;
-       ///
-       void cursorLeftOneWord(LyXCursor &);
 
        ///
        float getCursorX(RowList::iterator rit, lyx::pos_type pos,
index 9ee9800d3f40b71c511ba016d1d63c17ff6eb37b..c7711d87b82a4dc15631091747c042ffd51aecd6 100644 (file)
@@ -70,6 +70,21 @@ namespace lyx
 
 #endif
 
+       ///
+       enum word_location {
+               // the word around the cursor, only if the cursor is
+               //not at a boundary
+               WHOLE_WORD_STRICT,
+               // the word around the cursor
+               WHOLE_WORD,
+               /// the word begining from the cursor position
+               PARTIAL_WORD,
+               /// the word around the cursor or before the cursor
+               PREVIOUS_WORD,
+               /// the next word (not yet used)
+               NEXT_WORD
+       };
+
 }
 
 #endif // LYX_TYPES_H
index 3109fcbe4cb0524d0688aa14b153d1ec7d641cab..8e68a70a32f797702cf157a8266ab2fa36d220dd 100644 (file)
@@ -30,6 +30,7 @@
 #include "language.h"
 #include "ParagraphParameters.h"
 #include "undo_funcs.h"
+#include "text_funcs.h"
 #include "WordLangTuple.h"
 #include "paragraph_funcs.h"
 #include "rowpainter.h"
@@ -49,7 +50,10 @@ using std::max;
 using std::min;
 using std::endl;
 using std::pair;
+
 using lyx::pos_type;
+using lyx::word_location;
+
 using namespace bv_funcs;
 
 /// top, right, bottom pixel margin
@@ -1976,27 +1980,8 @@ void LyXText::prepareToPrint(RowList::iterator rit, float & x,
 
 void LyXText::cursorRightOneWord()
 {
-       // treat floats, HFills and Insets as words
-       ParagraphList::iterator pit = cursor.par();
-       pos_type pos = cursor.pos();
-
-       // CHECK See comment on top of text.C
-
-       if (pos == pit->size()
-           && boost::next(pit) != ownerParagraphs().end()) {
-               ++pit;
-               pos = 0;
-       } else {
-               // Skip through initial nonword stuff.
-               while (pos < pit->size() && !pit->isWord(pos)) {
-                       ++pos;
-               }
-               // Advance through word.
-               while (pos < pit->size() && pit->isWord(pos)) {
-                       ++pos;
-               }
-       }
-       setCursor(pit, pos);
+       ::cursorRightOneWord(cursor, ownerParagraphs());
+       setCursor(cursor.par(), cursor.pos());
 }
 
 
@@ -2005,102 +1990,16 @@ void LyXText::cursorRightOneWord()
 void LyXText::cursorLeftOneWord()
 {
        LyXCursor tmpcursor = cursor;
-       cursorLeftOneWord(tmpcursor);
+       ::cursorLeftOneWord(tmpcursor, ownerParagraphs());
        setCursor(tmpcursor.par(), tmpcursor.pos());
 }
 
 
-void LyXText::cursorLeftOneWord(LyXCursor & cur)
-{
-       // treat HFills, floats and Insets as words
-
-       ParagraphList::iterator pit = cursor.par();
-       pos_type pos = cursor.pos();
-
-       while (pos &&
-              (pit->isSeparator(pos - 1) ||
-               pit->isKomma(pos - 1) ||
-               pit->isNewline(pos - 1)) &&
-              !(pit->isHfill(pos - 1) ||
-                pit->isInset(pos - 1)))
-               --pos;
-
-       if (pos &&
-           (pit->isInset(pos - 1) ||
-            pit->isHfill(pos - 1))) {
-               --pos;
-       } else if (!pos) {
-               if (pit != ownerParagraphs().begin()) {
-                       --pit;
-                       pos = pit->size();
-               }
-       } else {                // Here, cur != 0
-               while (pos > 0 &&
-                      pit->isWord(pos - 1))
-                       --pos;
-       }
-
-       cur.par(pit);
-       cur.pos(pos);
-}
-
-
-// Select current word. This depends on behaviour of
-// CursorLeftOneWord(), so it is patched as well.
-void LyXText::getWord(LyXCursor & from, LyXCursor & to,
-                     word_location const loc)
-{
-       // first put the cursor where we wana start to select the word
-       from = cursor;
-       switch (loc) {
-       case WHOLE_WORD_STRICT:
-               if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
-                   || cursor.par()->isSeparator(cursor.pos())
-                   || cursor.par()->isKomma(cursor.pos())
-                   || cursor.par()->isNewline(cursor.pos())
-                   || cursor.par()->isSeparator(cursor.pos() - 1)
-                   || cursor.par()->isKomma(cursor.pos() - 1)
-                   || cursor.par()->isNewline(cursor.pos() - 1)) {
-                       to = from;
-                       return;
-               }
-               // no break here, we go to the next
-
-       case WHOLE_WORD:
-               // Move cursor to the beginning, when not already there.
-               if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
-                   && !(from.par()->isKomma(from.pos() - 1)
-                        || from.par()->isNewline(from.pos() - 1)))
-                       cursorLeftOneWord(from);
-               break;
-       case PREVIOUS_WORD:
-               // always move the cursor to the beginning of previous word
-               cursorLeftOneWord(from);
-               break;
-       case NEXT_WORD:
-               lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
-               break;
-       case PARTIAL_WORD:
-               break;
-       }
-       to = from;
-       while (to.pos() < to.par()->size()
-              && !to.par()->isSeparator(to.pos())
-              && !to.par()->isKomma(to.pos())
-              && !to.par()->isNewline(to.pos())
-              && !to.par()->isHfill(to.pos())
-              && !to.par()->isInset(to.pos()))
-       {
-               to.pos(to.pos() + 1);
-       }
-}
-
-
 void LyXText::selectWord(word_location loc)
 {
-       LyXCursor from;
+       LyXCursor from = cursor;
        LyXCursor to;
-       getWord(from, to, loc);
+       ::getWord(from, to, loc, ownerParagraphs());
        if (cursor != from)
                setCursor(from.par(), from.pos());
        if (to == from)
@@ -2358,7 +2257,8 @@ void LyXText::changeCase(LyXText::TextCase action)
                from = selection.start;
                to = selection.end;
        } else {
-               getWord(from, to, PARTIAL_WORD);
+               from = cursor;
+               ::getWord(from, to, lyx::PARTIAL_WORD, ownerParagraphs());
                setCursor(to.par(), to.pos() + 1);
        }
 
index dcc78c48ae42b15dd347938dae59e738e37e16a0..af480ff84fde7a82d352c8a840bb2ad7a0343e9c 100644 (file)
@@ -834,7 +834,7 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
        LyXCursor resetCursor = cursor;
        bool implicitSelection = (font.language() == ignore_language
                                  && font.number() == LyXFont::IGNORE)
-               ? selectWordWhenUnderCursor(WHOLE_WORD_STRICT) : false;
+               ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
 
        // Set font
        setFont(font, toggleall);
@@ -858,7 +858,8 @@ string LyXText::getStringToIndex()
        // If there is a change in the language the implicit word selection
        // is disabled.
        LyXCursor const reset_cursor = cursor;
-       bool const implicitSelection = selectWordWhenUnderCursor(PREVIOUS_WORD);
+       bool const implicitSelection =
+               selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
 
        string idxstring;
        if (!selection.set())
index 81952f4355a753b2077a2d70574d34fb515ad26a..e4cf6deba6a67e1d2589d245a2137706ec1c43a5 100644 (file)
@@ -590,9 +590,9 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_WORDSEL: {
                update();
-               LyXCursor cur1;
+               LyXCursor cur1 = cursor;
                LyXCursor cur2;
-               getWord(cur1, cur2, WHOLE_WORD);
+               ::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
                setCursor(cur1.par(), cur1.pos());
                bv->beforeChange(this);
                setCursor(cur2.par(), cur2.pos());
@@ -1018,7 +1018,9 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_TRANSPOSE_CHARS:
                update();
-               transposeChars(*this, cursor);
+               setUndo(bv, Undo::FINISH, cursor.par());
+               if (transposeChars(cursor))
+                       checkParagraph(cursor.par(), cursor.pos());
                if (inset_owner)
                        bv->updateInset(inset_owner);
                update();
@@ -1268,10 +1270,10 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (cmd.button() == mouse_button::button1) {
                        if (!isInInset()) {
                                bv->screen().toggleSelection(this, bv);
-                               selectWord(LyXText::WHOLE_WORD_STRICT);
+                               selectWord(lyx::WHOLE_WORD_STRICT);
                                bv->screen().toggleSelection(this, bv, false);
                        } else {
-                               selectWord(LyXText::WHOLE_WORD_STRICT);
+                               selectWord(lyx::WHOLE_WORD_STRICT);
                        }
                        update();
                        bv->haveSelection(selection.set());
index a5f4daf6fe913ec3e67a1a7047507de2664559f9..c9e13227546c53b938a249b40f84be93ebe5aa14 100644 (file)
 
 #include <config.h>
 
-#include "lyxtext.h"
-#include "paragraph.h"
+#include "debug.h"
 #include "lyxcursor.h"
-#include "undo_funcs.h"
+#include "ParagraphList.h"
+
+#include "support/types.h"
 
 #include <boost/next_prior.hpp>
 
 using lyx::pos_type;
+using lyx::word_location;
+
 
-void transposeChars(LyXText & text, LyXCursor const & cursor)
+bool transposeChars(LyXCursor const & cursor)
 {
        ParagraphList::iterator tmppit = cursor.par();
-
-       setUndo(text.bv(), Undo::FINISH, tmppit);
-
        pos_type tmppos = cursor.pos();
 
        // First decide if it is possible to transpose at all
 
        if (tmppos == 0 || tmppos == tmppit->size())
-               return;
+               return false;
 
        if (isDeletedText(*tmppit, tmppos - 1)
                || isDeletedText(*tmppit, tmppos))
-               return;
+               return false;
 
        unsigned char c1 = tmppit->getChar(tmppos);
        unsigned char c2 = tmppit->getChar(tmppos - 1);
@@ -46,13 +46,122 @@ void transposeChars(LyXText & text, LyXCursor const & cursor)
        // 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;
+               return false;
 
        bool const erased = tmppit->erase(tmppos - 1, tmppos + 1);
-       pos_type const ipos(erased ? tmppos - 1 : tmppos + 1);
+       size_t const ipos = erased ? tmppos - 1 : tmppos + 1;
 
        tmppit->insertChar(ipos, c1);
        tmppit->insertChar(ipos + 1, c2);
+       return true;
+}
+
+
+void cursorLeftOneWord(LyXCursor & cursor, ParagraphList const & pars)
+{
+       // treat HFills, floats and Insets as words
+
+       ParagraphList::iterator pit = cursor.par();
+       size_t pos = cursor.pos();
+
+       while (pos &&
+              (pit->isSeparator(pos - 1) ||
+               pit->isKomma(pos - 1) ||
+               pit->isNewline(pos - 1)) &&
+              !(pit->isHfill(pos - 1) ||
+                pit->isInset(pos - 1)))
+               --pos;
+
+       if (pos &&
+           (pit->isInset(pos - 1) ||
+            pit->isHfill(pos - 1))) {
+               --pos;
+       } else if (!pos) {
+               if (pit != pars.begin()) {
+                       --pit;
+                       pos = pit->size();
+               }
+       } else {                // Here, cur != 0
+               while (pos > 0 && pit->isWord(pos - 1))
+                       --pos;
+       }
+
+       cursor.par(pit);
+       cursor.pos(pos);
+}
+
+
+void cursorRightOneWord(LyXCursor & cursor, ParagraphList const & pars)
+{
+       // treat floats, HFills and Insets as words
+       ParagraphList::iterator pit = cursor.par();
+       pos_type pos = cursor.pos();
+
+       // CHECK See comment on top of text.C
+
+       if (pos == pit->size() && boost::next(pit) != pars.end()) {
+               ++pit;
+               pos = 0;
+       } else {
+               // Skip through initial nonword stuff.
+               while (pos < pit->size() && !pit->isWord(pos)) {
+                       ++pos;
+               }
+               // Advance through word.
+               while (pos < pit->size() && pit->isWord(pos)) {
+                       ++pos;
+               }
+       }
+
+       cursor.par(pit);
+       cursor.pos(pos);
+}
+
+
+// Select current word. This depends on behaviour of
+// CursorLeftOneWord(), so it is patched as well.
+void getWord(LyXCursor & from, LyXCursor & to, word_location const loc,
+       ParagraphList const & pars)
+{
+       switch (loc) {
+       case lyx::WHOLE_WORD_STRICT:
+               if (from.pos() == 0 || from.pos() == from.par()->size()
+                   || from.par()->isSeparator(from.pos())
+                   || from.par()->isKomma(from.pos())
+                   || from.par()->isNewline(from.pos())
+                   || from.par()->isSeparator(from.pos() - 1)
+                   || from.par()->isKomma(from.pos() - 1)
+                   || from.par()->isNewline(from.pos() - 1)) {
+                       to = from;
+                       return;
+               }
+               // no break here, we go to the next
 
-       text.checkParagraph(tmppit, tmppos);
+       case lyx::WHOLE_WORD:
+               // Move cursor to the beginning, when not already there.
+               if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
+                   && !(from.par()->isKomma(from.pos() - 1)
+                        || from.par()->isNewline(from.pos() - 1)))
+                       cursorLeftOneWord(from, pars);
+               break;
+       case lyx::PREVIOUS_WORD:
+               // always move the cursor to the beginning of previous word
+               cursorLeftOneWord(from, pars);
+               break;
+       case lyx::NEXT_WORD:
+               lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
+               break;
+       case lyx::PARTIAL_WORD:
+               break;
+       }
+       to = from;
+       while (to.pos() < to.par()->size()
+              && !to.par()->isSeparator(to.pos())
+              && !to.par()->isKomma(to.pos())
+              && !to.par()->isNewline(to.pos())
+              && !to.par()->isHfill(to.pos())
+              && !to.par()->isInset(to.pos()))
+       {
+               to.pos(to.pos() + 1);
+       }
 }
index 8ae6df785f2e8bba8b7875a7de211f19de4e192e..4b183beb7e2c7ab2afc7daee65d291f7cdd50204 100644 (file)
 
 #include <config.h>
 
-class LyXText;
+#include "support/types.h"
+
 class LyXCursor;
+class ParagraphList;
+
+
+// do no use LyXText or BufferView here
+
+
+///
+bool transposeChars(LyXCursor const & cursor);
+///
+void cursorLeftOneWord(LyXCursor &, ParagraphList const &);
+///
+void cursorRightOneWord(LyXCursor &, ParagraphList const &);
 
-void transposeChars(LyXText & text, LyXCursor const & cursor);
+// Select current word. This depends on behaviour of
+// CursorLeftOneWord(), so it is patched as well.
+void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const loc,
+       ParagraphList const & pars);
 
 #endif // TEXT_FUNCS_H
index 26091d5a4b68dc9cdd639e1abc65cb567a0c7d4c..530bb22840c67cd9f8ea2f6fe007e775f43fb51a 100644 (file)
@@ -16,6 +16,9 @@
 #ifndef TEXTCURSOR_H
 #define TEXTCURSOR_H
 
+// Do not even think of forward declaring LyXText/BufferView etc here!
+// If you need Paragraph proper, go to text_func.h
+
 /** The cursor.
        Later this variable has to be removed. There should be now internal
        cursor in a text (and thus not in a buffer). By keeping this it is