hide cursor and selection anchor behind accessor function

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8333 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-01-13 10:37:38 +00:00
parent 80296aac50
commit 97901b5d51
17 changed files with 332 additions and 275 deletions

View File

@ -316,7 +316,7 @@ void BufferView::gotoLabel(string const & label)
text()->setCursor( text()->setCursor(
std::distance(text()->paragraphs().begin(), it.getPar()), std::distance(text()->paragraphs().begin(), it.getPar()),
it.getPos()); it.getPos());
text()->selection.cursor = text()->cursor; text()->anchor() = text()->cursor();
update(); update();
return; return;
} }
@ -418,7 +418,7 @@ Encoding const * BufferView::getEncoding() const
return 0; return 0;
return t->cursorPar()->getFont( return t->cursorPar()->getFont(
buffer()->params(), buffer()->params(),
t->cursor.pos(), t->cursor().pos(),
outerFont(t->cursorPar(), t->paragraphs()) outerFont(t->cursorPar(), t->paragraphs())
).language()->encoding(); ).language()->encoding();
} }

View File

@ -388,37 +388,38 @@ void BufferView::Pimpl::resizeCurrentBuffer()
owner_->message(_("Formatting document...")); owner_->message(_("Formatting document..."));
lyxerr << "### resizeCurrentBuffer: text " << bv_->text() << endl; LyXText * text = bv_->text();
if (!bv_->text()) lyxerr << "### resizeCurrentBuffer: text " << text << endl;
if (!text)
return; return;
par = bv_->text()->cursor.par(); par = text->cursor().par();
pos = bv_->text()->cursor.pos(); pos = text->cursor().pos();
selstartpar = bv_->text()->selStart().par(); selstartpar = text->selStart().par();
selstartpos = bv_->text()->selStart().pos(); selstartpos = text->selStart().pos();
selendpar = bv_->text()->selEnd().par(); selendpar = text->selEnd().par();
selendpos = bv_->text()->selEnd().pos(); selendpos = text->selEnd().pos();
selection = bv_->text()->selection.set(); selection = text->selection.set();
mark_set = bv_->text()->selection.mark(); mark_set = text->selection.mark();
bv_->text()->textwidth_ = bv_->workWidth(); text->textwidth_ = bv_->workWidth();
bv_->text()->fullRebreak(); text->fullRebreak();
update(); update();
if (par != -1) { if (par != -1) {
bv_->text()->selection.set(true); text->selection.set(true);
// At this point just to avoid the Delete-Empty-Paragraph- // At this point just to avoid the Delete-Empty-Paragraph-
// Mechanism when setting the cursor. // Mechanism when setting the cursor.
bv_->text()->selection.mark(mark_set); text->selection.mark(mark_set);
if (selection) { if (selection) {
bv_->text()->setCursor(selstartpar, selstartpos); text->setCursor(selstartpar, selstartpos);
bv_->text()->selection.cursor = bv_->text()->cursor; text->anchor() = text->cursor();
bv_->text()->setCursor(selendpar, selendpos); text->setCursor(selendpar, selendpos);
bv_->text()->setSelection(); text->setSelection();
bv_->text()->setCursor(par, pos); text->setCursor(par, pos);
} else { } else {
bv_->text()->setCursor(par, pos); text->setCursor(par, pos);
bv_->text()->selection.cursor = bv_->text()->cursor; text->anchor() = text->cursor();
bv_->text()->selection.set(false); text->selection.set(false);
} }
} }
@ -536,11 +537,11 @@ void BufferView::Pimpl::selectionRequested()
} }
if (!xsel_cache_.set || if (!xsel_cache_.set ||
text->cursor != xsel_cache_.cursor || text->cursor() != xsel_cache_.cursor ||
text->selection.cursor != xsel_cache_.selection_cursor) text->anchor() != xsel_cache_.anchor)
{ {
xsel_cache_.cursor = text->cursor; xsel_cache_.cursor = text->cursor();
xsel_cache_.selection_cursor = text->selection.cursor; xsel_cache_.anchor = text->anchor();
xsel_cache_.set = text->selection.set(); xsel_cache_.set = text->selection.set();
sel = text->selectionAsString(*bv_->buffer(), false); sel = text->selectionAsString(*bv_->buffer(), false);
if (!sel.empty()) if (!sel.empty())
@ -647,7 +648,7 @@ void BufferView::Pimpl::savePosition(unsigned int i)
return; return;
saved_positions[i] = Position(buffer_->fileName(), saved_positions[i] = Position(buffer_->fileName(),
bv_->text()->cursorPar()->id(), bv_->text()->cursorPar()->id(),
bv_->text()->cursor.pos()); bv_->text()->cursor().pos());
if (i > 0) if (i > 0)
owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i))); owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i)));
} }
@ -741,7 +742,7 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
LyXCursor cursor = bv_->getLyXText()->cursor; LyXCursor cursor = bv_->getLyXText()->cursor;
Buffer::inset_iterator it = Buffer::inset_iterator it =
find_if(Buffer::inset_iterator( find_if(Buffer::inset_iterator(
cursorPar(), cursor.pos()), cursorPar(), cursor().pos()),
buffer_->inset_iterator_end(), buffer_->inset_iterator_end(),
lyx::compare_memfun(&Inset::lyxCode, code)); lyx::compare_memfun(&Inset::lyxCode, code));
return it != buffer_->inset_iterator_end() ? (*it) : 0; return it != buffer_->inset_iterator_end() ? (*it) : 0;
@ -763,7 +764,7 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
} }
if (cursor_par_seen) { if (cursor_par_seen) {
if (beg.getPar() == text->cursorPar() if (beg.getPar() == text->cursorPar()
&& beg.getPos() >= text->cursor.pos()) { && beg.getPos() >= text->cursor().pos()) {
break; break;
} else if (beg.getPar() != text->cursorPar()) { } else if (beg.getPar() != text->cursorPar()) {
break; break;
@ -1256,7 +1257,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
{ {
// not quite sure if we want this... // not quite sure if we want this...
bv_->text()->recUndo(bv_->text()->cursor.par()); bv_->text()->recUndo(bv_->text()->cursor().par());
freezeUndo(); freezeUndo();
bv_->text()->clearSelection(); bv_->text()->clearSelection();
@ -1285,10 +1286,7 @@ bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code,
string const & from, string const & to) string const & from, string const & to)
{ {
bool need_update = false; bool need_update = false;
LyXCursor cursor = bv_->text()->cursor; LyXCursor cur = bv_->text()->cursor();
LyXCursor tmpcursor = cursor;
cursor.par(tmpcursor.par());
cursor.pos(tmpcursor.pos());
ParIterator end = bv_->buffer()->par_iterator_end(); ParIterator end = bv_->buffer()->par_iterator_end();
for (ParIterator it = bv_->buffer()->par_iterator_begin(); for (ParIterator it = bv_->buffer()->par_iterator_begin();
@ -1317,7 +1315,7 @@ bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code,
} }
} }
} }
bv_->text()->setCursorIntern(cursor.par(), cursor.pos()); bv_->text()->setCursorIntern(cur.par(), cur.pos());
return need_update; return need_update;
} }

View File

@ -196,7 +196,7 @@ private:
/// this is used to handle XSelection events in the right manner /// this is used to handle XSelection events in the right manner
struct { struct {
LyXCursor cursor; LyXCursor cursor;
LyXCursor selection_cursor; LyXCursor anchor;
bool set; bool set;
} xsel_cache_; } xsel_cache_;
/// ///

View File

@ -1,3 +1,21 @@
2004-01-13 André Pönitz <poenitz@gmx.net>
* textcursor.[Ch]:
* lyxtext.h: hide cursor and selection anchor behind accessor function
* BufferView.C:
* BufferView_pimpl.[Ch]:
* PosIterator.C:
* bufferview_funcs.C:
* cursor.h:
* lyxfind.C:
* lyxfunc.C:
* text.C:
* text2.C:
* text3.C:
* undo.C: adjust
2004-01-08 Alfredo Braunstein <abraunst@lyx.org> 2004-01-08 Alfredo Braunstein <abraunst@lyx.org>
* text2.C (undoSpan): add and use * text2.C (undoSpan): add and use

View File

