mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
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
This commit is contained in:
parent
7150b25b7e
commit
502b048246
23
src/Text.cpp
23
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());
|
||||
|
17
src/Text.h
17
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
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user