]> git.lyx.org Git - features.git/commitdiff
* text.C: remove big comment on invalid Paragraph pointers as it is
authorAndré Pönitz <poenitz@gmx.net>
Tue, 11 Nov 2003 10:08:35 +0000 (10:08 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 11 Nov 2003 10:08:35 +0000 (10:08 +0000)
not valid anymore

* text_funcs.[Ch]: merge with ...

* text.C: ... this

* lyxtext.h:
* text2.C:
* text3.C: adjust

* Makefile.am: remove text_funcs.[Ch]

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8075 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/Makefile.am
src/lyxtext.h
src/text.C
src/text2.C
src/text3.C
src/text_funcs.C [deleted file]
src/text_funcs.h [deleted file]

index 45864a67b33d711204448234d6f3ba596abbe989..655258b2ae67fa83bea0ca678c4b0359558a3114 100644 (file)
@@ -1,3 +1,21 @@
+
+2003-11-11  André Pönitz  <poenitz@gmx.net>
+
+       * text.C: remove big comment on invalid Paragraph pointers as it is
+       not valid anymore
+
+2003-11-11  André Pönitz  <poenitz@gmx.net>
+
+       * text_funcs.[Ch]: merge with ...
+
+       * text.C: ... this
+
+       * lyxtext.h:
+       * text2.C:
+       * text3.C: adjust
+
+       * Makefile.am: remove text_funcs.[Ch]
+
 2003-11-11  Alfredo Braunstein  <abraunst@libero.it>
 
        * cursor.C (getPos): return absolute cached y coord
index d1a5bb06fdb12e6b44ffd1bbf3b733368c3e4436..4f27a7ff7d46ee01e76bd682ce06b07a657b5e30 100644 (file)
@@ -262,8 +262,6 @@ lyx_SOURCES = \
        text3.C \
        textcursor.C \
        textcursor.h \
-       text_funcs.C \
-       text_funcs.h \
        toc.C \
        toc.h \
        trans.C \
index af7f6bcfb576c904ccef376a8871dcea555113bd..b662e0859449cba52d7618ad42217ceaed3bd198 100644 (file)
@@ -439,6 +439,11 @@ public:
        std::string selectionAsString(Buffer const & buffer, bool label) const;
        ///
        double spacing(Paragraph const &) const;
+       ///
+       void cursorLeftOneWord(LyXCursor &);
+       ///
+       void cursorRightOneWord(LyXCursor &);
+
 private:
        /** Cursor related data.
          Later this variable has to be removed. There should be now internal
index 3a736e0b0c5d86d1461bf20548393b7542e8c137..995c935e1cb36cae77401c8e1fa6935ec1ab931c 100644 (file)
@@ -37,7 +37,6 @@
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 #include "rowpainter.h"
-#include "text_funcs.h"
 #include "undo.h"
 #include "vspace.h"
 #include "WordLangTuple.h"
@@ -128,31 +127,6 @@ int LyXText::workWidth() const
 }
 
 
-// This is the comments that some of the warnings below refers to.
-// There are some issues in this file and I don't think they are
-// really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
-// this is a problem that has been here almost from day one and that a
-// larger userbase with different access patters triggers the bad
-// behaviour. (segfaults.) What I think happen is: In several places
-// we store the paragraph in the current cursor and then moves the
-// cursor. This movement of the cursor will delete paragraph at the
-// old position if it is now empty. This will make the temporary
-// pointer to the old cursor paragraph invalid and dangerous to use.
-// And is some cases this will trigger a segfault. I have marked some
-// of the cases where this happens with a warning, but I am sure there
-// are others in this file and in text2.C. There is also a note in
-// Delete() that you should read. In Delete I store the paragraph->id
-// instead of a pointer to the paragraph. I am pretty sure this faulty
-// use of temporary pointers to paragraphs that might have gotten
-// invalidated (through a cursor movement) before they are used, are
-// the cause of the strange crashes we get reported often.
-//
-// It is very tiresom to change this code, especially when it is as
-// hard to read as it is. Help to fix all the cases where this is done
-// would be greately appreciated.
-//
-// Lgb
-
 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
 {
        if (pos >= pit->size())
@@ -1142,16 +1116,12 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
 }
 
 
-// important for the screen
-
-
 // the cursor set functions have a special mechanism. When they
 // realize, that you left an empty paragraph, they will delete it.
-// They also delete the corresponding row
 
 void LyXText::cursorRightOneWord()
 {
-       ::cursorRightOneWord(*this, cursor, ownerParagraphs());
+       cursorRightOneWord(cursor);
        setCursor(cursorPar(), cursor.pos());
 }
 
@@ -1161,7 +1131,7 @@ void LyXText::cursorRightOneWord()
 void LyXText::cursorLeftOneWord()
 {
        LyXCursor tmpcursor = cursor;
-       ::cursorLeftOneWord(*this, tmpcursor, ownerParagraphs());
+       cursorLeftOneWord(tmpcursor);
        setCursor(getPar(tmpcursor), tmpcursor.pos());
 }
 
@@ -1170,7 +1140,7 @@ void LyXText::selectWord(word_location loc)
 {
        LyXCursor from = cursor;
        LyXCursor to = cursor;
-       ::getWord(*this, from, to, loc, ownerParagraphs());
+       getWord(from, to, loc);
        if (cursor != from)
                setCursor(from.par(), from.pos());
        if (to == from)
@@ -1302,7 +1272,7 @@ void LyXText::changeCase(LyXText::TextCase action)
                to = selection.end;
        } else {
                from = cursor;
-               ::getWord(*this, from, to, lyx::PARTIAL_WORD, ownerParagraphs());
+               getWord(from, to, lyx::PARTIAL_WORD);
                setCursor(to.par(), to.pos() + 1);
        }
 
@@ -1703,3 +1673,112 @@ bool LyXText::isFirstRow(ParagraphList::iterator pit, Row const & row) const
 {
        return row.pos() == 0 && pit == ownerParagraphs().begin();
 }
+
+
+void LyXText::cursorLeftOneWord(LyXCursor & cursor)
+{
+       // treat HFills, floats and Insets as words
+
+       ParagraphList::iterator pit = cursorPar();
+       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 != ownerParagraphs().begin()) {
+                       --pit;
+                       pos = pit->size();
+               }
+       } else {                // Here, cur != 0
+               while (pos > 0 && pit->isWord(pos - 1))
+                       --pos;
+       }
+
+       cursor.par(parOffset(pit));
+       cursor.pos(pos);
+}
+
+
+void LyXText::cursorRightOneWord(LyXCursor & cursor)
+{
+       // treat floats, HFills and Insets as words
+       ParagraphList::iterator pit = cursorPar();
+       pos_type pos = cursor.pos();
+
+       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;
+               }
+       }
+
+       cursor.par(parOffset(pit));
+       cursor.pos(pos);
+}
+
+
+void LyXText::getWord(LyXCursor & from, LyXCursor & to, word_location const loc)
+{
+       ParagraphList::iterator from_par = getPar(from);
+       ParagraphList::iterator to_par = getPar(to);
+       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
+
+       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);
+               break;
+       case lyx::PREVIOUS_WORD:
+               // always move the cursor to the beginning of previous word
+               cursorLeftOneWord(from);
+               break;
+       case lyx::NEXT_WORD:
+               lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
+                      << endl;
+               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 725bca209c530d2186845b8f419f25fa906f9be0..d4db0a8e4dd50c5e20922fec7f698e9fc4d6d23e 100644 (file)
@@ -399,7 +399,7 @@ void LyXText::setLayout(string const & layout)
 bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
 {
        ParagraphList::iterator pit = cursorPar();
-       ParagraphList::iterator end = cursorPar();
+       ParagraphList::iterator end = pit;
        ParagraphList::iterator start = pit;
 
        if (selection.set()) {
index a82a92dda507d41942f8e2595c59a74af9c5a6fa..14c6b210915d32cb79663e53c5cb5df0839360a7 100644 (file)
@@ -33,7 +33,6 @@
 #include "paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
-#include "text_funcs.h"
 #include "undo.h"
 #include "vspace.h"
 
@@ -703,7 +702,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_WORDSEL: {
                LyXCursor cur1 = cursor;
                LyXCursor cur2;
-               ::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
+               getWord(cur1, cur2, lyx::WHOLE_WORD);
                setCursor(cur1.par(), cur1.pos());
                clearSelection();
                setCursor(cur2.par(), cur2.pos());
@@ -1231,8 +1230,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                gotoInset(InsetOld::NOTE_CODE, false);
                break;
 
-       case LFUN_REFERENCE_GOTO:
-       {
+       case LFUN_REFERENCE_GOTO: {
                vector<InsetOld::Code> tmp;
                tmp.push_back(InsetOld::LABEL_CODE);
                tmp.push_back(InsetOld::REF_CODE);
diff --git a/src/text_funcs.C b/src/text_funcs.C
deleted file mode 100644 (file)
index ea091d5..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-/**
- * \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 <config.h>
-
-#include "text_funcs.h"
-#include "debug.h"
-#include "lyxcursor.h"
-#include "lyxtext.h"
-#include "paragraph.h"
-
-#include <boost/next_prior.hpp>
-
-using lyx::pos_type;
-using lyx::word_location;
-
-using std::endl;
-
-
-bool transposeChars(LyXText & text, LyXCursor const & cursor)
-{
-       ParagraphList::iterator tmppit = text.cursorPar();
-       pos_type tmppos = cursor.pos();
-
-       // First decide if it is possible to transpose at all
-
-       if (tmppos == 0 || tmppos == tmppit->size())
-               return false;
-
-       if (isDeletedText(*tmppit, tmppos - 1)
-               || isDeletedText(*tmppit, tmppos))
-               return false;
-
-       unsigned char c1 = tmppit->getChar(tmppos);
-       unsigned char c2 = tmppit->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 false;
-
-       bool const erased = tmppit->erase(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(LyXText & text,
-       LyXCursor & cursor, ParagraphList const & pars)
-{
-       // treat HFills, floats and Insets as words
-
-       ParagraphList::iterator pit = text.cursorPar();
-       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) {
-               // cast only for BSD's g++ 2.95
-               if (pit != const_cast<ParagraphList &>(pars).begin()) {
-                       --pit;
-                       pos = pit->size();
-               }
-       } else {                // Here, cur != 0
-               while (pos > 0 && pit->isWord(pos - 1))
-                       --pos;
-       }
-
-       cursor.par(text.parOffset(pit));
-       cursor.pos(pos);
-}
-
-
-void cursorRightOneWord(LyXText & text,
-       LyXCursor & cursor, ParagraphList const & pars)
-{
-       // treat floats, HFills and Insets as words
-       ParagraphList::iterator pit = text.cursorPar();
-       pos_type pos = cursor.pos();
-
-       // CHECK See comment on top of text.C
-
-       // cast only for BSD's g++ 2.95
-       if (pos == pit->size() &&
-               boost::next(pit) != const_cast<ParagraphList &>(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(text.parOffset(pit));
-       cursor.pos(pos);
-}
-
-
-// Select current word. This depends on behaviour of
-// CursorLeftOneWord(), so it is patched as well.
-void getWord(LyXText & text, LyXCursor & from, LyXCursor & to,
-       word_location const loc, ParagraphList const & pars)
-{
-       ParagraphList::iterator from_par = text.getPar(from);
-       ParagraphList::iterator to_par = text.getPar(to);
-       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
-
-       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(text, from, pars);
-               break;
-       case lyx::PREVIOUS_WORD:
-               // always move the cursor to the beginning of previous word
-               cursorLeftOneWord(text, from, pars);
-               break;
-       case lyx::NEXT_WORD:
-               lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
-                      << endl;
-               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);
-       }
-}
diff --git a/src/text_funcs.h b/src/text_funcs.h
deleted file mode 100644 (file)
index bd4a767..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-// -*- C++ -*-
-/**
- * \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 "ParagraphList_fwd.h"
-#include "support/types.h"
-
-class LyXCursor;
-class LyXText;
-
-
-// do no use LyXText or BufferView here
-
-
-///
-bool transposeChars(LyXText &, LyXCursor const & cursor);
-///
-void cursorLeftOneWord(LyXText &, LyXCursor &, ParagraphList const &);
-///
-void cursorRightOneWord(LyXText &, LyXCursor &, ParagraphList const &);
-
-// Select current word. This depends on behaviour of
-// CursorLeftOneWord(), so it is patched as well.
-void getWord(LyXText &, LyXCursor & from, LyXCursor & to, lyx::word_location const loc,
-       ParagraphList const & pars);
-
-#endif // TEXT_FUNCS_H