@ -128,7 +128,7 @@ PosIterator::PosIterator(ParagraphList * pl, ParagraphList::iterator pit,
PosIterator::PosIterator(BufferView & bv) PosIterator::PosIterator(BufferView & bv)
{ {
LyXText * text = bv.getLyXText(); LyXText * text = bv.getLyXText();
lyx::pos_type pos = text->cursor.pos(); lyx::pos_type pos = text->cursor().pos();
ParagraphList::iterator pit = text->cursorPar(); ParagraphList::iterator pit = text->cursorPar();
ParIterator par = bv.buffer()->par_iterator_begin(); ParIterator par = bv.buffer()->par_iterator_begin();

View File

@ -179,10 +179,10 @@ string const currentState(BufferView * bv)
LyXText * text = bv->getLyXText(); LyXText * text = bv->getLyXText();
Buffer * buffer = bv->buffer(); Buffer * buffer = bv->buffer();
LyXCursor const & c = text->cursor; LyXCursor const & c = text->cursor();
bool const show_change = buffer->params().tracking_changes bool const show_change = buffer->params().tracking_changes
&& text->cursor.pos() != text->cursorPar()->size() && text->cursor().pos() != text->cursorPar()->size()
&& text->cursorPar()->lookupChange(c.pos()) != Change::UNCHANGED; && text->cursorPar()->lookupChange(c.pos()) != Change::UNCHANGED;
if (show_change) { if (show_change) {
@ -242,8 +242,8 @@ string const currentState(BufferView * bv)
#ifdef DEVEL_VERSION #ifdef DEVEL_VERSION
ParagraphList::iterator pit = text->cursorPar(); ParagraphList::iterator pit = text->cursorPar();
state << _(", Paragraph: ") << pit->id(); state << _(", Paragraph: ") << pit->id();
state << _(", Position: ") << text->cursor.pos(); state << _(", Position: ") << text->cursor().pos();
RowList::iterator rit = pit->getRow(text->cursor.pos()); RowList::iterator rit = pit->getRow(text->cursor().pos());
state << bformat(_(", Row b:%1$d e:%2$d"), rit->pos(), rit->endpos()); state << bformat(_(", Row b:%1$d e:%2$d"), rit->pos(), rit->endpos());
state << _(", Inset: "); state << _(", Inset: ");
InsetOld * inset = pit->inInset(); InsetOld * inset = pit->inInset();
@ -301,7 +301,7 @@ void put_selection_at(BufferView * bv, PosIterator const & cur,
text->setSelectionRange(length); text->setSelectionRange(length);
text->setSelection(); text->setSelection();
if (backwards) if (backwards)
std::swap(text->cursor, text->selection.cursor); std::swap(text->cursor(), text->anchor());
} }
bv->fitCursor(); bv->fitCursor();

View File

@ -45,6 +45,11 @@ public:
void pop(int depth); void pop(int depth);
/// pop one level off the cursor /// pop one level off the cursor
void pop(); void pop();
/// access to cursor 'tip'
CursorSlice & top() { return data_.back(); }
/// access to cursor 'tip'
CursorSlice const & top() const { return data_.back(); }
/// set the cell the cursor is in /// set the cell the cursor is in
void cell(int); void cell(int);
/// return the cell this cursor is in /// return the cell this cursor is in

View File

@ -236,14 +236,14 @@ void InsetText::updateLocal(BufferView * bv)
collapseParagraphs(bv); collapseParagraphs(bv);
if (!text_.selection.set()) if (!text_.selection.set())
text_.selection.cursor = text_.cursor; text_.anchor() = text_.cursor();
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
bv->owner()->updateMenubar(); bv->owner()->updateMenubar();
bv->owner()->updateToolbar(); bv->owner()->updateToolbar();
if (old_par != text_.cursor.par()) { if (old_par != text_.cursor().par()) {
bv->owner()->setLayout(text_.cursorPar()->layout()->name()); bv->owner()->setLayout(text_.cursorPar()->layout()->name());
old_par = text_.cursor.par(); old_par = text_.cursor().par();
} }
} }

View File

@ -394,7 +394,7 @@ int replace(BufferView * bv,
text->replaceSelectionWithString(replacestr); text->replaceSelectionWithString(replacestr);
text->setSelectionRange(replacestr.length()); text->setSelectionRange(replacestr.length());
text->cursor = fw ? text->selEnd() : text->selStart(); text->cursor() = fw ? text->selEnd() : text->selStart();
bv->buffer()->markDirty(); bv->buffer()->markDirty();
find(bv, searchstr, cs, mw, fw); find(bv, searchstr, cs, mw, fw);

View File

@ -158,7 +158,7 @@ void LyXFunc::handleKeyFunc(kb_action action)
keyseq.clear(); keyseq.clear();
// copied verbatim from do_accent_char // copied verbatim from do_accent_char
view()->update(); view()->update();
view()->getLyXText()->selection.cursor = view()->getLyXText()->cursor; view()->getLyXText()->anchor() = view()->getLyXText()->cursor();
} }

View File

@ -406,6 +406,16 @@ public:
/// ///
int cursorY(LyXCursor const & cursor) const; int cursorY(LyXCursor const & cursor) const;
/// the topmost cursor slice
LyXCursor & cursor();
/// the topmost cursor slice
LyXCursor const & cursor() const;
/// access to the selection anchor
LyXCursor & anchor();
/// access to the selection anchor
LyXCursor const & anchor() const;
public: public:
/// ///
int height; int height;

View File

@ -753,8 +753,8 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
{ {
// allow only if at start or end, or all previous is new text // allow only if at start or end, or all previous is new text
ParagraphList::iterator cpit = cursorPar(); ParagraphList::iterator cpit = cursorPar();
if (cursor.pos() && cursor.pos() != cpit->size() if (cursor().pos() && cursor().pos() != cpit->size()
&& cpit->isChangeEdited(0, cursor.pos())) && cpit->isChangeEdited(0, cursor().pos()))
return; return;
LyXTextClass const & tclass = LyXTextClass const & tclass =
@ -768,12 +768,12 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
return; return;
// a layout change may affect also the following paragraph // a layout change may affect also the following paragraph
recUndo(cursor.par(), parOffset(undoSpan(cpit)) - 1); recUndo(cursor().par(), parOffset(undoSpan(cpit)) - 1);
// Always break behind a space // Always break behind a space
// It is better to erase the space (Dekel) // It is better to erase the space (Dekel)
if (cursor.pos() < cpit->size() && cpit->isLineSeparator(cursor.pos())) if (cursor().pos() < cpit->size() && cpit->isLineSeparator(cursor().pos()))
cpit->erase(cursor.pos()); cpit->erase(cursor().pos());
// break the paragraph // break the paragraph
if (keep_layout) if (keep_layout)
@ -787,14 +787,14 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
// but we can fix this in 1.3.0 (Jug 20020509) // but we can fix this in 1.3.0 (Jug 20020509)
bool const isempty = cpit->allowEmpty() && cpit->empty(); bool const isempty = cpit->allowEmpty() && cpit->empty();
::breakParagraph(bv()->buffer()->params(), paragraphs, cpit, ::breakParagraph(bv()->buffer()->params(), paragraphs, cpit,
cursor.pos(), keep_layout); cursor().pos(), keep_layout);
cpit = cursorPar(); cpit = cursorPar();
ParagraphList::iterator next_par = boost::next(cpit); ParagraphList::iterator next_par = boost::next(cpit);
// well this is the caption hack since one caption is really enough // well this is the caption hack since one caption is really enough
if (layout->labeltype == LABEL_SENSITIVE) { if (layout->labeltype == LABEL_SENSITIVE) {
if (!cursor.pos()) if (!cursor().pos())
// set to standard-layout // set to standard-layout
cpit->applyLayout(tclass.defaultLayout()); cpit->applyLayout(tclass.defaultLayout());
else else
@ -806,9 +806,9 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
// move one row up! // move one row up!
// This touches only the screen-update. Otherwise we would may have // This touches only the screen-update. Otherwise we would may have
// an empty row on the screen // an empty row on the screen
RowList::iterator crit = cpit->getRow(cursor.pos()); RowList::iterator crit = cpit->getRow(cursor().pos());
if (cursor.pos() && crit->pos() == cursor.pos() if (cursor().pos() && crit->pos() == cursor().pos()
&& !cpit->isNewline(cursor.pos() - 1)) && !cpit->isNewline(cursor().pos() - 1))
{ {
cursorLeft(bv()); cursorLeft(bv());
} }
@ -822,7 +822,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
// This check is necessary. Otherwise the new empty paragraph will // This check is necessary. Otherwise the new empty paragraph will
// be deleted automatically. And it is more friendly for the user! // be deleted automatically. And it is more friendly for the user!
if (cursor.pos() || isempty) if (cursor().pos() || isempty)
setCursor(next_par, 0); setCursor(next_par, 0);
else else
setCursor(cpit, 0); setCursor(cpit, 0);
@ -834,7 +834,7 @@ void LyXText::redoParagraph()
{ {
clearSelection(); clearSelection();
redoParagraph(cursorPar()); redoParagraph(cursorPar());
setCursorIntern(cursor.par(), cursor.pos()); setCursorIntern(cursor().par(), cursor().pos());
} }
@ -842,7 +842,7 @@ void LyXText::redoParagraph()
// same Paragraph one to the right and make a rebreak // same Paragraph one to the right and make a rebreak
void LyXText::insertChar(char c) void LyXText::insertChar(char c)
{ {
recordUndo(Undo::INSERT, this, cursor.par(), cursor.par()); recordUndo(Undo::INSERT, this, cursor().par(), cursor().par());
// When the free-spacing option is set for the current layout, // When the free-spacing option is set for the current layout,
// disable the double-space checking // disable the double-space checking
@ -858,35 +858,35 @@ void LyXText::insertChar(char c)
if (current_font.number() == LyXFont::ON) { if (current_font.number() == LyXFont::ON) {
if (!IsDigit(c) && !contains(number_operators, c) && if (!IsDigit(c) && !contains(number_operators, c) &&
!(contains(number_seperators, c) && !(contains(number_seperators, c) &&
cursor.pos() >= 1 && cursor().pos() >= 1 &&
cursor.pos() < cursorPar()->size() && cursor().pos() < cursorPar()->size() &&
getFont(cursorPar(), cursor.pos()).number() == LyXFont::ON && getFont(cursorPar(), cursor().pos()).number() == LyXFont::ON &&
getFont(cursorPar(), cursor.pos() - 1).number() == LyXFont::ON) getFont(cursorPar(), cursor().pos() - 1).number() == LyXFont::ON)
) )
number(); // Set current_font.number to OFF number(); // Set current_font.number to OFF
} else if (IsDigit(c) && } else if (IsDigit(c) &&
real_current_font.isVisibleRightToLeft()) { real_current_font.isVisibleRightToLeft()) {
number(); // Set current_font.number to ON number(); // Set current_font.number to ON
if (cursor.pos() > 0) { if (cursor().pos() > 0) {
char const c = cursorPar()->getChar(cursor.pos() - 1); char const c = cursorPar()->getChar(cursor().pos() - 1);
if (contains(number_unary_operators, c) && if (contains(number_unary_operators, c) &&
(cursor.pos() == 1 || (cursor().pos() == 1 ||
cursorPar()->isSeparator(cursor.pos() - 2) || cursorPar()->isSeparator(cursor().pos() - 2) ||
cursorPar()->isNewline(cursor.pos() - 2)) cursorPar()->isNewline(cursor().pos() - 2))
) { ) {
setCharFont( setCharFont(
cursorPar(), cursorPar(),
cursor.pos() - 1, cursor().pos() - 1,
current_font); current_font);
} else if (contains(number_seperators, c) && } else if (contains(number_seperators, c) &&
cursor.pos() >= 2 && cursor().pos() >= 2 &&
getFont( getFont(
cursorPar(), cursorPar(),
cursor.pos() - 2).number() == LyXFont::ON) { cursor().pos() - 2).number() == LyXFont::ON) {
setCharFont( setCharFont(
cursorPar(), cursorPar(),
cursor.pos() - 1, cursor().pos() - 1,
current_font); current_font);
} }
} }
@ -910,14 +910,14 @@ void LyXText::insertChar(char c)
LyXFont rawtmpfont = current_font; LyXFont rawtmpfont = current_font;
if (!freeSpacing && IsLineSeparatorChar(c)) { if (!freeSpacing && IsLineSeparatorChar(c)) {
if ((cursor.pos() > 0 if ((cursor().pos() > 0
&& cursorPar()->isLineSeparator(cursor.pos() - 1)) && cursorPar()->isLineSeparator(cursor().pos() - 1))
|| (cursor.pos() > 0 || (cursor().pos() > 0
&& cursorPar()->isNewline(cursor.pos() - 1)) && cursorPar()->isNewline(cursor().pos() - 1))
|| (cursor.pos() == 0)) { || (cursor().pos() == 0)) {
static bool sent_space_message = false; static bool sent_space_message = false;
if (!sent_space_message) { if (!sent_space_message) {
if (cursor.pos() == 0) if (cursor().pos() == 0)
bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial.")); bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
else else
bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial.")); bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
@ -930,14 +930,14 @@ void LyXText::insertChar(char c)
// Here case LyXText::InsertInset already inserted the character // Here case LyXText::InsertInset already inserted the character
if (c != Paragraph::META_INSET) if (c != Paragraph::META_INSET)
cursorPar()->insertChar(cursor.pos(), c); cursorPar()->insertChar(cursor().pos(), c);
setCharFont(cursorPar(), cursor.pos(), rawtmpfont); setCharFont(cursorPar(), cursor().pos(), rawtmpfont);
current_font = rawtmpfont; current_font = rawtmpfont;
real_current_font = realtmpfont; real_current_font = realtmpfont;
redoParagraph(cursorPar()); redoParagraph(cursorPar());
setCursor(cursor.par(), cursor.pos() + 1, false, cursor.boundary()); setCursor(cursor().par(), cursor().pos() + 1, false, cursor().boundary());
charInserted(); charInserted();
} }
@ -1079,8 +1079,8 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
void LyXText::cursorRightOneWord() void LyXText::cursorRightOneWord()
{ {
cursorRightOneWord(cursor); cursorRightOneWord(cursor());
setCursor(cursorPar(), cursor.pos()); setCursor(cursorPar(), cursor().pos());
} }
@ -1088,7 +1088,7 @@ void LyXText::cursorRightOneWord()
// of prior word, not to end of next prior word. // of prior word, not to end of next prior word.
void LyXText::cursorLeftOneWord() void LyXText::cursorLeftOneWord()
{ {
LyXCursor tmpcursor = cursor; LyXCursor tmpcursor = cursor();
cursorLeftOneWord(tmpcursor); cursorLeftOneWord(tmpcursor);
setCursor(getPar(tmpcursor), tmpcursor.pos()); setCursor(getPar(tmpcursor), tmpcursor.pos());
} }
@ -1096,14 +1096,14 @@ void LyXText::cursorLeftOneWord()
void LyXText::selectWord(word_location loc) void LyXText::selectWord(word_location loc)
{ {
LyXCursor from = cursor; LyXCursor from = cursor();
LyXCursor to = cursor; LyXCursor to = cursor();
getWord(from, to, loc); getWord(from, to, loc);
if (cursor != from) if (cursor() != from)
setCursor(from.par(), from.pos()); setCursor(from.par(), from.pos());
if (to == from) if (to == from)
return; return;
selection.cursor = cursor; anchor() = cursor();
setCursor(to.par(), to.pos()); setCursor(to.par(), to.pos());
setSelection(); setSelection();
} }
@ -1165,12 +1165,12 @@ void LyXText::deleteWordForward()
if (cursorPar()->empty()) if (cursorPar()->empty())
cursorRight(bv()); cursorRight(bv());
else { else {
LyXCursor tmpcursor = cursor; LyXCursor tmpcursor = cursor();
selection.set(true); // to avoid deletion selection.set(true); // to avoid deletion
cursorRightOneWord(); cursorRightOneWord();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos()); setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
selection.cursor = cursor; anchor() = cursor();
cursor = tmpcursor; cursor() = tmpcursor;
setSelection(); setSelection();
cutSelection(true, false); cutSelection(true, false);
} }
@ -1183,12 +1183,12 @@ void LyXText::deleteWordBackward()
if (cursorPar()->empty()) if (cursorPar()->empty())
cursorLeft(bv()); cursorLeft(bv());
else { else {
LyXCursor tmpcursor = cursor; LyXCursor tmpcursor = cursor();
selection.set(true); // to avoid deletion selection.set(true); // to avoid deletion
cursorLeftOneWord(); cursorLeftOneWord();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos()); setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
selection.cursor = cursor; anchor() = cursor();
cursor = tmpcursor; cursor() = tmpcursor;
setSelection(); setSelection();
cutSelection(true, false); cutSelection(true, false);
} }
@ -1202,12 +1202,12 @@ void LyXText::deleteLineForward()
// Paragraph is empty, so we just go to the right // Paragraph is empty, so we just go to the right
cursorRight(bv()); cursorRight(bv());
} else { } else {
LyXCursor tmpcursor = cursor; LyXCursor tmpcursor = cursor();
selection.set(true); // to avoid deletion selection.set(true); // to avoid deletion
cursorEnd(); cursorEnd();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos()); setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
selection.cursor = cursor; anchor() = cursor();
cursor = tmpcursor; cursor() = tmpcursor;
setSelection(); setSelection();
// What is this test for ??? (JMarc) // What is this test for ??? (JMarc)
if (!selection.set()) if (!selection.set())
@ -1227,7 +1227,7 @@ void LyXText::changeCase(LyXText::TextCase action)
from = selStart(); from = selStart();
to = selEnd(); to = selEnd();
} else { } else {
from = cursor; from = cursor();
getWord(from, to, lyx::PARTIAL_WORD); getWord(from, to, lyx::PARTIAL_WORD);
setCursor(to.par(), to.pos() + 1); setCursor(to.par(), to.pos() + 1);
} }
@ -1270,13 +1270,14 @@ void LyXText::changeCase(LyXText::TextCase action)
void LyXText::Delete() void LyXText::Delete()
{ {
// this is a very easy implementation // this is a very easy implementation
LyXCursor old_cursor = cursor; LyXCursor old_cursor = cursor();
// just move to the right // just move to the right
cursorRight(true); cursorRight(true);
// if you had success make a backspace // if you had success make a backspace
if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) { if (old_cursor.par() != cursor().par() || old_cursor.pos() !=
cursor().pos()) {
recordUndo(Undo::DELETE, this, old_cursor.par()); recordUndo(Undo::DELETE, this, old_cursor.par());
backspace(); backspace();
} }
@ -1289,7 +1290,7 @@ void LyXText::backspace()
ParagraphList::iterator pit = cursorPar(); ParagraphList::iterator pit = cursorPar();
pos_type lastpos = pit->size(); pos_type lastpos = pit->size();
if (cursor.pos() == 0) { if (cursor().pos() == 0) {
// The cursor is at the beginning of a paragraph, so // The cursor is at the beginning of a paragraph, so
// the the backspace will collapse two paragraphs into // the the backspace will collapse two paragraphs into
// one. // one.
@ -1307,7 +1308,7 @@ void LyXText::backspace()
// left and let the DeleteEmptyParagraphMechanism // left and let the DeleteEmptyParagraphMechanism
// handle the actual deletion of the paragraph. // handle the actual deletion of the paragraph.
if (cursor.par()) { if (cursor().par()) {
cursorLeft(bv()); cursorLeft(bv());
// the layout things can change the height of a row ! // the layout things can change the height of a row !
redoParagraph(); redoParagraph();
@ -1315,18 +1316,18 @@ void LyXText::backspace()
} }
} }
if (cursor.par() != 0) if (cursor().par() != 0)
recordUndo(Undo::DELETE, this, cursor.par() - 1, cursor.par()); recordUndo(Undo::DELETE, this, cursor().par() - 1, cursor().par());
ParagraphList::iterator tmppit = cursorPar(); ParagraphList::iterator tmppit = cursorPar();
// We used to do cursorLeftIntern() here, but it is // We used to do cursorLeftIntern() here, but it is
// not a good idea since it triggers the auto-delete // not a good idea since it triggers the auto-delete
// mechanism. So we do a cursorLeftIntern()-lite, // mechanism. So we do a cursorLeftIntern()-lite,
// without the dreaded mechanism. (JMarc) // without the dreaded mechanism. (JMarc)
if (cursor.par() != 0) { if (cursor().par() != 0) {
// steps into the above paragraph. // steps into the above paragraph.
setCursorIntern(cursor.par() - 1, setCursorIntern(cursor().par() - 1,
getPar(cursor.par() - 1)->size(), getPar(cursor().par() - 1)->size(),
false); false);
} }
@ -1345,44 +1346,44 @@ void LyXText::backspace()
&& cpit->getAlign() == tmppit->getAlign()) { && cpit->getAlign() == tmppit->getAlign()) {
mergeParagraph(bufparams, buf.paragraphs(), cpit); mergeParagraph(bufparams, buf.paragraphs(), cpit);
if (cursor.pos() && cpit->isSeparator(cursor.pos() - 1)) if (cursor().pos() && cpit->isSeparator(cursor().pos() - 1))
cursor.pos(cursor.pos() - 1); cursor().pos(cursor().pos() - 1);
// the counters may have changed // the counters may have changed
updateCounters(); updateCounters();
setCursor(cursor.par(), cursor.pos(), false); setCursor(cursor().par(), cursor().pos(), false);
} }
} else { } else {
// this is the code for a normal backspace, not pasting // this is the code for a normal backspace, not pasting
// any paragraphs // any paragraphs
recordUndo(Undo::DELETE, this, cursor.par()); recordUndo(Undo::DELETE, this, cursor().par());
// We used to do cursorLeftIntern() here, but it is // We used to do cursorLeftIntern() here, but it is
// not a good idea since it triggers the auto-delete // not a good idea since it triggers the auto-delete
// mechanism. So we do a cursorLeftIntern()-lite, // mechanism. So we do a cursorLeftIntern()-lite,
// without the dreaded mechanism. (JMarc) // without the dreaded mechanism. (JMarc)
setCursorIntern(cursor.par(), cursor.pos() - 1, setCursorIntern(cursor().par(), cursor().pos() - 1,
false, cursor.boundary()); false, cursor().boundary());
cursorPar()->erase(cursor.pos()); cursorPar()->erase(cursor().pos());
} }
lastpos = cursorPar()->size(); lastpos = cursorPar()->size();
if (cursor.pos() == lastpos) if (cursor().pos() == lastpos)
setCurrentFont(); setCurrentFont();
redoParagraph(); redoParagraph();
setCursor(cursor.par(), cursor.pos(), false, cursor.boundary()); setCursor(cursor().par(), cursor().pos(), false, cursor().boundary());
} }
ParagraphList::iterator LyXText::cursorPar() const ParagraphList::iterator LyXText::cursorPar() const
{ {
return getPar(cursor.par()); return getPar(cursor().par());
} }
RowList::iterator LyXText::cursorRow() const RowList::iterator LyXText::cursorRow() const
{ {
return cursorPar()->getRow(cursor.pos()); return cursorPar()->getRow(cursor().pos());
} }
@ -1599,7 +1600,7 @@ void LyXText::redoParagraph(ParagraphList::iterator pit)
void LyXText::fullRebreak() void LyXText::fullRebreak()
{ {
redoParagraphs(paragraphs().begin(), paragraphs().end()); redoParagraphs(paragraphs().begin(), paragraphs().end());
selection.cursor = cursor; anchor() = cursor();
} }
@ -1645,12 +1646,12 @@ bool LyXText::isFirstRow(ParagraphList::iterator pit, Row const & row) const
} }
void LyXText::cursorLeftOneWord(LyXCursor & cursor) void LyXText::cursorLeftOneWord(LyXCursor & cur)
{ {
// treat HFills, floats and Insets as words // treat HFills, floats and Insets as words
ParagraphList::iterator pit = cursorPar(); ParagraphList::iterator pit = cursorPar();
size_t pos = cursor.pos(); size_t pos = cur.pos();
while (pos && while (pos &&
(pit->isSeparator(pos - 1) || (pit->isSeparator(pos - 1) ||
@ -1674,16 +1675,16 @@ void LyXText::cursorLeftOneWord(LyXCursor & cursor)
--pos; --pos;
} }
cursor.par(parOffset(pit)); cur.par(parOffset(pit));
cursor.pos(pos); cur.pos(pos);
} }
void LyXText::cursorRightOneWord(LyXCursor & cursor) void LyXText::cursorRightOneWord(LyXCursor & cur)
{ {
// treat floats, HFills and Insets as words // treat floats, HFills and Insets as words
ParagraphList::iterator pit = cursorPar(); ParagraphList::iterator pit = cursorPar();
pos_type pos = cursor.pos(); pos_type pos = cur.pos();
if (pos == pit->size() && if (pos == pit->size() &&
boost::next(pit) != paragraphs().end()) { boost::next(pit) != paragraphs().end()) {
@ -1700,8 +1701,8 @@ void LyXText::cursorRightOneWord(LyXCursor & cursor)
} }
} }
cursor.par(parOffset(pit)); cur.par(parOffset(pit));
cursor.pos(pos); cur.pos(pos);
} }
@ -1854,13 +1855,13 @@ int LyXText::descent() const
int LyXText::cursorX() const int LyXText::cursorX() const
{ {
return cursorX(cursor); return cursorX(cursor());
} }
int LyXText::cursorY() const int LyXText::cursorY() const
{ {
return cursorY(cursor); return cursorY(cursor());
} }
@ -1932,3 +1933,28 @@ int LyXText::cursorY(LyXCursor const & cur) const
return par.y + row.y_offset() + row.baseline(); return par.y + row.y_offset() + row.baseline();
} }
LyXCursor & LyXText::cursor()
{
return cursor_;
}
LyXCursor const & LyXText::cursor() const
{
return cursor_;
}
LyXCursor & LyXText::anchor()
{
return anchor_;
}
LyXCursor const & LyXText::anchor() const
{
return anchor_;
}

