On Sat, Aug 09, 2003 at 01:00:57PM +0200, Juergen Spitzmueller wrote:
> Andre Poenitz wrote:
> > What is it good for?
> 
> it toggles the selection ;-)

Under what circumstances would I notice it?

> > Everything still seems to work if I simply remove it?
> 
> It has been used in text3.C before I have introduced my replaceSelection 
> method (to replace selected text with pasted or typed text). In the old days, 
> the text would have remained selected after insertion, which looked at least 
> odd. That has become redundant of course since the selection was deleted.
> 
> Don't know if it is also used in other places though.

Would you mind quickly testing the attached patch?

Andre'

-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one.     (T. Jefferson or B. Franklin or both...)
? .text2.C.swp
? 1.diff
? 2.diff
? 4.diff
? 5.diff
? fullredraw.diff
? par-row.diff
? insets/1.diff
Index: BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.177
diff -u -p -r1.177 BufferView.C
--- BufferView.C        5 Aug 2003 08:07:00 -0000       1.177
+++ BufferView.C        15 Aug 2003 10:04:22 -0000
@@ -214,12 +214,6 @@ int BufferView::workWidth() const
 }
 
 
-void BufferView::toggleSelection(bool b)
-{
-       pimpl_->toggleSelection(b);
-}
-
-
 void BufferView::center()
 {
        pimpl_->center();
@@ -419,7 +413,6 @@ void BufferView::selectLastWord()
        beforeChange(text);
        text->selection.cursor = cur;
        text->selectSelectedWord();
-       toggleSelection(false);
        update();
 }
 
@@ -442,13 +435,7 @@ void BufferView::replaceWord(string cons
 
        LyXText * tt = getLyXText();
 
-       // clear the selection (if there is any)
-       toggleSelection(false);
-
-       // clear the selection (if there is any)
-       toggleSelection(false);
        tt->replaceSelectionWithString(replacestring);
-
        tt->setSelectionRange(replacestring.length());
 
        // Go back so that replacement string is also spellchecked
Index: BufferView.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.h,v
retrieving revision 1.138
diff -u -p -r1.138 BufferView.h
--- BufferView.h        5 Aug 2003 08:07:00 -0000       1.138
+++ BufferView.h        15 Aug 2003 10:04:22 -0000
@@ -155,8 +155,6 @@ public:
 
        /// FIXME
        bool fitLockedInsetCursor(int x, int y, int asc, int desc);
-       /// FIXME
-       void toggleSelection(bool = true);
 
        /// hide the cursor if it is visible
        void hideCursor();
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.411
diff -u -p -r1.411 BufferView_pimpl.C
--- BufferView_pimpl.C  11 Aug 2003 09:08:51 -0000      1.411
+++ BufferView_pimpl.C  15 Aug 2003 10:04:22 -0000
@@ -577,7 +577,6 @@ void BufferView::Pimpl::selectionLost()
 {
        if (available()) {
                screen().hideCursor();
-               toggleSelection();
                bv_->getLyXText()->clearSelection();
                bv_->text->xsel_cache.set(false);
        }
@@ -662,19 +661,18 @@ Change const BufferView::Pimpl::getCurre
        if (!bv_->buffer()->params.tracking_changes)
                return Change(Change::UNCHANGED);
 
-       LyXText * t(bv_->getLyXText());
+       LyXText * text = bv_->getLyXText();
 
-       if (!t->selection.set())
+       if (!text->selection.set())
                return Change(Change::UNCHANGED);
 
-       LyXCursor const & cur(t->selection.start);
+       LyXCursor const & cur = text->selection.start;
        return cur.par()->lookupChangeFull(cur.pos());
 }
 
 
 void BufferView::Pimpl::beforeChange(LyXText * text)
 {
-       toggleSelection();
        text->clearSelection();
 }
 
@@ -760,12 +758,6 @@ void BufferView::Pimpl::insetUnlock()
                bv_->theLockingInset(0);
                finishUndo();
        }
-}
-
-
-void BufferView::Pimpl::toggleSelection(bool b)
-{
-       screen().toggleSelection(bv_->text, bv_, b);
 }
 
 
Index: BufferView_pimpl.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.h,v
retrieving revision 1.99
diff -u -p -r1.99 BufferView_pimpl.h
--- BufferView_pimpl.h  11 Aug 2003 09:08:52 -0000      1.99
+++ BufferView_pimpl.h  15 Aug 2003 10:04:22 -0000
@@ -89,8 +89,6 @@ struct BufferView::Pimpl : public boost:
        ///
        void insetUnlock();
        ///
