From: Abdelrazak Younes Date: Sun, 2 Sep 2007 11:21:33 +0000 (+0000) Subject: Transfer metrics and screen related methods from Text to TextMetrics. X-Git-Tag: 1.6.10~8551 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=502b0482466e992ae0543193de7c72a5e8f28576;p=features.git Transfer metrics and screen related methods from Text to TextMetrics. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19994 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Text.cpp b/src/Text.cpp index a208017019..4013905d6d 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -810,7 +810,6 @@ void Text::rejectChanges(BufferParams const & bparams) } -// Delete from cursor up to the end of the current or next word. void Text::deleteWordForward(Cursor & cur) { BOOST_ASSERT(this == cur.text()); @@ -827,7 +826,6 @@ void Text::deleteWordForward(Cursor & cur) } -// Delete from cursor to start of current or prior word. void Text::deleteWordBackward(Cursor & cur) { BOOST_ASSERT(this == cur.text()); @@ -845,27 +843,6 @@ void Text::deleteWordBackward(Cursor & cur) // Kill to end of line. -void Text::deleteLineForward(Cursor & cur) -{ - BOOST_ASSERT(this == cur.text()); - if (cur.lastpos() == 0) { - // Paragraph is empty, so we just go to the right - cursorRight(cur); - } else { - cur.resetAnchor(); - cur.selection() = true; // to avoid deletion - cursorEnd(cur); - cur.setSelection(); - // What is this test for ??? (JMarc) - if (!cur.selection()) - deleteWordForward(cur); - else - cutSelection(cur, true, false); - checkBufferStructure(cur.buffer(), cur); - } -} - - void Text::changeCase(Cursor & cur, Text::TextCase action) { BOOST_ASSERT(this == cur.text()); diff --git a/src/Text.h b/src/Text.h index 88295d2ba6..f0d75fa8ef 100644 --- a/src/Text.h +++ b/src/Text.h @@ -191,17 +191,15 @@ public: bool cursorLeftOneWord(Cursor & cur); /// bool cursorRightOneWord(Cursor & cur); + /// Delete from cursor up to the end of the current or next word. + void deleteWordForward(Cursor & cur); + /// Delete from cursor to start of current or prior word. + void deleteWordBackward(Cursor & cur); /// bool cursorUpParagraph(Cursor & cur); /// bool cursorDownParagraph(Cursor & cur); /// - /// FIXME: move to TextMetrics. - bool cursorHome(Cursor & cur); - /// - /// FIXME: move to TextMetrics. - bool cursorEnd(Cursor & cur); - /// bool cursorTop(Cursor & cur); /// bool cursorBottom(Cursor & cur); @@ -331,13 +329,6 @@ private: bool backspacePos0(Cursor & cur); /// handle the case where bibitems were deleted bool handleBibitems(Cursor & cur); - - /// - void deleteWordForward(Cursor & cur); - /// - void deleteWordBackward(Cursor & cur); - /// - void deleteLineForward(Cursor & cur); /// void charInserted(); /// set 'number' font property diff --git a/src/Text2.cpp b/src/Text2.cpp index 375cb15ff4..9fb515e1b9 100644 --- a/src/Text2.cpp +++ b/src/Text2.cpp @@ -465,40 +465,6 @@ void Text::setFont(Buffer const & buffer, CursorSlice const & begin, } -// the cursor set functions have a special mechanism. When they -// realize you left an empty paragraph, they will delete it. - -bool Text::cursorHome(Cursor & cur) -{ - BOOST_ASSERT(this == cur.text()); - ParagraphMetrics const & pm = cur.bv().parMetrics(this, cur.pit()); - Row const & row = pm.getRow(cur.pos(),cur.boundary()); - return setCursor(cur, cur.pit(), row.pos()); -} - - -bool Text::cursorEnd(Cursor & cur) -{ - BOOST_ASSERT(this == 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 setCursor(cur, cur.pit(), end, true, boundary); -} - - bool Text::cursorTop(Cursor & cur) { BOOST_ASSERT(this == cur.text()); diff --git a/src/Text3.cpp b/src/Text3.cpp index 320e3b4387..05495d9d3e 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -398,7 +398,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) if (cur.selection()) { cutSelection(cur, true, false); } else - deleteLineForward(cur); + tm.deleteLineForward(cur); finishChange(cur, false); break; @@ -516,13 +516,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_LINE_BEGIN: case LFUN_LINE_BEGIN_SELECT: needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT); - needsUpdate |= cursorHome(cur); + needsUpdate |= tm.cursorHome(cur); break; case LFUN_LINE_END: case LFUN_LINE_END_SELECT: needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT); - needsUpdate |= cursorEnd(cur); + needsUpdate |= tm.cursorEnd(cur); break; case LFUN_WORD_FORWARD: @@ -959,9 +959,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_MOUSE_TRIPLE: if (cmd.button() == mouse_button::button1) { - cursorHome(cur); + tm.cursorHome(cur); cur.resetAnchor(); - cursorEnd(cur); + tm.cursorEnd(cur); cur.setSelection(); bv->cursor() = cur; } diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index e1c9c845b1..9bde046c8e 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -20,11 +20,13 @@ #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" @@ -1400,6 +1402,61 @@ 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); + } +} + + int TextMetrics::leftMargin(int max_width, pit_type pit) const { BOOST_ASSERT(pit >= 0); diff --git a/src/TextMetrics.h b/src/TextMetrics.h index 57cf9b3f12..784e91fc36 100644 --- a/src/TextMetrics.h +++ b/src/TextMetrics.h @@ -174,6 +174,12 @@ public: void cursorPrevious(Cursor & cur); /// void cursorNext(Cursor & cur); + /// + bool cursorHome(Cursor & cur); + /// + bool cursorEnd(Cursor & cur); + /// + void deleteLineForward(Cursor & cur); /// Returns an inset if inset was hit, or 0 if not. /// \warning This method is not recursive! It will return the