View File

@ -95,7 +95,7 @@ void LyXText::init(BufferView * bview)
redoParagraphs(beg, end); redoParagraphs(beg, end);
setCursorIntern(0, 0); setCursorIntern(0, 0);
selection.cursor = cursor; anchor() = cursor();
updateCounters(); updateCounters();
} }
@ -217,7 +217,7 @@ void LyXText::setCharFont(
InsetOld * LyXText::getInset() const InsetOld * LyXText::getInset() const
{ {
ParagraphList::iterator pit = cursorPar(); ParagraphList::iterator pit = cursorPar();
pos_type const pos = cursor.pos(); pos_type const pos = cursor().pos();
if (pos < pit->size() && pit->isInset(pos)) { if (pos < pit->size() && pit->isInset(pos)) {
return pit->getInset(pos); return pit->getInset(pos);
@ -236,7 +236,7 @@ bool LyXText::toggleInset()
// do we want to keep this?? (JMarc) // do we want to keep this?? (JMarc)
if (!isHighlyEditableInset(inset)) if (!isHighlyEditableInset(inset))
recUndo(cursor.par()); recUndo(cursor().par());
if (inset->isOpen()) if (inset->isOpen())
inset->close(); inset->close();
@ -428,7 +428,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
if (!selection.set()) { if (!selection.set()) {
// Determine basis font // Determine basis font
LyXFont layoutfont; LyXFont layoutfont;
if (cursor.pos() < cursorPar()->beginOfBody()) if (cursor().pos() < cursorPar()->beginOfBody())
layoutfont = getLabelFont(cursorPar()); layoutfont = getLabelFont(cursorPar());
else else
layoutfont = getLayoutFont(cursorPar()); layoutfont = getLayoutFont(cursorPar());
@ -497,14 +497,14 @@ void LyXText::clearSelection()
void LyXText::cursorHome() void LyXText::cursorHome()
{ {
ParagraphList::iterator cpit = cursorPar(); ParagraphList::iterator cpit = cursorPar();
setCursor(cpit, cpit->getRow(cursor.pos())->pos()); setCursor(cpit, cpit->getRow(cursor().pos())->pos());
} }
void LyXText::cursorEnd() void LyXText::cursorEnd()
{ {
ParagraphList::iterator cpit = cursorPar(); ParagraphList::iterator cpit = cursorPar();
pos_type end = cpit->getRow(cursor.pos())->endpos(); pos_type end = cpit->getRow(cursor().pos())->endpos();
// if not on the last row of the par, put the cursor before // if not on the last row of the par, put the cursor before
// the final space // the final space
setCursor(cpit, end == cpit->size() ? end : end - 1); setCursor(cpit, end == cpit->size() ? end : end - 1);
@ -538,7 +538,7 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
// Try implicit word selection // Try implicit word selection
// If there is a change in the language the implicit word selection // If there is a change in the language the implicit word selection
// is disabled. // is disabled.
LyXCursor resetCursor = cursor; LyXCursor resetCursor = cursor();
bool implicitSelection = bool implicitSelection =
font.language() == ignore_language font.language() == ignore_language
&& font.number() == LyXFont::IGNORE && font.number() == LyXFont::IGNORE
@ -551,8 +551,8 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
//and cursor is set to the original position. //and cursor is set to the original position.
if (implicitSelection) { if (implicitSelection) {
clearSelection(); clearSelection();
cursor = resetCursor; cursor() = resetCursor;
selection.cursor = cursor; anchor() = cursor();
} }
} }
@ -562,7 +562,7 @@ string LyXText::getStringToIndex()
// Try implicit word selection // Try implicit word selection
// If there is a change in the language the implicit word selection // If there is a change in the language the implicit word selection
// is disabled. // is disabled.
LyXCursor const reset_cursor = cursor; LyXCursor const reset_cursor = cursor();
bool const implicitSelection = bool const implicitSelection =
selectWordWhenUnderCursor(lyx::PREVIOUS_WORD); selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
@ -575,8 +575,8 @@ string LyXText::getStringToIndex()
idxstring = selectionAsString(*bv()->buffer(), false); idxstring = selectionAsString(*bv()->buffer(), false);
// Reset cursors to their original position. // Reset cursors to their original position.
cursor = reset_cursor; cursor() = reset_cursor;
selection.cursor = cursor; anchor() = cursor();
// Clear the implicit selection. // Clear the implicit selection.
if (implicitSelection) if (implicitSelection)
@ -919,9 +919,9 @@ void LyXText::insertInset(InsetOld * inset)
if (!cursorPar()->insetAllowed(inset->lyxCode())) if (!cursorPar()->insetAllowed(inset->lyxCode()))
return; return;
recUndo(cursor.par()); recUndo(cursor().par());
freezeUndo(); freezeUndo();
cursorPar()->insertInset(cursor.pos(), inset); cursorPar()->insertInset(cursor().pos(), inset);
// Just to rebreak and refresh correctly. // Just to rebreak and refresh correctly.
// The character will not be inserted a second time // The character will not be inserted a second time
insertChar(Paragraph::META_INSET); insertChar(Paragraph::META_INSET);
@ -984,8 +984,8 @@ void LyXText::cutSelection(bool doclear, bool realcut)
// cutSelection can invalidate the cursor so we need to set // cutSelection can invalidate the cursor so we need to set
// it anew. (Lgb) // it anew. (Lgb)
// we prefer the end for when tracking changes // we prefer the end for when tracking changes
cursor.pos(endpos); cursor().pos(endpos);
cursor.par(parOffset(endpit)); cursor().par(parOffset(endpit));
// need a valid cursor. (Lgb) // need a valid cursor. (Lgb)
clearSelection(); clearSelection();
@ -1026,7 +1026,7 @@ void LyXText::pasteSelection(size_t sel_index)
if (!CutAndPaste::checkPastePossible()) if (!CutAndPaste::checkPastePossible())
return; return;
recUndo(cursor.par()); recUndo(cursor().par());
ParagraphList::iterator endpit; ParagraphList::iterator endpit;
PitPosPair ppp; PitPosPair ppp;
@ -1036,7 +1036,7 @@ void LyXText::pasteSelection(size_t sel_index)
boost::tie(ppp, endpit) = boost::tie(ppp, endpit) =
CutAndPaste::pasteSelection(*bv()->buffer(), CutAndPaste::pasteSelection(*bv()->buffer(),
paragraphs(), paragraphs(),
cursorPar(), cursor.pos(), cursorPar(), cursor().pos(),
bv()->buffer()->params().textclass, bv()->buffer()->params().textclass,
sel_index, el); sel_index, el);
bufferErrors(*bv()->buffer(), el); bufferErrors(*bv()->buffer(), el);
@ -1046,7 +1046,7 @@ void LyXText::pasteSelection(size_t sel_index)
clearSelection(); clearSelection();
selection.cursor = cursor; anchor() = cursor();
setCursor(ppp.first, ppp.second); setCursor(ppp.first, ppp.second);
setSelection(); setSelection();
updateCounters(); updateCounters();
@ -1058,7 +1058,7 @@ void LyXText::setSelectionRange(lyx::pos_type length)
if (!length) if (!length)
return; return;
selection.cursor = cursor; anchor() = cursor();
while (length--) while (length--)
cursorRight(true); cursorRight(true);
setSelection(); setSelection();
@ -1068,7 +1068,7 @@ void LyXText::setSelectionRange(lyx::pos_type length)
// simple replacing. The font of the first selected character is used // simple replacing. The font of the first selected character is used
void LyXText::replaceSelectionWithString(string const & str) void LyXText::replaceSelectionWithString(string const & str)
{ {
recUndo(cursor.par()); recUndo(cursor().par());
freezeUndo(); freezeUndo();
// Get font setting before we cut // Get font setting before we cut
@ -1096,10 +1096,10 @@ void LyXText::replaceSelectionWithString(string const & str)
void LyXText::insertStringAsLines(string const & str) void LyXText::insertStringAsLines(string const & str)
{ {
ParagraphList::iterator pit = cursorPar(); ParagraphList::iterator pit = cursorPar();
pos_type pos = cursor.pos(); pos_type pos = cursor().pos();
ParagraphList::iterator endpit = boost::next(cursorPar()); ParagraphList::iterator endpit = boost::next(cursorPar());
recUndo(cursor.par()); recUndo(cursor().par());
// only to be sure, should not be neccessary // only to be sure, should not be neccessary
clearSelection(); clearSelection();
@ -1107,7 +1107,7 @@ void LyXText::insertStringAsLines(string const & str)
bv()->buffer()->insertStringAsLines(pit, pos, current_font, str); bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
redoParagraphs(cursorPar(), endpit); redoParagraphs(cursorPar(), endpit);
selection.cursor = cursor; anchor() = cursor();
setCursor(pit, pos); setCursor(pit, pos);
setSelection(); setSelection();
} }
@ -1150,7 +1150,7 @@ void LyXText::setCursor(ParagraphList::iterator pit, pos_type pos)
bool LyXText::setCursor(paroffset_type par, pos_type pos, bool setfont, bool LyXText::setCursor(paroffset_type par, pos_type pos, bool setfont,
bool boundary) bool boundary)
{ {
LyXCursor old_cursor = cursor; LyXCursor old_cursor = cursor();
setCursorIntern(par, pos, setfont, boundary); setCursorIntern(par, pos, setfont, boundary);
return deleteEmptyParagraphMechanism(old_cursor); return deleteEmptyParagraphMechanism(old_cursor);
} }
@ -1210,7 +1210,7 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
void LyXText::setCursorIntern(paroffset_type par, void LyXText::setCursorIntern(paroffset_type par,
pos_type pos, bool setfont, bool boundary) pos_type pos, bool setfont, bool boundary)
{ {
setCursor(cursor, par, pos, boundary); setCursor(cursor(), par, pos, boundary);
bv()->x_target(cursorX() + xo_); bv()->x_target(cursorX() + xo_);
if (setfont) if (setfont)
setCurrentFont(); setCurrentFont();
@ -1219,10 +1219,10 @@ void LyXText::setCursorIntern(paroffset_type par,
void LyXText::setCurrentFont() void LyXText::setCurrentFont()
{ {
pos_type pos = cursor.pos(); pos_type pos = cursor().pos();
ParagraphList::iterator pit = cursorPar(); ParagraphList::iterator pit = cursorPar();
if (cursor.boundary() && pos > 0) if (cursor().boundary() && pos > 0)
--pos; --pos;
if (pos > 0) { if (pos > 0) {
@ -1243,9 +1243,9 @@ void LyXText::setCurrentFont()
current_font = pit->getFontSettings(bufparams, pos); current_font = pit->getFontSettings(bufparams, pos);
real_current_font = getFont(pit, pos); real_current_font = getFont(pit, pos);
if (cursor.pos() == pit->size() && if (cursor().pos() == pit->size() &&
bidi.isBoundary(*bv()->buffer(), *pit, cursor.pos()) && bidi.isBoundary(*bv()->buffer(), *pit, cursor().pos()) &&
!cursor.boundary()) { !cursor().boundary()) {
Language const * lang = Language const * lang =
pit->getParLanguage(bufparams); pit->getParLanguage(bufparams);
current_font.setLanguage(lang); current_font.setLanguage(lang);
@ -1362,8 +1362,8 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
void LyXText::setCursorFromCoordinates(int x, int y) void LyXText::setCursorFromCoordinates(int x, int y)
{ {
LyXCursor old_cursor = cursor; LyXCursor old_cursor = cursor();
setCursorFromCoordinates(cursor, x, y); setCursorFromCoordinates(cursor(), x, y);
setCurrentFont(); setCurrentFont();
deleteEmptyParagraphMechanism(old_cursor); deleteEmptyParagraphMechanism(old_cursor);
} }
@ -1384,9 +1384,9 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
bool LyXText::checkAndActivateInset(bool front) bool LyXText::checkAndActivateInset(bool front)
{ {
if (cursor.pos() == cursorPar()->size()) if (cursor().pos() == cursorPar()->size())
return false; return false;
InsetOld * inset = cursorPar()->getInset(cursor.pos()); InsetOld * inset = cursorPar()->getInset(cursor().pos());
if (!isHighlyEditableInset(inset)) if (!isHighlyEditableInset(inset))
return false; return false;
inset->edit(bv(), front); inset->edit(bv(), front);
@ -1416,7 +1416,7 @@ DispatchResult LyXText::moveRightIntern(bool front, bool activate_inset, bool se
{ {
ParagraphList::iterator c_par = cursorPar(); ParagraphList::iterator c_par = cursorPar();
if (boost::next(c_par) == paragraphs().end() if (boost::next(c_par) == paragraphs().end()
&& cursor.pos() >= c_par->size()) && cursor().pos() >= c_par->size())
return DispatchResult(false, FINISHED_RIGHT); return DispatchResult(false, FINISHED_RIGHT);
if (activate_inset && checkAndActivateInset(front)) if (activate_inset && checkAndActivateInset(front))
return DispatchResult(true, true); return DispatchResult(true, true);
@ -1430,7 +1430,7 @@ DispatchResult LyXText::moveRightIntern(bool front, bool activate_inset, bool se
DispatchResult LyXText::moveLeftIntern(bool front, DispatchResult LyXText::moveLeftIntern(bool front,
bool activate_inset, bool selecting) bool activate_inset, bool selecting)
{ {
if (cursor.par() == 0 && cursor.pos() <= 0) if (cursor().par() == 0 && cursor().pos() <= 0)
return DispatchResult(false, FINISHED); return DispatchResult(false, FINISHED);
cursorLeft(true); cursorLeft(true);
if (!selecting) if (!selecting)
@ -1463,18 +1463,18 @@ DispatchResult LyXText::moveDown()
bool LyXText::cursorLeft(bool internal) bool LyXText::cursorLeft(bool internal)
{ {
if (cursor.pos() > 0) { if (cursor().pos() > 0) {
bool boundary = cursor.boundary(); bool boundary = cursor().boundary();
setCursor(cursor.par(), cursor.pos() - 1, true, false); setCursor(cursor().par(), cursor().pos() - 1, true, false);
if (!internal && !boundary && if (!internal && !boundary &&
bidi.isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos() + 1)) bidi.isBoundary(*bv()->buffer(), *cursorPar(), cursor().pos() + 1))
setCursor(cursor.par(), cursor.pos() + 1, true, true); setCursor(cursor().par(), cursor().pos() + 1, true, true);
return true; return true;
} }
if (cursor.par() != 0) { if (cursor().par() != 0) {
// steps into the paragraph above // steps into the paragraph above
setCursor(cursor.par() - 1, boost::prior(cursorPar())->size()); setCursor(cursor().par() - 1, boost::prior(cursorPar())->size());
return true; return true;
} }
@ -1484,21 +1484,21 @@ bool LyXText::cursorLeft(bool internal)
bool LyXText::cursorRight(bool internal) bool LyXText::cursorRight(bool internal)
{ {
if (!internal && cursor.boundary()) { if (!internal && cursor().boundary()) {
setCursor(cursor.par(), cursor.pos(), true, false); setCursor(cursor().par(), cursor().pos(), true, false);
return true; return true;
} }
if (cursor.pos() != cursorPar()->size()) { if (cursor().pos() != cursorPar()->size()) {
setCursor(cursor.par(), cursor.pos() + 1, true, false); setCursor(cursor().par(), cursor().pos() + 1, true, false);
if (!internal && bidi.isBoundary(*bv()->buffer(), *cursorPar(), if (!internal && bidi.isBoundary(*bv()->buffer(), *cursorPar(),
cursor.pos())) cursor().pos()))
setCursor(cursor.par(), cursor.pos(), true, true); setCursor(cursor().par(), cursor().pos(), true, true);
return true; return true;
} }
if (cursor.par() + 1 != int(paragraphs().size())) { if (cursor().par() + 1 != int(paragraphs().size())) {
setCursor(cursor.par() + 1, 0); setCursor(cursor().par() + 1, 0);
return true; return true;
} }
@ -1541,7 +1541,7 @@ void LyXText::cursorDown(bool selecting)
void LyXText::cursorUpParagraph() void LyXText::cursorUpParagraph()
{ {
ParagraphList::iterator cpit = cursorPar(); ParagraphList::iterator cpit = cursorPar();
if (cursor.pos() > 0) if (cursor().pos() > 0)
setCursor(cpit, 0); setCursor(cpit, 0);
else if (cpit != paragraphs().begin()) else if (cpit != paragraphs().begin())
setCursor(boost::prior(cpit), 0); setCursor(boost::prior(cpit), 0);
@ -1620,8 +1620,8 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
// MISSING // MISSING
// If the pos around the old_cursor were spaces, delete one of them. // If the pos around the old_cursor were spaces, delete one of them.
if (old_cursor.par() != cursor.par() if (old_cursor.par() != cursor().par()
|| old_cursor.pos() != cursor.pos()) { || old_cursor.pos() != cursor().pos()) {
// Only if the cursor has really moved // Only if the cursor has really moved
if (old_cursor.pos() > 0 if (old_cursor.pos() > 0
@ -1640,8 +1640,8 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
// automated way in LyXCursor code. (JMarc 26/09/2001) // automated way in LyXCursor code. (JMarc 26/09/2001)
#endif #endif
// correct all cursors held by the LyXText // correct all cursors held by the LyXText
fixCursorAfterDelete(cursor, old_cursor); fixCursorAfterDelete(cursor(), old_cursor);
fixCursorAfterDelete(selection.cursor, old_cursor); fixCursorAfterDelete(anchor(), old_cursor);
return false; return false;
} }
} }
@ -1655,7 +1655,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
return false; return false;
// only do our magic if we changed paragraph // only do our magic if we changed paragraph
if (old_cursor.par() == cursor.par()) if (old_cursor.par() == cursor().par())
return false; return false;
// record if we have deleted a paragraph // record if we have deleted a paragraph
@ -1670,30 +1670,30 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
deleted = true; deleted = true;
bool selection_position_was_oldcursor_position = bool selection_position_was_oldcursor_position =
selection.cursor.par() == old_cursor.par() anchor().par() == old_cursor.par()
&& selection.cursor.pos() == old_cursor.pos(); && anchor().pos() == old_cursor.pos();
tmpcursor = cursor; tmpcursor = cursor();
cursor = old_cursor; // that undo can restore the right cursor position cursor() = old_cursor; // that undo can restore the right cursor position
ParagraphList::iterator endpit = boost::next(old_pit); ParagraphList::iterator endpit = boost::next(old_pit);
while (endpit != paragraphs().end() && endpit->getDepth()) while (endpit != paragraphs().end() && endpit->getDepth())
++endpit; ++endpit;
recUndo(parOffset(old_pit), parOffset(endpit) - 1); recUndo(parOffset(old_pit), parOffset(endpit) - 1);
cursor = tmpcursor; cursor() = tmpcursor;
// cache cursor pit // cache cursor pit
ParagraphList::iterator tmppit = cursorPar(); ParagraphList::iterator tmppit = cursorPar();
// delete old par // delete old par
paragraphs().erase(old_pit); paragraphs().erase(old_pit);
// update cursor par offset // update cursor par offset
cursor.par(parOffset(tmppit)); cursor().par(parOffset(tmppit));
redoParagraph(); redoParagraph();
if (selection_position_was_oldcursor_position) { if (selection_position_was_oldcursor_position) {
// correct selection // correct selection
selection.cursor = cursor; anchor() = cursor();
} }
} }
@ -1702,7 +1702,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
if (old_pit->stripLeadingSpaces()) { if (old_pit->stripLeadingSpaces()) {
redoParagraph(old_pit); redoParagraph(old_pit);
selection.cursor = cursor; anchor() = cursor();
} }
return false; return false;
} }

View File

@ -91,16 +91,16 @@ namespace {
if (font.language() != ignore_language || if (font.language() != ignore_language ||
font.number() != LyXFont::IGNORE) { font.number() != LyXFont::IGNORE) {
LyXCursor & cursor = text->cursor; LyXCursor & cur = text->cursor();
Paragraph & par = *text->cursorPar(); Paragraph & par = *text->cursorPar();
text->bidi.computeTables(par, *bv->buffer(), text->bidi.computeTables(par, *bv->buffer(),
*par.getRow(cursor.pos())); *par.getRow(cur.pos()));
if (cursor.boundary() != if (cur.boundary() !=
text->bidi.isBoundary(*bv->buffer(), par, text->bidi.isBoundary(*bv->buffer(), par,
cursor.pos(), cur.pos(),
text->real_current_font)) text->real_current_font))
text->setCursor(cursor.par(), cursor.pos(), text->setCursor(cur.par(), cur.pos(),
false, !cursor.boundary()); false, !cur.boundary());
} }
} }
@ -218,7 +218,7 @@ namespace {
LyXText * lt = bv->getLyXText(); LyXText * lt = bv->getLyXText();
// if (!lt->selection.set()) // if (!lt->selection.set())
// lt->selection.cursor = lt->cursor; // lt->selection.cursor = lt->cursor();
if (selecting || lt->selection.mark()) if (selecting || lt->selection.mark())
lt->setSelection(); lt->setSelection();
@ -294,7 +294,7 @@ bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
{ {
ParagraphList::iterator end = paragraphs().end(); ParagraphList::iterator end = paragraphs().end();
ParagraphList::iterator pit = cursorPar(); ParagraphList::iterator pit = cursorPar();
pos_type pos = cursor.pos(); pos_type pos = cursor().pos();
InsetOld * inset; InsetOld * inset;
do { do {
@ -327,21 +327,21 @@ void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
clearSelection(); clearSelection();
string contents; string contents;
if (same_content && cursor.pos() < cursorPar()->size() if (same_content && cursor().pos() < cursorPar()->size()
&& cursorPar()->isInset(cursor.pos())) { && cursorPar()->isInset(cursor().pos())) {
InsetOld const * inset = cursorPar()->getInset(cursor.pos()); InsetOld const * inset = cursorPar()->getInset(cursor().pos());
if (find(codes.begin(), codes.end(), inset->lyxCode()) if (find(codes.begin(), codes.end(), inset->lyxCode())
!= codes.end()) != codes.end())
contents = static_cast<InsetCommand const *>(inset)->getContents(); contents = static_cast<InsetCommand const *>(inset)->getContents();
} }
if (!gotoNextInset(codes, contents)) { if (!gotoNextInset(codes, contents)) {
if (cursor.pos() || cursorPar() != paragraphs().begin()) { if (cursor().pos() || cursorPar() != paragraphs().begin()) {
LyXCursor tmp = cursor; LyXCursor tmp = cursor();
cursor.par(0); cursor().par(0);
cursor.pos(0); cursor().pos(0);
if (!gotoNextInset(codes, contents)) { if (!gotoNextInset(codes, contents)) {
cursor = tmp; cursor() = tmp;
bv()->owner()->message(_("No more insets")); bv()->owner()->message(_("No more insets"));
} }
} else { } else {
@ -349,7 +349,7 @@ void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
} }
} }
bv()->update(); bv()->update();
selection.cursor = cursor; anchor() = cursor();
} }
@ -543,7 +543,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_RIGHTSEL: case LFUN_RIGHTSEL:
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
if (rtl()) if (rtl())
cursorLeft(bv); cursorLeft(bv);
else else
@ -553,7 +553,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_LEFTSEL: case LFUN_LEFTSEL:
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
if (rtl()) if (rtl())
cursorRight(bv); cursorRight(bv);
else else
@ -563,56 +563,56 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_UPSEL: case LFUN_UPSEL:
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
cursorUp(true); cursorUp(true);
finishChange(bv, true); finishChange(bv, true);
break; break;
case LFUN_DOWNSEL: case LFUN_DOWNSEL:
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
cursorDown(true); cursorDown(true);
finishChange(bv, true); finishChange(bv, true);
break; break;
case LFUN_UP_PARAGRAPHSEL: case LFUN_UP_PARAGRAPHSEL:
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
cursorUpParagraph(); cursorUpParagraph();
finishChange(bv, true); finishChange(bv, true);
break; break;
case LFUN_DOWN_PARAGRAPHSEL: case LFUN_DOWN_PARAGRAPHSEL:
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
cursorDownParagraph(); cursorDownParagraph();
finishChange(bv, true); finishChange(bv, true);
break; break;
case LFUN_PRIORSEL: case LFUN_PRIORSEL:
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
cursorPrevious(); cursorPrevious();
finishChange(bv, true); finishChange(bv, true);
break; break;
case LFUN_NEXTSEL: case LFUN_NEXTSEL:
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
cursorNext(); cursorNext();
finishChange(bv, true); finishChange(bv, true);
break; break;
case LFUN_HOMESEL: case LFUN_HOMESEL:
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
cursorHome(); cursorHome();
finishChange(bv, true); finishChange(bv, true);
break; break;
case LFUN_ENDSEL: case LFUN_ENDSEL:
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
cursorEnd(); cursorEnd();
finishChange(bv, true); finishChange(bv, true);
break; break;
@ -634,7 +634,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
break; break;
case LFUN_WORDSEL: { case LFUN_WORDSEL: {
LyXCursor cur1 = cursor; LyXCursor cur1 = cursor();
LyXCursor cur2; LyXCursor cur2;
getWord(cur1, cur2, lyx::WHOLE_WORD); getWord(cur1, cur2, lyx::WHOLE_WORD);
setCursor(cur1.par(), cur1.pos()); setCursor(cur1.par(), cur1.pos());
@ -710,7 +710,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
lyx::pos_type body = cursorPar()->beginOfBody(); lyx::pos_type body = cursorPar()->beginOfBody();
// Not allowed by LaTeX (labels or empty par) // Not allowed by LaTeX (labels or empty par)
if (cursor.pos() <= body) if (cursor().pos() <= body)
break; break;
replaceSelection(bv->getLyXText()); replaceSelection(bv->getLyXText());
@ -722,7 +722,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_DELETE: case LFUN_DELETE:
if (!selection.set()) { if (!selection.set()) {
Delete(); Delete();
selection.cursor = cursor; anchor() = cursor();
// It is possible to make it a lot faster still // It is possible to make it a lot faster still
// just comment out the line below... // just comment out the line below...
} else { } else {
@ -735,14 +735,14 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_DELETE_SKIP: case LFUN_DELETE_SKIP:
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP. // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
if (!selection.set()) { if (!selection.set()) {
if (cursor.pos() == cursorPar()->size()) { if (cursor().pos() == cursorPar()->size()) {
cursorRight(bv); cursorRight(bv);
cursorLeft(bv); cursorLeft(bv);
Delete(); Delete();
selection.cursor = cursor; anchor() = cursor();
} else { } else {
Delete(); Delete();
selection.cursor = cursor; anchor() = cursor();
} }
} else { } else {
cutSelection(true, false); cutSelection(true, false);
@ -755,7 +755,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
if (!selection.set()) { if (!selection.set()) {
if (bv->owner()->getIntl().getTransManager().backspace()) { if (bv->owner()->getIntl().getTransManager().backspace()) {
backspace(); backspace();
selection.cursor = cursor; anchor() = cursor();
// It is possible to make it a lot faster still // It is possible to make it a lot faster still
// just comment out the line below... // just comment out the line below...
} }
@ -770,9 +770,9 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_BACKSPACE_SKIP: case LFUN_BACKSPACE_SKIP:
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP. // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
if (!selection.set()) { if (!selection.set()) {
LyXCursor cur = cursor; LyXCursor cur = cursor();
backspace(); backspace();
selection.cursor = cur; anchor() = cur;
} else { } else {
cutSelection(true, false); cutSelection(true, false);
} }
@ -783,7 +783,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
replaceSelection(bv->getLyXText()); replaceSelection(bv->getLyXText());
breakParagraph(bv->buffer()->paragraphs(), 0); breakParagraph(bv->buffer()->paragraphs(), 0);
bv->update(); bv->update();
selection.cursor = cursor; anchor() = cursor();
bv->switchKeyMap(); bv->switchKeyMap();
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
@ -792,7 +792,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
replaceSelection(bv->getLyXText()); replaceSelection(bv->getLyXText());
breakParagraph(bv->buffer()->paragraphs(), 1); breakParagraph(bv->buffer()->paragraphs(), 1);
bv->update(); bv->update();
selection.cursor = cursor; anchor() = cursor();
bv->switchKeyMap(); bv->switchKeyMap();
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
@ -801,7 +801,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
// When at the beginning of a paragraph, remove // When at the beginning of a paragraph, remove
// indentation and add a "defskip" at the top. // indentation and add a "defskip" at the top.
// Otherwise, do the same as LFUN_BREAKPARAGRAPH. // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
LyXCursor cur = cursor; LyXCursor cur = cursor();
replaceSelection(bv->getLyXText()); replaceSelection(bv->getLyXText());
if (cur.pos() == 0) { if (cur.pos() == 0) {
ParagraphParameters & params = getPar(cur)->params(); ParagraphParameters & params = getPar(cur)->params();
@ -813,7 +813,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
breakParagraph(bv->buffer()->paragraphs(), 0); breakParagraph(bv->buffer()->paragraphs(), 0);
} }
bv->update(); bv->update();
selection.cursor = cur; anchor() = cur;
bv->switchKeyMap(); bv->switchKeyMap();
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
@ -924,7 +924,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_MARK_OFF: case LFUN_MARK_OFF:
clearSelection(); clearSelection();
bv->update(); bv->update();
selection.cursor = cursor; anchor() = cursor();
cmd.message(N_("Mark off")); cmd.message(N_("Mark off"));
break; break;
@ -932,7 +932,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
clearSelection(); clearSelection();
selection.mark(true); selection.mark(true);
bv->update(); bv->update();
selection.cursor = cursor; anchor() = cursor();
cmd.message(N_("Mark on")); cmd.message(N_("Mark on"));
break; break;
@ -944,7 +944,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
selection.mark(true); selection.mark(true);
cmd.message(N_("Mark set")); cmd.message(N_("Mark set"));
} }
selection.cursor = cursor; anchor() = cursor();
bv->update(); bv->update();
break; break;
@ -964,7 +964,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
break; break;
case LFUN_TRANSPOSE_CHARS: case LFUN_TRANSPOSE_CHARS:
recUndo(cursor.par()); recUndo(cursor().par());
redoParagraph(); redoParagraph();
bv->update(); bv->update();
break; break;
@ -998,7 +998,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
if (in_inset_) if (in_inset_)
return DispatchResult(false); return DispatchResult(false);
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
cursorTop(); cursorTop();
finishChange(bv, true); finishChange(bv, true);
break; break;
@ -1007,7 +1007,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
if (in_inset_) if (in_inset_)
return DispatchResult(false); return DispatchResult(false);
if (!selection.set()) if (!selection.set())
selection.cursor = cursor; anchor() = cursor();
cursorBottom(); cursorBottom();
finishChange(bv, true); finishChange(bv, true);
break; break;
@ -1135,7 +1135,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_QUOTE: { case LFUN_QUOTE: {
replaceSelection(bv->getLyXText()); replaceSelection(bv->getLyXText());
ParagraphList::iterator pit = cursorPar(); ParagraphList::iterator pit = cursorPar();
lyx::pos_type pos = cursor.pos(); lyx::pos_type pos = cursor().pos();
char c; char c;
if (!pos) if (!pos)
c = ' '; c = ' ';
@ -1171,7 +1171,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
for (int i = 0; i < datetmp_len; i++) for (int i = 0; i < datetmp_len; i++)
insertChar(datetmp[i]); insertChar(datetmp[i]);
selection.cursor = cursor; anchor() = cursor();
moveCursor(bv, false); moveCursor(bv, false);
break; break;
} }
@ -1182,7 +1182,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
if (cmd.button() == mouse_button::button1) { if (cmd.button() == mouse_button::button1) {
selection_possible = true; selection_possible = true;
cursorHome(); cursorHome();
selection.cursor = cursor; anchor() = cursor();
cursorEnd(); cursorEnd();
setSelection(); setSelection();
bv->haveSelection(selection.set()); bv->haveSelection(selection.set());
@ -1270,7 +1270,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
} }
setCursorFromCoordinates(cmd.x, cmd.y); setCursorFromCoordinates(cmd.x, cmd.y);
selection.cursor = cursor; anchor() = cursor();
finishUndo(); finishUndo();
bv->x_target(cursorX() + xo_); bv->x_target(cursorX() + xo_);
@ -1340,7 +1340,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
bv->owner()->getIntl().getTransManager(). bv->owner()->getIntl().getTransManager().
TranslateAndInsert(*cit, this); TranslateAndInsert(*cit, this);
selection.cursor = cursor; anchor() = cursor();
moveCursor(bv, false); moveCursor(bv, false);
// real_current_font.number can change so we need to // real_current_font.number can change so we need to

View File

@ -9,7 +9,6 @@
*/ */
#include <config.h> #include <config.h>
#include <algorithm>
#include "textcursor.h" #include "textcursor.h"
@ -17,30 +16,33 @@
LyXCursor const & TextCursor::selStart() const LyXCursor const & TextCursor::selStart() const
{ {
if (!selection.set()) if (!selection.set())
return cursor; return cursor_;
return std::min(selection.cursor, cursor); // can't use std::min as this creates a new object
return anchor_ < cursor_ ? anchor_ : cursor_;
} }
LyXCursor const & TextCursor::selEnd() const LyXCursor const & TextCursor::selEnd() const
{ {
if (!selection.set()) if (!selection.set())
return cursor; return cursor_;
return std::max(selection.cursor, cursor); return anchor_ > cursor_ ? anchor_ : cursor_;
} }
LyXCursor & TextCursor::selStart() LyXCursor & TextCursor::selStart()
{ {
TextCursor const & t = *this; if (!selection.set())
return const_cast<LyXCursor &>(t.selStart()); return cursor_;
return anchor_ < cursor_ ? anchor_ : cursor_;
} }
LyXCursor & TextCursor::selEnd() LyXCursor & TextCursor::selEnd()
{ {
TextCursor const & t = *this; if (!selection.set())
return const_cast<LyXCursor &>(t.selEnd()); return cursor_;
return anchor_ > cursor_ ? anchor_ : cursor_;
} }
@ -48,18 +50,15 @@ void TextCursor::setSelection()
{ {
selection.set(true); selection.set(true);
// a selection with no contents is not a selection // a selection with no contents is not a selection
if (cursor.par() == selection.cursor.par() && if (cursor_.par() == anchor_.par() && cursor_.pos() == anchor_.pos())
cursor.pos() == selection.cursor.pos())
{
selection.set(false); selection.set(false);
} }
}
void TextCursor::clearSelection() void TextCursor::clearSelection()
{ {
selection.set(false); selection.set(false);
selection.mark(false); selection.mark(false);
selection.cursor = cursor; anchor_ = cursor_;
} }

View File

@ -50,7 +50,6 @@ struct Selection {
void mark(bool m) { void mark(bool m) {
mark_ = m; mark_ = m;
} }
LyXCursor cursor; // the other end of the selection
private: private:
bool set_; // former selection bool set_; // former selection
bool mark_; // former mark_set bool mark_; // former mark_set
@ -64,7 +63,9 @@ struct TextCursor {
void clearSelection(); void clearSelection();
// actual cursor position // actual cursor position
LyXCursor cursor; LyXCursor cursor_;
// the other end of the selection
LyXCursor anchor_;
Selection selection; Selection selection;

View File

@ -121,7 +121,7 @@ void recordUndo(Undo::undo_kind kind,
int textnum; int textnum;
ParIterator pit = text2pit(buf, text, textnum); ParIterator pit = text2pit(buf, text, textnum);
stack.push(Undo(kind, textnum, pit.index(), stack.push(Undo(kind, textnum, pit.index(),
first_par, end_par, text->cursor.par(), text->cursor.pos())); first_par, end_par, text->cursor().par(), text->cursor().pos()));
lyxerr << "undo record: " << stack.top() << std::endl; lyxerr << "undo record: " << stack.top() << std::endl;
// record the relevant paragraphs // record the relevant paragraphs
@ -178,12 +178,12 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo)
<< std::endl; << std::endl;
// set cursor again to force the position to be the right one // set cursor again to force the position to be the right one
text->cursor.par(undo.cursor_par); text->cursor().par(undo.cursor_par);
text->cursor.pos(undo.cursor_pos); text->cursor().pos(undo.cursor_pos);
// clear any selection // clear any selection
text->clearSelection(); text->clearSelection();
text->selection.cursor = text->cursor; text->anchor() = text->cursor();
text->updateCounters(); text->updateCounters();
// rebreak the entire lyxtext // rebreak the entire lyxtext
@ -225,8 +225,8 @@ bool textUndoOrRedo(BufferView * bv,
otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last); otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last);
} }
LyXText * text = pit.text(buf); LyXText * text = pit.text(buf);
otherstack.top().cursor_pos = text->cursor.pos(); otherstack.top().cursor_pos = text->cursor().pos();
otherstack.top().cursor_par = text->cursor.par(); otherstack.top().cursor_par = text->cursor().par();
lyxerr << " undo other: " << otherstack.top() << std::endl; lyxerr << " undo other: " << otherstack.top() << std::endl;
} }
@ -293,5 +293,5 @@ void recordUndo(Undo::undo_kind kind, LyXText const * text, paroffset_type par)
void recordUndo(BufferView * bv, Undo::undo_kind kind) void recordUndo(BufferView * bv, Undo::undo_kind kind)
{ {
recordUndo(kind, bv->text(), bv->text()->cursor.par()); recordUndo(kind, bv->text(), bv->text()->cursor().par());
} }