]> git.lyx.org Git - features.git/commitdiff
more shuffling...
authorAndré Pönitz <poenitz@gmx.net>
Wed, 14 Jan 2004 17:21:39 +0000 (17:21 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 14 Jan 2004 17:21:39 +0000 (17:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8347 a592a061-630c-0410-9148-cb99ea01b6c8

18 files changed:
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/PosIterator.C
src/bufferview_funcs.C
src/bufferview_funcs.h
src/frontends/controllers/ControlErrorList.C
src/frontends/controllers/ControlSpellchecker.C
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/lyx_cb.C
src/lyxfind.C
src/lyxtext.h
src/text.C
src/text2.C
src/text3.C
src/undo.C

index 2baef2572a9aceda2bb0b0f07755a093772f5c18..ca388dc4cf0a0078c8a1ede2ff2baab59507901b 100644 (file)
@@ -28,6 +28,7 @@
 #include "lyxtext.h"
 #include "paragraph.h"
 #include "paragraph_funcs.h"
+#include "PosIterator.h"
 #include "texrow.h"
 #include "undo.h"
 #include "WordLangTuple.h"
@@ -259,7 +260,7 @@ bool BufferView::insertLyXFile(string const & filen)
 
        string const fname = MakeAbsPath(filen);
 
-       text()->clearSelection();
+       clearSelection();
        text()->breakParagraph(buffer()->paragraphs());
 
        bool res = buffer()->readFile(fname, text()->cursorPar());
@@ -312,7 +313,7 @@ void BufferView::gotoLabel(string const & label)
                vector<string> labels;
                it->getLabelList(*buffer(), labels);
                if (find(labels.begin(),labels.end(),label) != labels.end()) {
-                       text()->clearSelection();
+                       clearSelection();
                        text()->setCursor(
                                std::distance(text()->paragraphs().begin(), it.getPar()),
                                it.getPos());
@@ -330,7 +331,7 @@ void BufferView::undo()
                return;
 
        owner()->message(_("Undo"));
-       text()->clearSelection();
+       clearSelection();
        if (!textUndo(this))
                owner()->message(_("No further undo information"));
        update();
@@ -344,7 +345,7 @@ void BufferView::redo()
                return;
 
        owner()->message(_("Redo"));
-       text()->clearSelection();
+       clearSelection();
        if (!textRedo(this))
                owner()->message(_("No further redo information"));
        update();
@@ -551,3 +552,65 @@ CursorSlice & BufferView::selEnd()
                return cursor();
        return anchor() > cursor() ? anchor() : cursor();
 }
+
+
+void BufferView::setSelection()
+{
+       selection().set(true);
+       // a selection with no contents is not a selection
+       if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
+               selection().set(false);
+}
+
+
+void BufferView::clearSelection()
+{
+       selection().set(false);
+       selection().mark(false);
+       resetAnchor();
+       unsetXSel();
+}
+
+
+
+/*
+if the fitCursor call refers to some point in never-explored-land, then we
+don't have y information in insets there, then we cannot even do an update
+to get it (because we need the y infomation for setting top_y first). So
+this is solved in put_selection_at with:
+
+- setting top_y to the y of the outerPar (that has good info)
+- calling update
+- calling cursor().updatePos()
+- then call fitCursor()
+
+Ab.
+*/
+
+void BufferView::putSelectionAt(PosIterator const & cur,
+                     int length, bool backwards)
+{
+       ParIterator par(cur);
+       
+       clearSelection();
+
+       LyXText * text = par.text(*buffer());
+       par.lockPath(this);
+       // hack for the chicken and egg problem
+       if (par.inset())
+               top_y(par.outerPar()->y);
+       update();
+       text->setCursor(cur.pit(), cur.pos());
+       fullCursor().updatePos();
+
+       if (length) {
+               text->setSelectionRange(length);
+               setSelection();
+               if (backwards)
+                       std::swap(cursor(), anchor());
+       }
+
+       fitCursor();
+       update();
+}
+
index 0e33ef08e75c92b7c7cc34c9ba5110195907a91f..a48fab0c842588b614c38370fd25d38c6f4053b7 100644 (file)
@@ -32,6 +32,7 @@ class LyXText;
 class LyXScreen;
 class LyXView;
 class Painter;
+class PosIterator;
 class Selection;
 class TeXErrors;
 class UpdatableInset;
@@ -142,6 +143,8 @@ public:
 
        /// replace the currently selected word
        void replaceWord(std::string const & replacestring);
+       /// simple replacing. Use the font of the first selected character 
+       void replaceSelectionWithString(std::string const & str);
 
        /// move cursor to the named label
        void gotoLabel(std::string const & label);
@@ -241,6 +244,12 @@ public:
        CursorSlice & selEnd();
        ///
        CursorSlice const & selEnd() const;
+       ///
+       void setSelection();
+       ///
+       void clearSelection();
+       ///
+       void putSelectionAt(PosIterator const & cur, int length, bool backwards);
 
        ///
        Selection selection_;
index 67f9f5262c21fbc6bb71874277bf684ddf7000da..c751f2771bfc3cf8fabeee9334e6af4d059a0d3d 100644 (file)
@@ -414,7 +414,7 @@ void BufferView::Pimpl::resizeCurrentBuffer()
                        text->setCursor(selstartpar, selstartpos);
                        bv_->resetAnchor();
                        text->setCursor(selendpar, selendpos);
-                       text->setSelection();
+                       bv_->setSelection();
                        text->setCursor(par, pos);
                } else {
                        text->setCursor(par, pos);
@@ -554,7 +554,7 @@ void BufferView::Pimpl::selectionLost()
 {
        if (available()) {
                screen().hideCursor();
-               bv_->getLyXText()->clearSelection();
+               bv_->clearSelection();
                xsel_cache_.set = false;
        }
 }
@@ -661,7 +661,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
 
        string const fname = saved_positions[i].filename;
 
-       bv_->text()->clearSelection();
+       bv_->clearSelection();
 
        if (fname != buffer_->fileName()) {
                Buffer * b = 0;
@@ -713,7 +713,7 @@ void BufferView::Pimpl::center()
 {
        LyXText * text = bv_->text();
 
-       text->clearSelection();
+       bv_->clearSelection();
        int const half_height = workarea().workHeight() / 2;
        int new_y = std::max(0, text->cursorY() - half_height);
 
@@ -751,7 +751,7 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
        // should work for now. Better infrastructure is coming. (Lgb)
 
        Buffer * b = bv_->buffer();
-       LyXText * text =  bv_->getLyXText();
+       LyXText * text = bv_->getLyXText();
 
        Buffer::inset_iterator beg = b->inset_iterator_begin();
        Buffer::inset_iterator end = b->inset_iterator_end();
@@ -1243,6 +1243,33 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                lyx::find::replace(ev);
                break;
 
+       case LFUN_MARK_OFF:
+               bv_->clearSelection();
+               bv_->update();
+               bv_->resetAnchor();
+               ev.message(N_("Mark off"));
+               break;
+
+       case LFUN_MARK_ON:
+               bv_->clearSelection();
+               bv_->selection().mark(true);
+               bv_->update();
+               bv_->resetAnchor();
+               ev.message(N_("Mark on"));
+               break;
+
+       case LFUN_SETMARK:
+               bv_->clearSelection();
+               if (bv_->selection().mark()) {
+                       ev.message(N_("Mark removed"));
+               } else {
+                       bv_->selection().mark(true);
+                       ev.message(N_("Mark set"));
+               }
+               bv_->resetAnchor();
+               bv_->update();
+               break;
+
        case LFUN_UNKNOWN_ACTION:
                ev.errorMessage(N_("Unknown function!"));
                break;
@@ -1261,7 +1288,7 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
        bv_->text()->recUndo(bv_->text()->cursor().par());
        freezeUndo();
 
-       bv_->text()->clearSelection();
+       bv_->clearSelection();
        if (!lout.empty()) {
                bv_->text()->breakParagraph(bv_->buffer()->paragraphs());
 
index d2e20651b6c6e8ecb7c97e57c739faf75954bd2f..69004c07948d079622c91b360f46f699546fd0b9 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "buffer.h"
 #include "BufferView.h"
+#include "cursor_slice.h"
 #include "iterators.h"
 #include "lyxtext.h"
 #include "paragraph.h"
@@ -26,6 +27,7 @@
 
 using boost::prior;
 
+
 PosIterator & PosIterator::operator++()
 {
        BOOST_ASSERT(!stack_.empty());
@@ -128,7 +130,7 @@ PosIterator::PosIterator(ParagraphList * pl, ParagraphList::iterator pit,
 PosIterator::PosIterator(BufferView & bv)
 {
        LyXText * text = bv.getLyXText();
-       lyx::pos_type pos = text->cursor().pos();
+       lyx::pos_type pos = bv.cursor().pos();
        ParagraphList::iterator pit = text->cursorPar();
        
        ParIterator par = bv.buffer()->par_iterator_begin();
index 93c26024dca4c76135ba2193e81bbc404b00d413..02eff2023481c78fe5e922f21237b410a2c830bf 100644 (file)
@@ -27,7 +27,6 @@
 #include "lyxrow.h"
 #include "paragraph.h"
 #include "ParagraphParameters.h"
-#include "PosIterator.h"
 #include "iterators.h"
 
 #include "frontends/Alert.h"
@@ -265,47 +264,4 @@ void replaceSelection(LyXText * text)
        }
 }
 
-
-/*
-if the fitCursor call refers to some point in never-explored-land, then we
-don't have y information in insets there, then we cannot even do an update
-to get it (because we need the y infomation for setting top_y first). So
-this is solved in put_selection_at with:
-
-- setting top_y to the y of the outerPar (that has good info)
-- calling update
-- calling cursor().updatePos()
-- then call fitCursor()
-
-Ab.
-*/
-
-void put_selection_at(BufferView * bv, PosIterator const & cur,
-                     int length, bool backwards)
-{
-       ParIterator par(cur);
-       
-       bv->getLyXText()->clearSelection();
-
-       LyXText * text = par.text(*bv->buffer());
-       par.lockPath(bv);
-       // hack for the chicken and egg problem
-       if (par.inset())
-               bv->top_y(par.outerPar()->y);
-       bv->update();
-       text->setCursor(cur.pit(), cur.pos());
-       bv->fullCursor().updatePos();
-
-       if (length) {
-               text->setSelectionRange(length);
-               text->setSelection();
-               if (backwards)
-                       std::swap(text->cursor(), text->anchor());
-       }
-
-       bv->fitCursor();
-       bv->update();
-}
-
-
 } // namespace bv_funcs
index 5ab134fd42e6a765a7d13a4214f39ab8b5f6b8a8..d6bf1c7c2618b41331f8667fe3b52658cf129652 100644 (file)
@@ -37,9 +37,6 @@ bool string2font(std::string const & data, LyXFont & font, bool & toggle);
  *  frontends.
  */
 std::string const freefont2string();
-///
-void put_selection_at(BufferView * bv, PosIterator const & cur,
-                     int length, bool backwards);
 
 
 /// what type of depth change to make
index 2d3fefe598b0e96a75e237c216314b2612fae189..0c87819e65dd3ef6a5a814c32197d176446b6846 100644 (file)
@@ -13,7 +13,6 @@
 #include "ControlErrorList.h"
 #include "buffer.h"
 #include "BufferView.h"
-#include "bufferview_funcs.h"
 #include "debug.h"
 #include "iterators.h"
 #include "lyxtext.h"
@@ -75,5 +74,5 @@ void ControlErrorList::goTo(int item)
 
        // Now make the selection.
        PosIterator const pos = pit.asPosIterator(start);
-       bv_funcs::put_selection_at(kernel().bufferview(), pos, range, false);
+       kernel().bufferview()->putSelectionAt(pos, range, false);
 }
index 503c40dcf5d7fc388ad27c234f555258fce0a2d2..1de7fb2c30131212847d9193fdde874060204864 100644 (file)
@@ -236,7 +236,7 @@ void ControlSpellchecker::check()
        if (!word_.word().empty()) {
                int const size = word_.word().size();
                advance(cur, -size);
-               bv_funcs::put_selection_at(bufferview(), cur, size, false);
+               bufferview()->putSelectionAt(cur, size, false);
                advance(cur, size);
        } else {
                showSummary();
index ad7754429cd28cf6cb103cdd291e11220b858f17..cd13bcc1e2e7cd4c338641173228ca3c17c14e11 100644 (file)
@@ -423,7 +423,7 @@ void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
        setPos(bv, cmd.x, cmd.y);
        if (!hasSelection()) {
                setSelection(actcell, actcell);
-               tabular.getCellInset(actcell).text_.setSelection();
+               bv->setSelection();
        } else {
                bv->cursor().cell(actcell);
                setSelection(sel_cell_start, actcell);
index 33802b38101b6c3527b0bc8db40ea2b04972dc29..09a509de3a27a7cbfcc83515439e8d8c78189890 100644 (file)
@@ -84,7 +84,7 @@ public:
        ///
        void updateLocal(BufferView *) const;
        ///
-       bool insetAllowed(InsetOld::Code code) const { return true; }
+       bool insetAllowed(InsetOld::Code) const { return true; }
        ///
        bool isTextInset() const { return true; }
        /** returns true if, when outputing LaTeX, font changes should
index f1eedec9e619bcd4008435a977f7a13c4fe8366d..aa15d2e3d2d19424bd1b5aaeadb0f32448bac7ac 100644 (file)
@@ -277,7 +277,7 @@ void InsetText::edit(BufferView * bv, bool left)
        int const par = left ? 0 : paragraphs().size() - 1;
        int const pos = left ? 0 : paragraphs().back().size();
        text_.setCursor(par, pos);
-       text_.clearSelection();
+       bv->clearSelection();
        finishUndo();
        sanitizeEmptyText(bv);
        updateLocal(bv);
@@ -290,7 +290,7 @@ void InsetText::edit(BufferView * bv, int x, int y)
        lyxerr << "InsetText::edit xy" << endl;
        old_par = -1;
        text_.setCursorFromCoordinates(x - text_.xo_, y + bv->top_y() - text_.yo_);
-       text_.clearSelection();
+       bv->clearSelection();
        finishUndo();
        sanitizeEmptyText(bv);
        updateLocal(bv);
@@ -542,7 +542,7 @@ void InsetText::collapseParagraphs(BufferView * bv)
                        first->insertChar(first_par_size, ' ');
                }
 
-               text_.clearSelection();
+               bv->clearSelection();
                mergeParagraph(bv->buffer()->params(), paragraphs(), first);
        }
 }
index fda8f46af66635cedf770366c5e2cb2f5d92e9ee..d8c34ada01f61a9647b8259201e3b3229270cba5 100644 (file)
@@ -358,7 +358,7 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
 
        // clear the selection
        if (bv->text() == bv->getLyXText())
-               bv->text()->clearSelection();
+               bv->clearSelection();
        if (asParagraph)
                bv->getLyXText()->insertStringAsParagraphs(tmpstr);
        else
index 87225f67ed3e6bc8bb2de0e96c19a774eb9c2e34..96c3da77a069677bcdbc7d7a81e6f8851a2dcc23 100644 (file)
@@ -16,6 +16,7 @@
 #include "lyxfind.h"
 
 #include "buffer.h"
+#include "cursor_slice.h"
 #include "BufferView.h"
 #include "debug.h"
 #include "iterators.h"
@@ -38,8 +39,6 @@ using lyx::support::lowercase;
 using lyx::support::uppercase;
 using lyx::support::split;
 
-using bv_funcs::put_selection_at;
-
 using std::ostringstream;
 using std::string;
 
@@ -202,7 +201,7 @@ bool findNextChange(BufferView * bv)
                }
        }
        pos_type length = end - pos;
-       put_selection_at(bv, cur, length, true);
+       bv->putSelectionAt(cur, length, true);
        return true;
 }
 
@@ -317,7 +316,7 @@ bool find(BufferView * bv, string const & searchstr, bool cs, bool mw, bool fw)
                : findBackwards(cur, beg, match);
 
        if (found)
-               put_selection_at(bv, cur, searchstr.length(), !fw);
+               bv->putSelectionAt(cur, searchstr.length(), !fw);
 
        return found;
 }
@@ -354,7 +353,7 @@ int replaceAll(BufferView * bv,
 
        PosIterator beg = buf.pos_iterator_begin();
        bv->text()->init(bv);
-       put_selection_at(bv, beg, 0, false);
+       bv->putSelectionAt(beg, 0, false);
        if (num)
                buf.markDirty();
        return num;
index 44a8419f58f68a1c8609bfba4c5169fe2217a574..f63a9a1eaa4108f78207712492ccc2af0b798f91 100644 (file)
@@ -15,7 +15,6 @@
 #define LYXTEXT_H
 
 #include "bufferview_funcs.h"
-#include "cursor_slice.h"
 #include "Bidi.h"
 #include "layout.h"
 #include "lyxfont.h"
@@ -405,11 +404,6 @@ public:
        /// access to the selection anchor
        CursorSlice const & anchor() const;
 
-       ///
-       void setSelection();
-       ///
-       void clearSelection();
-
 public:
        ///
        int height;
index eaccc9cc027ac5ca63ab8e0d09e5e6f1c386d30f..5f477a7605f2f3e43538dc906b83150b518c6f54 100644 (file)
@@ -833,7 +833,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
 // convenience function
 void LyXText::redoParagraph()
 {
-       clearSelection();
+       bv()->clearSelection();
        redoParagraph(cursorPar());
        setCursorIntern(cursor().par(), cursor().pos());
 }
@@ -1106,7 +1106,7 @@ void LyXText::selectWord(word_location loc)
                return;
        bv()->resetAnchor();
        setCursor(to.par(), to.pos());
-       setSelection();
+       bv()->setSelection();
 }
 
 
@@ -1133,7 +1133,7 @@ void LyXText::acceptChange()
                recordUndo(Undo::INSERT, this, startc.par());
                getPar(startc)->acceptChange(startc.pos(), endc.pos());
                finishUndo();
-               clearSelection();
+               bv()->clearSelection();
                redoParagraph(getPar(startc));
                setCursorIntern(startc.par(), 0);
        }
@@ -1152,7 +1152,7 @@ void LyXText::rejectChange()
                recordUndo(Undo::INSERT, this, startc.par());
                getPar(startc)->rejectChange(startc.pos(), endc.pos());
                finishUndo();
-               clearSelection();
+               bv()->clearSelection();
                redoParagraph(getPar(startc));
                setCursorIntern(startc.par(), 0);
        }
@@ -1172,7 +1172,7 @@ void LyXText::deleteWordForward()
                setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
                bv()->resetAnchor();
                cursor() = tmpcursor;
-               setSelection();
+               bv()->setSelection();
                cutSelection(true, false);
        }
 }
@@ -1190,7 +1190,7 @@ void LyXText::deleteWordBackward()
                setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
                bv()->resetAnchor();
                cursor() = tmpcursor;
-               setSelection();
+               bv()->setSelection();
                cutSelection(true, false);
        }
 }
@@ -1209,7 +1209,7 @@ void LyXText::deleteLineForward()
                setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
                bv()->resetAnchor();
                cursor() = tmpcursor;
-               setSelection();
+               bv()->setSelection();
                // What is this test for ??? (JMarc)
                if (!bv()->selection().set())
                        deleteWordForward();
@@ -1957,24 +1957,3 @@ CursorSlice const & LyXText::anchor() const
 {
        return bv()->anchor();
 }
-
-
-void LyXText::setSelection()
-{
-       bv()->selection().set(true);
-       // a selection with no contents is not a selection
-       if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
-               bv()->selection().set(false);
-}
-
-
-void LyXText::clearSelection()
-{
-       bv()->selection().set(false);
-       bv()->selection().mark(false);
-       bv()->resetAnchor();
-       // reset this in the bv()!
-       if (bv() && bv()->text())
-               bv()->unsetXSel();
-}
-
index c362d0dc5a71a486e43cd5d08e0639fe94c06922..d29df28b39a25ff46b6ac6e1b8d44e5e0967d52b 100644 (file)
@@ -530,7 +530,7 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
        // Implicit selections are cleared afterwards
        //and cursor is set to the original position.
        if (implicitSelection) {
-               clearSelection();
+               bv()->clearSelection();
                cursor() = resetCursor;
                bv()->resetAnchor();
        }
@@ -560,7 +560,7 @@ string LyXText::getStringToIndex()
 
        // Clear the implicit selection.
        if (implicitSelection)
-               clearSelection();
+               bv()->clearSelection();
 
        return idxstring;
 }
@@ -968,7 +968,7 @@ void LyXText::cutSelection(bool doclear, bool realcut)
        cursor().par(parOffset(endpit));
 
        // need a valid cursor. (Lgb)
-       clearSelection();
+       bv()->clearSelection();
        updateCounters();
 }
 
@@ -1024,11 +1024,10 @@ void LyXText::pasteSelection(size_t sel_index)
 
        redoParagraphs(cursorPar(), endpit);
 
-       clearSelection();
-
+       bv()->clearSelection();
        bv()->resetAnchor();
        setCursor(ppp.first, ppp.second);
-       setSelection();
+       bv()->setSelection();
        updateCounters();
 }
 
@@ -1041,7 +1040,7 @@ void LyXText::setSelectionRange(lyx::pos_type length)
        bv()->resetAnchor();
        while (length--)
                cursorRight(true);
-       setSelection();
+       bv()->setSelection();
 }
 
 
@@ -1082,14 +1081,13 @@ void LyXText::insertStringAsLines(string const & str)
        recUndo(cursor().par());
 
        // only to be sure, should not be neccessary
-       clearSelection();
-
+       bv()->clearSelection();
        bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
 
        redoParagraphs(cursorPar(), endpit);
        bv()->resetAnchor();
        setCursor(pit, pos);
-       setSelection();
+       bv()->setSelection();
 }
 
 
@@ -1401,7 +1399,7 @@ DispatchResult LyXText::moveRightIntern(bool front, bool activate_inset, bool se
                return DispatchResult(true, true);
        cursorRight(true);
        if (!selecting)
-               clearSelection();
+               bv()->clearSelection();
        return DispatchResult(true);
 }
 
@@ -1413,7 +1411,7 @@ DispatchResult LyXText::moveLeftIntern(bool front,
                return DispatchResult(false, FINISHED);
        cursorLeft(true);
        if (!selecting)
-               clearSelection();
+               bv()->clearSelection();
        if (activate_inset && checkAndActivateInset(front))
                return DispatchResult(true, true);
        return DispatchResult(true);
@@ -1425,7 +1423,7 @@ DispatchResult LyXText::moveUp()
        if (cursorPar() == firstPar() && cursorRow() == firstRow())
                return DispatchResult(false, FINISHED_UP);
        cursorUp(false);
-       clearSelection();
+       bv()->clearSelection();
        return DispatchResult(true);
 }
 
@@ -1435,7 +1433,7 @@ DispatchResult LyXText::moveDown()
        if (cursorPar() == lastPar() && cursorRow() == lastRow())
                return DispatchResult(false, FINISHED_DOWN);
        cursorDown(false);
-       clearSelection();
+       bv()->clearSelection();
        return DispatchResult(true);
 }
 
@@ -1562,6 +1560,9 @@ void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where)
 
 bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor)
 {
+#warning Disabled as it crashes after the cursor data shift... (Andre)
+       return false;
+
        // Would be wrong to delete anything if we have a selection.
        if (bv()->selection().set())
                return false;
index c3e533c83890be6c8a50e25560b628ab2b406fcf..7c34e2c4c9ca9e60910e31af5bff7c2baa795103 100644 (file)
@@ -215,10 +215,8 @@ namespace {
 
        void moveCursor(BufferView * bv, bool selecting)
        {
-               LyXText * lt = bv->getLyXText();
-
                if (selecting || bv->selection().mark())
-                       lt->setSelection();
+                       bv->setSelection();
 
                if (!bv->selection().set())
                        bv->haveSelection(false);
@@ -321,7 +319,7 @@ bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
 void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
                        bool same_content)
 {
-       clearSelection();
+       bv()->clearSelection();
 
        string contents;
        if (same_content && cursor().pos() < cursorPar()->size()
@@ -486,26 +484,26 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_DELETE_WORD_FORWARD:
-               clearSelection();
+               bv->clearSelection();
                deleteWordForward();
                finishChange(bv);
                break;
 
        case LFUN_DELETE_WORD_BACKWARD:
-               clearSelection();
+               bv->clearSelection();
                deleteWordBackward();
                finishChange(bv);
                break;
 
        case LFUN_DELETE_LINE_FORWARD:
-               clearSelection();
+               bv->clearSelection();
                deleteLineForward();
                finishChange(bv);
                break;
 
        case LFUN_WORDRIGHT:
                if (!bv->selection().mark())
-                       clearSelection();
+                       bv->clearSelection();
                if (rtl())
                        cursorLeftOneWord();
                else
@@ -515,7 +513,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_WORDLEFT:
                if (!bv->selection().mark())
-                       clearSelection();
+                       bv->clearSelection();
                if (rtl())
                        cursorRightOneWord();
                else
@@ -525,14 +523,14 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_BEGINNINGBUF:
                if (!bv->selection().mark())
-                       clearSelection();
+                       bv->clearSelection();
                cursorTop();
                finishChange(bv);
                break;
 
        case LFUN_ENDBUF:
                if (bv->selection().mark())
-                       clearSelection();
+                       bv->clearSelection();
                cursorBottom();
                finishChange(bv);
                break;
@@ -657,21 +655,21 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_UP_PARAGRAPH:
                if (!bv->selection().mark())
-                       clearSelection();
+                       bv->clearSelection();
                cursorUpParagraph();
                finishChange(bv);
                break;
 
        case LFUN_DOWN_PARAGRAPH:
                if (!bv->selection().mark())
-                       clearSelection();
+                       bv->clearSelection();
                cursorDownParagraph();
                finishChange(bv, false);
                break;
 
        case LFUN_PRIOR:
                if (!bv->selection().mark())
-                       clearSelection();
+                       bv->clearSelection();
                finishChange(bv, false);
                if (cursorPar() == firstPar() && cursorRow() == firstRow())
                        return DispatchResult(false, FINISHED_UP);
@@ -680,7 +678,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_NEXT:
                if (!bv->selection().mark())
-                       clearSelection();
+                       bv->clearSelection();
                finishChange(bv, false);
                if (cursorPar() == lastPar() && cursorRow() == lastRow())
                        return DispatchResult(false, FINISHED_DOWN);
@@ -689,14 +687,14 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_HOME:
                if (!bv->selection().mark())
-                       clearSelection();
+                       bv->clearSelection();
                cursorHome();
                finishChange(bv, false);
                break;
 
        case LFUN_END:
                if (!bv->selection().mark())
-                       clearSelection();
+                       bv->clearSelection();
                cursorEnd();
                finishChange(bv, false);
                break;
@@ -881,7 +879,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_INSET_TOGGLE:
-               clearSelection();
+               bv->clearSelection();
                if (!toggleInset())
                        return DispatchResult(false);
                bv->update();
@@ -916,33 +914,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR);
                break;
 
-       case LFUN_MARK_OFF:
-               clearSelection();
-               bv->update();
-               bv->resetAnchor();
-               cmd.message(N_("Mark off"));
-               break;
-
-       case LFUN_MARK_ON:
-               clearSelection();
-               bv->selection().mark(true);
-               bv->update();
-               bv->resetAnchor();
-               cmd.message(N_("Mark on"));
-               break;
-
-       case LFUN_SETMARK:
-               clearSelection();
-               if (bv->selection().mark()) {
-                       cmd.message(N_("Mark removed"));
-               } else {
-                       bv->selection().mark(true);
-                       cmd.message(N_("Mark set"));
-               }
-               bv->resetAnchor();
-               bv->update();
-               break;
-
        case LFUN_UPCASE_WORD:
                changeCase(LyXText::text_uppercase);
                bv->update();
@@ -972,7 +943,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                        pasteSelection(strToUnsignedInt(cmd.argument));
                else
                        pasteSelection(0);
-               clearSelection(); // bug 393
+               bv->clearSelection(); // bug 393
                bv->update();
                bv->switchKeyMap();
                finishUndo();
@@ -1097,9 +1068,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_PASTESELECTION: {
-               // this was originally a bv->text->clearSelection(), i.e
-               // the outermost LyXText!
-               clearSelection();
+               bv->clearSelection();
                string const clip = bv->getClipboard();
                if (!clip.empty()) {
                        if (cmd.argument == "paragraph")
@@ -1179,7 +1148,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                        cursorHome();
                        bv->resetAnchor();
                        cursorEnd();
-                       setSelection();
+                       bv->setSelection();
                        bv->haveSelection(bv->selection().set());
                }
                break;
@@ -1221,7 +1190,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                        else if (cmd.y - bv->top_y() < 0)
                                cursorUp(true);
                }
-               setSelection();
+               bv->setSelection();
                break;
        }
 
@@ -1256,7 +1225,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                selection_possible = true;
 
                // Clear the selection
-               clearSelection();
+               bv->clearSelection();
 
                // Right click on a footnote flag opens float menu
                if (cmd.button() == mouse_button::button3) {
@@ -1326,7 +1295,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                        bv->haveSelection(false);
                }
 
-               clearSelection();
+               bv->clearSelection();
                LyXFont const old_font = real_current_font;
 
                string::const_iterator cit = cmd.argument.begin();
index 7bcf23b74a11bd103e37e7d10599f55e0b5095df..410ec3bc355b6ca8492b882664b6970a024d5e81 100644 (file)
@@ -17,6 +17,7 @@
 #include "undo.h"
 
 #include "buffer.h"
+#include "cursor_slice.h"
 #include "debug.h"
 #include "BufferView.h"
 #include "iterators.h"
@@ -178,11 +179,11 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo)
               << std::endl;
 
        // set cursor again to force the position to be the right one
-       text->cursor().par(undo.cursor_par);
-       text->cursor().pos(undo.cursor_pos);
+       bv->cursor().par(undo.cursor_par);
+       bv->cursor().pos(undo.cursor_pos);
 
        // clear any selection
-       text->clearSelection();
+       bv->clearSelection();
        bv->resetAnchor();
        text->updateCounters();
 
@@ -224,9 +225,8 @@ bool textUndoOrRedo(BufferView * bv,
                        advance(last, plist.size() - undo.end_par + 1);
                        otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last);
                }
-               LyXText * text = pit.text(buf);
-               otherstack.top().cursor_pos = text->cursor().pos();
-               otherstack.top().cursor_par = text->cursor().par();
+               otherstack.top().cursor_pos = bv->cursor().pos();
+               otherstack.top().cursor_par = bv->cursor().par();
                lyxerr << " undo other: " << otherstack.top() << std::endl;
        }