#include "buffer.h"
#include "bufferparams.h"
#include "BufferView.h"
+#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "encoding.h"
using lyx::support::lowercase;
using lyx::support::uppercase;
+using std::advance;
+using std::distance;
using std::max;
using std::endl;
using std::string;
{
LyXTextClass const & tclass = bv()->buffer()->params().getLyXTextClass();
- return
+ return
RIGHT_MARGIN
+ font_metrics::signedWidth(tclass.rightmargin(),
tclass.defaultfont())
// convenience function
void LyXText::redoParagraph()
{
- clearSelection();
+ bv()->cursor().clearSelection();
redoParagraph(cursorPar());
setCursorIntern(cursor().par(), cursor().pos());
}
// same Paragraph one to the right and make a rebreak
void LyXText::insertChar(char c)
{
- recordUndo(Undo::INSERT, this, cursor().par(), cursor().par());
+ recordUndo(bv()->cursor(), Undo::INSERT);
// When the free-spacing option is set for the current layout,
// disable the double-space checking
int const ns = numberOfSeparators(*pit, row);
bool disp_inset = false;
if (row.endpos() < pit->size()) {
- InsetOld * in = pit->getInset(row.endpos());
+ InsetBase * in = pit->getInset(row.endpos());
if (in)
disp_inset = in->display();
}
// of prior word, not to end of next prior word.
void LyXText::cursorLeftOneWord()
{
- LyXCursor tmpcursor = cursor();
+ CursorSlice tmpcursor = cursor();
cursorLeftOneWord(tmpcursor);
setCursor(getPar(tmpcursor), tmpcursor.pos());
}
void LyXText::selectWord(word_location loc)
{
- LyXCursor from = cursor();
- LyXCursor to = cursor();
+ CursorSlice from = cursor();
+ CursorSlice to = cursor();
getWord(from, to, loc);
if (cursor() != from)
setCursor(from.par(), from.pos());
if (to == from)
return;
- anchor() = cursor();
+ bv()->cursor().resetAnchor();
setCursor(to.par(), to.pos());
- setSelection();
+ bv()->cursor().setSelection();
}
// selection is currently set
bool LyXText::selectWordWhenUnderCursor(word_location loc)
{
- if (!selection.set()) {
- selectWord(loc);
- return selection.set();
- }
- return false;
+ if (bv()->cursor().selection())
+ return false;
+ selectWord(loc);
+ return bv()->cursor().selection();
}
void LyXText::acceptChange()
{
- if (!selection.set() && cursorPar()->size())
+ LCursor & cur = bv()->cursor();
+ if (!cur.selection() && cursorPar()->size())
return;
- if (selStart().par() == selEnd().par()) {
- LyXCursor const & startc = selStart();
- LyXCursor const & endc = selEnd();
- recordUndo(Undo::INSERT, this, startc.par());
+ if (cur.selBegin().par() == cur.par()) {
+ CursorSlice const & startc = cur.selBegin();
+ CursorSlice const & endc = cur.selEnd();
+ recordUndo(cur, Undo::INSERT, cur.anchor().par());
getPar(startc)->acceptChange(startc.pos(), endc.pos());
finishUndo();
- clearSelection();
+ cur.clearSelection();
redoParagraph(getPar(startc));
setCursorIntern(startc.par(), 0);
}
void LyXText::rejectChange()
{
- if (!selection.set() && cursorPar()->size())
+ LCursor & cur = bv()->cursor();
+ if (!cur.selection() && cursorPar()->size())
return;
- if (selStart().par() == selEnd().par()) {
- LyXCursor const & startc = selStart();
- LyXCursor const & endc = selEnd();
- recordUndo(Undo::INSERT, this, startc.par());
+ if (cur.selBegin().par() == cur.selEnd().par()) {
+ CursorSlice const & startc = cur.selBegin();
+ CursorSlice const & endc = cur.selEnd();
+ recordUndo(cur, Undo::INSERT, cur.anchor().par());
getPar(startc)->rejectChange(startc.pos(), endc.pos());
finishUndo();
- clearSelection();
+ cur.clearSelection();
redoParagraph(getPar(startc));
setCursorIntern(startc.par(), 0);
}
// Delete from cursor up to the end of the current or next word.
void LyXText::deleteWordForward()
{
+ LCursor & cur = bv()->cursor();
if (cursorPar()->empty())
- cursorRight(bv());
+ cursorRight(true);
else {
- LyXCursor tmpcursor = cursor();
- selection.set(true); // to avoid deletion
+ CursorSlice tmpcursor = cursor();
+ cur.selection() = true; // to avoid deletion
cursorRightOneWord();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
- anchor() = cursor();
+ cur.resetAnchor();
cursor() = tmpcursor;
- setSelection();
+ cur.setSelection();
cutSelection(true, false);
}
}
// Delete from cursor to start of current or prior word.
void LyXText::deleteWordBackward()
{
+ LCursor & cur = bv()->cursor();
if (cursorPar()->empty())
- cursorLeft(bv());
+ cursorLeft(true);
else {
- LyXCursor tmpcursor = cursor();
- selection.set(true); // to avoid deletion
+ CursorSlice tmpcursor = cursor();
+ cur.selection() = true; // to avoid deletion
cursorLeftOneWord();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
- anchor() = cursor();
+ cur.resetAnchor();
cursor() = tmpcursor;
- setSelection();
+ cur.setSelection();
cutSelection(true, false);
}
}
// Kill to end of line.
void LyXText::deleteLineForward()
{
+ LCursor & cur = bv()->cursor();
if (cursorPar()->empty()) {
// Paragraph is empty, so we just go to the right
- cursorRight(bv());
+ cursorRight(true);
} else {
- LyXCursor tmpcursor = cursor();
- selection.set(true); // to avoid deletion
+ CursorSlice tmpcursor = cursor();
+ cur.selection() = true; // to avoid deletion
cursorEnd();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
- anchor() = cursor();
+ cur.resetAnchor();
cursor() = tmpcursor;
- setSelection();
+ cur.setSelection();
// What is this test for ??? (JMarc)
- if (!selection.set())
+ if (!cur.selection())
deleteWordForward();
else
cutSelection(true, false);
void LyXText::changeCase(LyXText::TextCase action)
{
- LyXCursor from;
- LyXCursor to;
+ LCursor & cur = bv()->cursor();
+ CursorSlice from;
+ CursorSlice to;
- if (selection.set()) {
- from = selStart();
- to = selEnd();
+ if (cur.selection()) {
+ from = cur.selBegin();
+ to = cur.selEnd();
} else {
from = cursor();
getWord(from, to, lyx::PARTIAL_WORD);
setCursor(to.par(), to.pos() + 1);
}
- recordUndo(Undo::ATOMIC, this, from.par(), to.par());
+ recordUndo(cur, Undo::ATOMIC, cur.anchor().par());
pos_type pos = from.pos();
int par = from.par();
void LyXText::Delete()
{
// this is a very easy implementation
- LyXCursor old_cursor = cursor();
+ CursorSlice old_cursor = cursor();
// just move to the right
cursorRight(true);
// if you had success make a backspace
- if (old_cursor.par() != cursor().par() || old_cursor.pos() !=
-cursor().pos()) {
- recordUndo(Undo::DELETE, this, old_cursor.par());
+ if (old_cursor.par() != cursor().par()
+ || old_cursor.pos() != cursor().pos()) {
+ recordUndo(bv()->cursor(), Undo::DELETE, old_cursor.par());
backspace();
}
}
}
if (cursor().par() != 0)
- recordUndo(Undo::DELETE, this, cursor().par() - 1, cursor().par());
+ recordUndo(bv()->cursor(), Undo::DELETE, cursor().par() - 1);
ParagraphList::iterator tmppit = cursorPar();
// We used to do cursorLeftIntern() here, but it is
} else {
// this is the code for a normal backspace, not pasting
// any paragraphs
- recordUndo(Undo::DELETE, this, cursor().par());
+ recordUndo(bv()->cursor(), Undo::DELETE);
// We used to do cursorLeftIntern() here, but it is
// not a good idea since it triggers the auto-delete
// mechanism. So we do a cursorLeftIntern()-lite,
ParagraphList::iterator LyXText::cursorPar() const
{
+ //lyxerr << "### cursorPar: cursor: " << bv()->cursor() << endl;
+ //lyxerr << "xxx cursorPar: cursor: " << cursor() << endl;
return getPar(cursor().par());
}
}
-ParagraphList::iterator LyXText::getPar(LyXCursor const & cur) const
+ParagraphList::iterator LyXText::getPar(CursorSlice const & cur) const
{
return getPar(cur.par());
}
ParagraphList::iterator LyXText::getPar(int par) const
{
+ //lyxerr << "getPar: " << par << " from " << paragraphs().size() << endl;
BOOST_ASSERT(par >= 0);
BOOST_ASSERT(par < int(paragraphs().size()));
ParagraphList::iterator pit = paragraphs().begin();
- std::advance(pit, par);
+ advance(pit, par);
return pit;
}
RowList::iterator
LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const
{
- //lyxerr << "getRowNearY: y " << y << endl;
#if 1
ParagraphList::iterator const
pend = boost::prior(paragraphs().end());
}
-ParagraphList::iterator LyXText::firstPar() const
-{
- return paragraphs().begin();
-}
-
-
RowList::iterator LyXText::lastRow() const
{
return boost::prior(endRow());
}
-ParagraphList::iterator LyXText::lastPar() const
-{
- return boost::prior(endPar());
-}
-
-
RowList::iterator LyXText::endRow() const
{
return paragraphs().back().rows.end();
}
-ParagraphList::iterator LyXText::endPar() const
-{
- return paragraphs().end();
-}
-
-
void LyXText::nextRow(ParagraphList::iterator & pit,
RowList::iterator & rit) const
{
string LyXText::selectionAsString(Buffer const & buffer, bool label) const
{
- if (!selection.set())
+ LCursor & cur = bv()->cursor();
+ if (!cur.selection())
return string();
// should be const ...
- ParagraphList::iterator startpit = getPar(selStart());
- ParagraphList::iterator endpit = getPar(selEnd());
- size_t const startpos = selStart().pos();
- size_t const endpos = selEnd().pos();
+ ParagraphList::iterator startpit = getPar(cur.selBegin());
+ ParagraphList::iterator endpit = getPar(cur.selEnd());
+ size_t const startpos = cur.selBegin().pos();
+ size_t const endpos = cur.selEnd().pos();
if (startpit == endpit)
return startpit->asString(buffer, startpos, endpos, label);
int LyXText::parOffset(ParagraphList::iterator pit) const
{
- return std::distance(paragraphs().begin(), pit);
+ return distance(paragraphs().begin(), pit);
}
void LyXText::fullRebreak()
{
redoParagraphs(paragraphs().begin(), paragraphs().end());
- anchor() = cursor();
+ bv()->cursor().resetAnchor();
}
}
-void LyXText::cursorLeftOneWord(LyXCursor & cur)
+void LyXText::cursorLeftOneWord(CursorSlice & cur)
{
// treat HFills, floats and Insets as words
}
-void LyXText::cursorRightOneWord(LyXCursor & cur)
+void LyXText::cursorRightOneWord(CursorSlice & cur)
{
// treat floats, HFills and Insets as words
ParagraphList::iterator pit = cursorPar();
}
-void LyXText::getWord(LyXCursor & from, LyXCursor & to, word_location const loc)
+void LyXText::getWord(CursorSlice & from, CursorSlice & to, word_location const loc)
{
ParagraphList::iterator from_par = getPar(from);
- ParagraphList::iterator to_par = getPar(to);
switch (loc) {
case lyx::WHOLE_WORD_STRICT:
if (from.pos() == 0 || from.pos() == from_par->size()
break;
}
to = from;
+ ParagraphList::iterator to_par = getPar(to);
while (to.pos() < to_par->size()
&& !to_par->isSeparator(to.pos())
&& !to_par->isKomma(to.pos())
bool LyXText::read(Buffer const & buf, LyXLex & lex)
-{
+{
static Change current_change;
bool the_end_read = false;
}
-int LyXText::cursorX() const
-{
- return cursorX(cursor());
-}
-
-
-int LyXText::cursorY() const
-{
- return cursorY(cursor());
-}
-
-
-int LyXText::cursorX(LyXCursor const & cur) const
+int LyXText::cursorX(CursorSlice const & cur) const
{
ParagraphList::iterator pit = getPar(cur);
if (pit->rows.empty())
- return 0;
+ return xo_;
Row const & row = *pit->getRow(cur.pos());
pos_type pos = cur.pos();
pos_type cursor_vpos = 0;
} else
x += singleWidth(pit, pos);
}
- return int(x);
+ return xo_ + int(x);
}
-int LyXText::cursorY(LyXCursor const & cur) const
+int LyXText::cursorY(CursorSlice const & cur) const
{
Paragraph & par = *getPar(cur);
Row & row = *par.getRow(cur.pos());
- return par.y + row.y_offset() + row.baseline();
-}
-
-
-LyXCursor & LyXText::cursor()
-{
- return cursor_;
+ return yo_ + par.y + row.y_offset() + row.baseline();
}
-LyXCursor const & LyXText::cursor() const
+CursorSlice & LyXText::cursor()
{
- return cursor_;
-}
-
-
-LyXCursor & LyXText::anchor()
-{
- return anchor_;
+ //lyxerr << "# accessing slice " << findText(this) << endl;
+ if (this != bv()->cursor().text()) {
+ lyxerr << "cursor: " << bv()->cursor()
+ << "\ntext: " << bv()->cursor().text()
+ << "\nthis: " << this << endl;
+ BOOST_ASSERT(false);
+ }
+ return bv()->cursor().current();
}
-LyXCursor const & LyXText::anchor() const
+CursorSlice const & LyXText::cursor() const
{
- return anchor_;
+ if (this != bv()->cursor().text()) {
+ lyxerr << "cursor: " << bv()->cursor()
+ << "\ntext: " << bv()->cursor().text()
+ << "\nthis: " << this << endl;
+ BOOST_ASSERT(false);
+ }
+ return bv()->cursor().current();
}
-
-