]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Transfer current_font and real_current_font from Text to Cursor.
[lyx.git] / src / TextMetrics.cpp
index e1c9c845b1252215f2118b2ae131004e4eb81782..cb5946266832028daa23517cadf5e5a92fb5b783 100644 (file)
 #include "TextMetrics.h"
 
 #include "Buffer.h"
+#include "buffer_funcs.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "bufferview_funcs.h"
 #include "Color.h"
 #include "CoordCache.h"
+#include "CutAndPaste.h"
 #include "debug.h"
 #include "FontIterator.h"
 #include "FuncRequest.h"
@@ -1110,7 +1112,9 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y)
        if (!inset) {
                // Either we deconst editXY or better we move current_font
                // and real_current_font to Cursor
-               text_->setCurrentFont(cur);
+               // FIXME: what is needed now that current_font and real_current_font
+               // are transferred?
+               cur.setCurrentFont();
                return 0;
        }
 
@@ -1134,7 +1138,7 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y)
        inset = inset->editXY(cur, x, y);
 
        if (cur.top().text() == text_)
-               text_->setCurrentFont(cur);
+               cur.setCurrentFont();
        return inset;
 }
 
@@ -1400,6 +1404,75 @@ void TextMetrics::cursorNext(Cursor & cur)
 }
 
 
+// the cursor set functions have a special mechanism. When they
+// realize you left an empty paragraph, they will delete it.
+
+bool TextMetrics::cursorHome(Cursor & cur)
+{
+       BOOST_ASSERT(text_ == cur.text());
+       ParagraphMetrics const & pm = par_metrics_[cur.pit()];
+       Row const & row = pm.getRow(cur.pos(),cur.boundary());
+       return text_->setCursor(cur, cur.pit(), row.pos());
+}
+
+
+bool TextMetrics::cursorEnd(Cursor & cur)
+{
+       BOOST_ASSERT(text_ == cur.text());
+       // if not on the last row of the par, put the cursor before
+       // the final space exept if I have a spanning inset or one string
+       // is so long that we force a break.
+       pos_type end = cur.textRow().endpos();
+       if (end == 0)
+               // empty text, end-1 is no valid position
+               return false;
+       bool boundary = false;
+       if (end != cur.lastpos()) {
+               if (!cur.paragraph().isLineSeparator(end-1)
+                   && !cur.paragraph().isNewline(end-1))
+                       boundary = true;
+               else
+                       --end;
+       }
+       return text_->setCursor(cur, cur.pit(), end, true, boundary);
+}
+
+
+void TextMetrics::deleteLineForward(Cursor & cur)
+{
+       BOOST_ASSERT(text_ == cur.text());
+       if (cur.lastpos() == 0) {
+               // Paragraph is empty, so we just go to the right
+               text_->cursorRight(cur);
+       } else {
+               cur.resetAnchor();
+               cur.selection() = true; // to avoid deletion
+               cursorEnd(cur);
+               cur.setSelection();
+               // What is this test for ??? (JMarc)
+               if (!cur.selection())
+                       text_->deleteWordForward(cur);
+               else
+                       cap::cutSelection(cur, true, false);
+               checkBufferStructure(cur.buffer(), cur);
+       }
+}
+
+
+bool TextMetrics::isLastRow(pit_type pit, Row const & row) const
+{
+       ParagraphList const & pars = text_->paragraphs();
+       return row.endpos() >= pars[pit].size()
+               && pit + 1 == pit_type(pars.size());
+}
+
+
+bool TextMetrics::isFirstRow(pit_type pit, Row const & row) const
+{
+       return row.pos() == 0 && pit == 0;
+}
+
+
 int TextMetrics::leftMargin(int max_width, pit_type pit) const
 {
        BOOST_ASSERT(pit >= 0);