-       void toggleSelection(bool = true);
-       ///
        void center();
        ///
        bool insertInset(InsetOld * inset, string const & lout = string());
Index: lyxfind.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfind.C,v
retrieving revision 1.44
diff -u -p -r1.44 lyxfind.C
--- lyxfind.C   4 Aug 2003 09:06:31 -0000       1.44
+++ lyxfind.C   15 Aug 2003 10:04:22 -0000
@@ -198,7 +198,6 @@ int replace(BufferView * bv,
                if (!bv->theLockingInset() ||
                        ((text != bv->text) &&
                         (text->inset_owner == text->inset_owner->getLockingInset()))) 
{
-                       bv->toggleSelection(false);
                        text->replaceSelectionWithString(replacestr);
                        text->setSelectionRange(replacestr.length());
                        ++replace_count;
@@ -247,7 +246,6 @@ bool find(BufferView * bv,
                text->cursor = forward ?
                        text->selection.end : text->selection.start;
 
-       bv->toggleSelection();
        text->clearSelection();
 
        SearchResult result = forward ?
@@ -261,7 +259,6 @@ bool find(BufferView * bv,
        if (result == SR_FOUND) {
                bv->unlockInset(bv->theLockingInset());
                text->setSelectionRange(searchstr.length());
-               bv->toggleSelection(false);
        } else if (result == SR_NOT_FOUND) {
                bv->unlockInset(bv->theLockingInset());
                found = false;
@@ -281,7 +278,6 @@ SearchResult find(BufferView * bv, LyXTe
                text->cursor = forward ?
                        text->selection.end : text->selection.start;
 
-       bv->toggleSelection();
        text->clearSelection();
 
        SearchResult result = forward ?
@@ -351,7 +347,6 @@ SearchResult findNextChange(BufferView *
        if (text->selection.set())
                text->cursor = text->selection.end;
 
-       bv->toggleSelection();
        text->clearSelection();
 
        return nextChange(bv, text, length);
@@ -385,7 +380,6 @@ bool findNextChange(BufferView * bv)
        if (text->selection.set())
                text->cursor = text->selection.end;
 
-       bv->toggleSelection();
        text->clearSelection();
 
        SearchResult result = nextChange(bv, text, length);
@@ -398,7 +392,6 @@ bool findNextChange(BufferView * bv)
        if (result == SR_FOUND) {
                bv->unlockInset(bv->theLockingInset());
                text->setSelectionRange(length);
-               bv->toggleSelection(false);
        } else if (result == SR_NOT_FOUND) {
                bv->unlockInset(bv->theLockingInset());
                found = false;
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.216
diff -u -p -r1.216 lyxtext.h
--- lyxtext.h   15 Aug 2003 08:03:50 -0000      1.216
+++ lyxtext.h   15 Aug 2003 10:04:22 -0000
@@ -39,7 +39,10 @@ class Dimension;
 
 
 /**
-  This class holds the mapping between buffer paragraphs and screen rows.
+  This class used to hold the mapping between buffer paragraphs and
+       screen rows. Nowadays, the Paragraphs take care of their rows
+  themselves and this contains just most of the code for manipulating 
+  them and interaction with the Cursor. 
   */
 
 // The inheritance from TextCursor should go. It's just there to ease
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.115
diff -u -p -r1.115 text3.C
--- text3.C     15 Aug 2003 08:03:52 -0000      1.115
+++ text3.C     15 Aug 2003 10:04:22 -0000
@@ -1172,14 +1172,10 @@ InsetOld::RESULT LyXText::dispatch(FuncR
                if (!isInInset() && bv->theLockingInset())
                        break;
                if (cmd.button() == mouse_button::button1) {
-                       if (!isInInset())
-                               bv->screen().toggleSelection(this, bv);
                        cursorHome();
                        selection.cursor = cursor;
                        cursorEnd();
                        setSelection();
-                       if (!isInInset())
-                               bv->screen().toggleSelection(this, bv, false);
                        bv->update();
                        bv->haveSelection(selection.set());
                }
@@ -1191,13 +1187,7 @@ InsetOld::RESULT LyXText::dispatch(FuncR
                if (!isInInset() && bv->theLockingInset())
                        break;
                if (cmd.button() == mouse_button::button1) {
-                       if (!isInInset()) {
-                               bv->screen().toggleSelection(this, bv);
-                               selectWord(lyx::WHOLE_WORD_STRICT);
-                               bv->screen().toggleSelection(this, bv, false);
-                       } else {
-                               selectWord(lyx::WHOLE_WORD_STRICT);
-                       }
+                       selectWord(lyx::WHOLE_WORD_STRICT);
                        bv->update();
                        bv->haveSelection(selection.set());
                }
@@ -1314,7 +1304,6 @@ InsetOld::RESULT LyXText::dispatch(FuncR
                        selection_possible = true;
 
                // Clear the selection
-               bv->screen().toggleSelection(bv->text, bv);
                bv->text->clearSelection();
                bv->update();
                bv->updateScrollbar();
Index: frontends/screen.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/screen.C,v
retrieving revision 1.60
diff -u -p -r1.60 screen.C
--- frontends/screen.C  15 Aug 2003 08:03:52 -0000      1.60
+++ frontends/screen.C  15 Aug 2003 10:04:22 -0000
@@ -297,38 +297,6 @@ bool LyXScreen::fitCursor(LyXText * text
 }
 
 
-void LyXScreen::toggleSelection(LyXText * text, BufferView * bv,
-                               bool kill_selection,
-                               int yo, int xo)
-{
-       // only if there is a selection
-       if (!text->selection.set())
-               return;
-
-       int const bottom = min(
-               max(int(text->selection.end.y()
-                                    - text->getRow(text->selection.end)->baseline()
-                                    + text->getRow(text->selection.end)->height()),
-                   text->top_y()),
-               int(text->top_y() + workarea().workHeight()));
-       int const top = min(
-               max(int(text->selection.start.y() -
-                                    text->getRow(text->selection.start)->baseline()),
-                   text->top_y()),
-               int(text->top_y() + workarea().workHeight()));
-
-       if (kill_selection)
-               text->selection.set(false);
-
-       workarea().getPainter().start();
-
-       drawFromTo(text, bv, top - text->top_y(), bottom - text->top_y(), yo, xo);
-       expose(0, top - text->top_y(), workarea().workWidth(), bottom - top);
-
-       workarea().getPainter().end();
-}
-
-
 void LyXScreen::redraw(BufferView & bv)
 {
        greyed_out_ = !bv.text;
Index: frontends/screen.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/screen.h,v
retrieving revision 1.21
diff -u -p -r1.21 screen.h
--- frontends/screen.h  1 Aug 2003 14:51:09 -0000       1.21
+++ frontends/screen.h  15 Aug 2003 10:04:22 -0000
@@ -92,10 +92,6 @@ public:
        /// toggle the cursor's visibility
        void toggleCursor(BufferView & bv);
 
-       /// FIXME
-       virtual void toggleSelection(LyXText *, BufferView *, bool = true,
-                            int y_offset = 0, int x_offset = 0);
-
 protected:
        /// cause the display of the given area of the work area
        virtual void expose(int x, int y, int w, int h) = 0;
Index: frontends/controllers/ControlErrorList.C
===================================================================
RCS file: 
/usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlErrorList.C,v
retrieving revision 1.7
diff -u -p -r1.7 ControlErrorList.C
--- frontends/controllers/ControlErrorList.C    4 Aug 2003 09:06:35 -0000       1.7
+++ frontends/controllers/ControlErrorList.C    15 Aug 2003 10:04:22 -0000
@@ -75,11 +75,9 @@ void ControlErrorList::goTo(int item)
        // Now make the selection.
        BufferView * const bv = kernel().bufferview();
        bv->insetUnlock();
-       bv->toggleSelection();
        bv->text->clearSelection();
        bv->text->setCursor(pit.pit(), err.pos_start);
        bv->text->setSelectionRange(range);
-       bv->toggleSelection(false);
        bv->fitCursor();
        bv->update();
 }
Index: frontends/controllers/ControlSpellchecker.C
===================================================================
RCS file: 
/usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlSpellchecker.C,v
retrieving revision 1.48
diff -u -p -r1.48 ControlSpellchecker.C
--- frontends/controllers/ControlSpellchecker.C 7 Aug 2003 10:12:49 -0000       1.48
+++ frontends/controllers/ControlSpellchecker.C 15 Aug 2003 10:04:22 -0000
@@ -149,7 +149,6 @@ void ControlSpellchecker::check()
 
        // clear any old selection
        LyXText * text = bufferview()->getLyXText();
-       bufferview()->toggleSelection(true);
        bufferview()->update();
 
        while (res == SpellBase::OK || res == SpellBase::IGNORE) {

Reply via email to