mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 21:40:19 +00:00
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:
parent
80296aac50
commit
97901b5d51
@ -316,7 +316,7 @@ void BufferView::gotoLabel(string const & label)
|
||||
text()->setCursor(
|
||||
std::distance(text()->paragraphs().begin(), it.getPar()),
|
||||
it.getPos());
|
||||
text()->selection.cursor = text()->cursor;
|
||||
text()->anchor() = text()->cursor();
|
||||
update();
|
||||
return;
|
||||
}
|
||||
@ -418,7 +418,7 @@ Encoding const * BufferView::getEncoding() const
|
||||
return 0;
|
||||
return t->cursorPar()->getFont(
|
||||
buffer()->params(),
|
||||
t->cursor.pos(),
|
||||
t->cursor().pos(),
|
||||
outerFont(t->cursorPar(), t->paragraphs())
|
||||
).language()->encoding();
|
||||
}
|
||||
|
@ -388,37 +388,38 @@ void BufferView::Pimpl::resizeCurrentBuffer()
|
||||
|
||||
owner_->message(_("Formatting document..."));
|
||||
|
||||
lyxerr << "### resizeCurrentBuffer: text " << bv_->text() << endl;
|
||||
if (!bv_->text())
|
||||
LyXText * text = bv_->text();
|
||||
lyxerr << "### resizeCurrentBuffer: text " << text << endl;
|
||||
if (!text)
|
||||
return;
|
||||
|
||||
par = bv_->text()->cursor.par();
|
||||
pos = bv_->text()->cursor.pos();
|
||||
selstartpar = bv_->text()->selStart().par();
|
||||
selstartpos = bv_->text()->selStart().pos();
|
||||
selendpar = bv_->text()->selEnd().par();
|
||||
selendpos = bv_->text()->selEnd().pos();
|
||||
selection = bv_->text()->selection.set();
|
||||
mark_set = bv_->text()->selection.mark();
|
||||
bv_->text()->textwidth_ = bv_->workWidth();
|
||||
bv_->text()->fullRebreak();
|
||||
par = text->cursor().par();
|
||||
pos = text->cursor().pos();
|
||||
selstartpar = text->selStart().par();
|
||||
selstartpos = text->selStart().pos();
|
||||
selendpar = text->selEnd().par();
|
||||
selendpos = text->selEnd().pos();
|
||||
selection = text->selection.set();
|
||||
mark_set = text->selection.mark();
|
||||
text->textwidth_ = bv_->workWidth();
|
||||
text->fullRebreak();
|
||||
update();
|
||||
|
||||
if (par != -1) {
|
||||
bv_->text()->selection.set(true);
|
||||
text->selection.set(true);
|
||||
// At this point just to avoid the Delete-Empty-Paragraph-
|
||||
// Mechanism when setting the cursor.
|
||||
bv_->text()->selection.mark(mark_set);
|
||||
text->selection.mark(mark_set);
|
||||
if (selection) {
|
||||
bv_->text()->setCursor(selstartpar, selstartpos);
|
||||
bv_->text()->selection.cursor = bv_->text()->cursor;
|
||||
bv_->text()->setCursor(selendpar, selendpos);
|
||||
bv_->text()->setSelection();
|
||||
bv_->text()->setCursor(par, pos);
|
||||
text->setCursor(selstartpar, selstartpos);
|
||||
text->anchor() = text->cursor();
|
||||
text->setCursor(selendpar, selendpos);
|
||||
text->setSelection();
|
||||
text->setCursor(par, pos);
|
||||
} else {
|
||||
bv_->text()->setCursor(par, pos);
|
||||
bv_->text()->selection.cursor = bv_->text()->cursor;
|
||||
bv_->text()->selection.set(false);
|
||||
text->setCursor(par, pos);
|
||||
text->anchor() = text->cursor();
|
||||
text->selection.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -536,11 +537,11 @@ void BufferView::Pimpl::selectionRequested()
|
||||
}
|
||||
|
||||
if (!xsel_cache_.set ||
|
||||
text->cursor != xsel_cache_.cursor ||
|
||||
text->selection.cursor != xsel_cache_.selection_cursor)
|
||||
text->cursor() != xsel_cache_.cursor ||
|
||||
text->anchor() != xsel_cache_.anchor)
|
||||
{
|
||||
xsel_cache_.cursor = text->cursor;
|
||||
xsel_cache_.selection_cursor = text->selection.cursor;
|
||||
xsel_cache_.cursor = text->cursor();
|
||||
xsel_cache_.anchor = text->anchor();
|
||||
xsel_cache_.set = text->selection.set();
|
||||
sel = text->selectionAsString(*bv_->buffer(), false);
|
||||
if (!sel.empty())
|
||||
@ -647,7 +648,7 @@ void BufferView::Pimpl::savePosition(unsigned int i)
|
||||
return;
|
||||
saved_positions[i] = Position(buffer_->fileName(),
|
||||
bv_->text()->cursorPar()->id(),
|
||||
bv_->text()->cursor.pos());
|
||||
bv_->text()->cursor().pos());
|
||||
if (i > 0)
|
||||
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;
|
||||
Buffer::inset_iterator it =
|
||||
find_if(Buffer::inset_iterator(
|
||||
cursorPar(), cursor.pos()),
|
||||
cursorPar(), cursor().pos()),
|
||||
buffer_->inset_iterator_end(),
|
||||
lyx::compare_memfun(&Inset::lyxCode, code));
|
||||
return it != buffer_->inset_iterator_end() ? (*it) : 0;
|
||||
@ -763,7 +764,7 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
|
||||
}
|
||||
if (cursor_par_seen) {
|
||||
if (beg.getPar() == text->cursorPar()
|
||||
&& beg.getPos() >= text->cursor.pos()) {
|
||||
&& beg.getPos() >= text->cursor().pos()) {
|
||||
break;
|
||||
} else if (beg.getPar() != text->cursorPar()) {
|
||||
break;
|
||||
@ -1256,7 +1257,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
|
||||
bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
|
||||
{
|
||||
// not quite sure if we want this...
|
||||
bv_->text()->recUndo(bv_->text()->cursor.par());
|
||||
bv_->text()->recUndo(bv_->text()->cursor().par());
|
||||
freezeUndo();
|
||||
|
||||
bv_->text()->clearSelection();
|
||||
@ -1285,10 +1286,7 @@ bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code,
|
||||
string const & from, string const & to)
|
||||
{
|
||||
bool need_update = false;
|
||||
LyXCursor cursor = bv_->text()->cursor;
|
||||
LyXCursor tmpcursor = cursor;
|
||||
cursor.par(tmpcursor.par());
|
||||
cursor.pos(tmpcursor.pos());
|
||||
LyXCursor cur = bv_->text()->cursor();
|
||||
|
||||
ParIterator end = bv_->buffer()->par_iterator_end();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ private:
|
||||
/// this is used to handle XSelection events in the right manner
|
||||
struct {
|
||||
LyXCursor cursor;
|
||||
LyXCursor selection_cursor;
|
||||
LyXCursor anchor;
|
||||
bool set;
|
||||
} xsel_cache_;
|
||||
///
|
||||
|
@ -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>
|
||||
|
||||
* text2.C (undoSpan): add and use
|
||||
|
@ -128,7 +128,7 @@ PosIterator::PosIterator(ParagraphList * pl, ParagraphList::iterator pit,
|
||||
PosIterator::PosIterator(BufferView & bv)
|
||||
{
|
||||
LyXText * text = bv.getLyXText();
|
||||
lyx::pos_type pos = text->cursor.pos();
|
||||
lyx::pos_type pos = text->cursor().pos();
|
||||
ParagraphList::iterator pit = text->cursorPar();
|
||||
|
||||
ParIterator par = bv.buffer()->par_iterator_begin();
|
||||
|
@ -179,10 +179,10 @@ string const currentState(BufferView * bv)
|
||||
|
||||
LyXText * text = bv->getLyXText();
|
||||
Buffer * buffer = bv->buffer();
|
||||
LyXCursor const & c = text->cursor;
|
||||
LyXCursor const & c = text->cursor();
|
||||
|
||||
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;
|
||||
|
||||
if (show_change) {
|
||||
@ -242,8 +242,8 @@ string const currentState(BufferView * bv)
|
||||
#ifdef DEVEL_VERSION
|
||||
ParagraphList::iterator pit = text->cursorPar();
|
||||
state << _(", Paragraph: ") << pit->id();
|
||||
state << _(", Position: ") << text->cursor.pos();
|
||||
RowList::iterator rit = pit->getRow(text->cursor.pos());
|
||||
state << _(", Position: ") << 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 << _(", Inset: ");
|
||||
InsetOld * inset = pit->inInset();
|
||||
@ -301,7 +301,7 @@ void put_selection_at(BufferView * bv, PosIterator const & cur,
|
||||
text->setSelectionRange(length);
|
||||
text->setSelection();
|
||||
if (backwards)
|
||||
std::swap(text->cursor, text->selection.cursor);
|
||||
std::swap(text->cursor(), text->anchor());
|
||||
}
|
||||
|
||||
bv->fitCursor();
|
||||
|
@ -45,6 +45,11 @@ public:
|
||||
void pop(int depth);
|
||||
/// pop one level off the cursor
|
||||
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
|
||||
void cell(int);
|
||||
/// return the cell this cursor is in
|
||||
|
@ -236,14 +236,14 @@ void InsetText::updateLocal(BufferView * bv)
|
||||
collapseParagraphs(bv);
|
||||
|
||||
if (!text_.selection.set())
|
||||
text_.selection.cursor = text_.cursor;
|
||||
text_.anchor() = text_.cursor();
|
||||
|
||||
bv->owner()->view_state_changed();
|
||||
bv->owner()->updateMenubar();
|
||||
bv->owner()->updateToolbar();
|
||||
if (old_par != text_.cursor.par()) {
|
||||
if (old_par != text_.cursor().par()) {
|
||||
bv->owner()->setLayout(text_.cursorPar()->layout()->name());
|
||||
old_par = text_.cursor.par();
|
||||
old_par = text_.cursor().par();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,7 +394,7 @@ int replace(BufferView * bv,
|
||||
|
||||
text->replaceSelectionWithString(replacestr);
|
||||
text->setSelectionRange(replacestr.length());
|
||||
text->cursor = fw ? text->selEnd() : text->selStart();
|
||||
text->cursor() = fw ? text->selEnd() : text->selStart();
|
||||
|
||||
bv->buffer()->markDirty();
|
||||
find(bv, searchstr, cs, mw, fw);
|
||||
|
@ -158,7 +158,7 @@ void LyXFunc::handleKeyFunc(kb_action action)
|
||||
keyseq.clear();
|
||||
// copied verbatim from do_accent_char
|
||||
view()->update();
|
||||
view()->getLyXText()->selection.cursor = view()->getLyXText()->cursor;
|
||||
view()->getLyXText()->anchor() = view()->getLyXText()->cursor();
|
||||
}
|
||||
|
||||
|
||||
|
@ -406,6 +406,16 @@ public:
|
||||
///
|
||||
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:
|
||||
///
|
||||
int height;
|
||||
|
192
src/text.C
192
src/text.C
@ -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
|
||||
ParagraphList::iterator cpit = cursorPar();
|
||||
if (cursor.pos() && cursor.pos() != cpit->size()
|
||||
&& cpit->isChangeEdited(0, cursor.pos()))
|
||||
if (cursor().pos() && cursor().pos() != cpit->size()
|
||||
&& cpit->isChangeEdited(0, cursor().pos()))
|
||||
return;
|
||||
|
||||
LyXTextClass const & tclass =
|
||||
@ -768,12 +768,12 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
||||
return;
|
||||
|
||||
// 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
|
||||
// It is better to erase the space (Dekel)
|
||||
if (cursor.pos() < cpit->size() && cpit->isLineSeparator(cursor.pos()))
|
||||
cpit->erase(cursor.pos());
|
||||
if (cursor().pos() < cpit->size() && cpit->isLineSeparator(cursor().pos()))
|
||||
cpit->erase(cursor().pos());
|
||||
|
||||
// break the paragraph
|
||||
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)
|
||||
bool const isempty = cpit->allowEmpty() && cpit->empty();
|
||||
::breakParagraph(bv()->buffer()->params(), paragraphs, cpit,
|
||||
cursor.pos(), keep_layout);
|
||||
cursor().pos(), keep_layout);
|
||||
|
||||
cpit = cursorPar();
|
||||
ParagraphList::iterator next_par = boost::next(cpit);
|
||||
|
||||
// well this is the caption hack since one caption is really enough
|
||||
if (layout->labeltype == LABEL_SENSITIVE) {
|
||||
if (!cursor.pos())
|
||||
if (!cursor().pos())
|
||||
// set to standard-layout
|
||||
cpit->applyLayout(tclass.defaultLayout());
|
||||
else
|
||||
@ -806,9 +806,9 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
||||
// move one row up!
|
||||
// This touches only the screen-update. Otherwise we would may have
|
||||
// an empty row on the screen
|
||||
RowList::iterator crit = cpit->getRow(cursor.pos());
|
||||
if (cursor.pos() && crit->pos() == cursor.pos()
|
||||
&& !cpit->isNewline(cursor.pos() - 1))
|
||||
RowList::iterator crit = cpit->getRow(cursor().pos());
|
||||
if (cursor().pos() && crit->pos() == cursor().pos()
|
||||
&& !cpit->isNewline(cursor().pos() - 1))
|
||||
{
|
||||
cursorLeft(bv());
|
||||
}
|
||||
@ -822,7 +822,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
||||
|
||||
// This check is necessary. Otherwise the new empty paragraph will
|
||||
// be deleted automatically. And it is more friendly for the user!
|
||||
if (cursor.pos() || isempty)
|
||||
if (cursor().pos() || isempty)
|
||||
setCursor(next_par, 0);
|
||||
else
|
||||
setCursor(cpit, 0);
|
||||
@ -834,7 +834,7 @@ void LyXText::redoParagraph()
|
||||
{
|
||||
clearSelection();
|
||||
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
|
||||
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,
|
||||
// disable the double-space checking
|
||||
@ -858,35 +858,35 @@ void LyXText::insertChar(char c)
|
||||
if (current_font.number() == LyXFont::ON) {
|
||||
if (!IsDigit(c) && !contains(number_operators, c) &&
|
||||
!(contains(number_seperators, c) &&
|
||||
cursor.pos() >= 1 &&
|
||||
cursor.pos() < cursorPar()->size() &&
|
||||
getFont(cursorPar(), cursor.pos()).number() == LyXFont::ON &&
|
||||
getFont(cursorPar(), cursor.pos() - 1).number() == LyXFont::ON)
|
||||
cursor().pos() >= 1 &&
|
||||
cursor().pos() < cursorPar()->size() &&
|
||||
getFont(cursorPar(), cursor().pos()).number() == LyXFont::ON &&
|
||||
getFont(cursorPar(), cursor().pos() - 1).number() == LyXFont::ON)
|
||||
)
|
||||
number(); // Set current_font.number to OFF
|
||||
} else if (IsDigit(c) &&
|
||||
real_current_font.isVisibleRightToLeft()) {
|
||||
number(); // Set current_font.number to ON
|
||||
|
||||
if (cursor.pos() > 0) {
|
||||
char const c = cursorPar()->getChar(cursor.pos() - 1);
|
||||
if (cursor().pos() > 0) {
|
||||
char const c = cursorPar()->getChar(cursor().pos() - 1);
|
||||
if (contains(number_unary_operators, c) &&
|
||||
(cursor.pos() == 1 ||
|
||||
cursorPar()->isSeparator(cursor.pos() - 2) ||
|
||||
cursorPar()->isNewline(cursor.pos() - 2))
|
||||
(cursor().pos() == 1 ||
|
||||
cursorPar()->isSeparator(cursor().pos() - 2) ||
|
||||
cursorPar()->isNewline(cursor().pos() - 2))
|
||||
) {
|
||||
setCharFont(
|
||||
cursorPar(),
|
||||
cursor.pos() - 1,
|
||||
cursor().pos() - 1,
|
||||
current_font);
|
||||
} else if (contains(number_seperators, c) &&
|
||||
cursor.pos() >= 2 &&
|
||||
cursor().pos() >= 2 &&
|
||||
getFont(
|
||||
cursorPar(),
|
||||
cursor.pos() - 2).number() == LyXFont::ON) {
|
||||
cursor().pos() - 2).number() == LyXFont::ON) {
|
||||
setCharFont(
|
||||
cursorPar(),
|
||||
cursor.pos() - 1,
|
||||
cursor().pos() - 1,
|
||||
current_font);
|
||||
}
|
||||
}
|
||||
@ -910,14 +910,14 @@ void LyXText::insertChar(char c)
|
||||
LyXFont rawtmpfont = current_font;
|
||||
|
||||
if (!freeSpacing && IsLineSeparatorChar(c)) {
|
||||
if ((cursor.pos() > 0
|
||||
&& cursorPar()->isLineSeparator(cursor.pos() - 1))
|
||||
|| (cursor.pos() > 0
|
||||
&& cursorPar()->isNewline(cursor.pos() - 1))
|
||||
|| (cursor.pos() == 0)) {
|
||||
if ((cursor().pos() > 0
|
||||
&& cursorPar()->isLineSeparator(cursor().pos() - 1))
|
||||
|| (cursor().pos() > 0
|
||||
&& cursorPar()->isNewline(cursor().pos() - 1))
|
||||
|| (cursor().pos() == 0)) {
|
||||
static bool sent_space_message = false;
|
||||
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."));
|
||||
else
|
||||
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
|
||||
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;
|
||||
real_current_font = realtmpfont;
|
||||
redoParagraph(cursorPar());
|
||||
setCursor(cursor.par(), cursor.pos() + 1, false, cursor.boundary());
|
||||
setCursor(cursor().par(), cursor().pos() + 1, false, cursor().boundary());
|
||||
|
||||
charInserted();
|
||||
}
|
||||
@ -1079,8 +1079,8 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
|
||||
|
||||
void LyXText::cursorRightOneWord()
|
||||
{
|
||||
cursorRightOneWord(cursor);
|
||||
setCursor(cursorPar(), cursor.pos());
|
||||
cursorRightOneWord(cursor());
|
||||
setCursor(cursorPar(), cursor().pos());
|
||||
}
|
||||
|
||||
|
||||
@ -1088,7 +1088,7 @@ void LyXText::cursorRightOneWord()
|
||||
// of prior word, not to end of next prior word.
|
||||
void LyXText::cursorLeftOneWord()
|
||||
{
|
||||
LyXCursor tmpcursor = cursor;
|
||||
LyXCursor tmpcursor = cursor();
|
||||
cursorLeftOneWord(tmpcursor);
|
||||
setCursor(getPar(tmpcursor), tmpcursor.pos());
|
||||
}
|
||||
@ -1096,14 +1096,14 @@ void LyXText::cursorLeftOneWord()
|
||||
|
||||
void LyXText::selectWord(word_location loc)
|
||||
{
|
||||
LyXCursor from = cursor;
|
||||
LyXCursor to = cursor;
|
||||
LyXCursor from = cursor();
|
||||
LyXCursor to = cursor();
|
||||
getWord(from, to, loc);
|
||||
if (cursor != from)
|
||||
if (cursor() != from)
|
||||
setCursor(from.par(), from.pos());
|
||||
if (to == from)
|
||||
return;
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
setCursor(to.par(), to.pos());
|
||||
setSelection();
|
||||
}
|
||||
@ -1165,12 +1165,12 @@ void LyXText::deleteWordForward()
|
||||
if (cursorPar()->empty())
|
||||
cursorRight(bv());
|
||||
else {
|
||||
LyXCursor tmpcursor = cursor;
|
||||
LyXCursor tmpcursor = cursor();
|
||||
selection.set(true); // to avoid deletion
|
||||
cursorRightOneWord();
|
||||
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
||||
selection.cursor = cursor;
|
||||
cursor = tmpcursor;
|
||||
anchor() = cursor();
|
||||
cursor() = tmpcursor;
|
||||
setSelection();
|
||||
cutSelection(true, false);
|
||||
}
|
||||
@ -1183,12 +1183,12 @@ void LyXText::deleteWordBackward()
|
||||
if (cursorPar()->empty())
|
||||
cursorLeft(bv());
|
||||
else {
|
||||
LyXCursor tmpcursor = cursor;
|
||||
LyXCursor tmpcursor = cursor();
|
||||
selection.set(true); // to avoid deletion
|
||||
cursorLeftOneWord();
|
||||
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
||||
selection.cursor = cursor;
|
||||
cursor = tmpcursor;
|
||||
anchor() = cursor();
|
||||
cursor() = tmpcursor;
|
||||
setSelection();
|
||||
cutSelection(true, false);
|
||||
}
|
||||
@ -1202,12 +1202,12 @@ void LyXText::deleteLineForward()
|
||||
// Paragraph is empty, so we just go to the right
|
||||
cursorRight(bv());
|
||||
} else {
|
||||
LyXCursor tmpcursor = cursor;
|
||||
LyXCursor tmpcursor = cursor();
|
||||
selection.set(true); // to avoid deletion
|
||||
cursorEnd();
|
||||
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
||||
selection.cursor = cursor;
|
||||
cursor = tmpcursor;
|
||||
anchor() = cursor();
|
||||
cursor() = tmpcursor;
|
||||
setSelection();
|
||||
// What is this test for ??? (JMarc)
|
||||
if (!selection.set())
|
||||
@ -1227,7 +1227,7 @@ void LyXText::changeCase(LyXText::TextCase action)
|
||||
from = selStart();
|
||||
to = selEnd();
|
||||
} else {
|
||||
from = cursor;
|
||||
from = cursor();
|
||||
getWord(from, to, lyx::PARTIAL_WORD);
|
||||
setCursor(to.par(), to.pos() + 1);
|
||||
}
|
||||
@ -1270,13 +1270,14 @@ void LyXText::changeCase(LyXText::TextCase action)
|
||||
void LyXText::Delete()
|
||||
{
|
||||
// this is a very easy implementation
|
||||
LyXCursor old_cursor = cursor;
|
||||
LyXCursor 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()) {
|
||||
if (old_cursor.par() != cursor().par() || old_cursor.pos() !=
|
||||
cursor().pos()) {
|
||||
recordUndo(Undo::DELETE, this, old_cursor.par());
|
||||
backspace();
|
||||
}
|
||||
@ -1289,7 +1290,7 @@ void LyXText::backspace()
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type lastpos = pit->size();
|
||||
|
||||
if (cursor.pos() == 0) {
|
||||
if (cursor().pos() == 0) {
|
||||
// The cursor is at the beginning of a paragraph, so
|
||||
// the the backspace will collapse two paragraphs into
|
||||
// one.
|
||||
@ -1307,7 +1308,7 @@ void LyXText::backspace()
|
||||
// left and let the DeleteEmptyParagraphMechanism
|
||||
// handle the actual deletion of the paragraph.
|
||||
|
||||
if (cursor.par()) {
|
||||
if (cursor().par()) {
|
||||
cursorLeft(bv());
|
||||
// the layout things can change the height of a row !
|
||||
redoParagraph();
|
||||
@ -1315,18 +1316,18 @@ void LyXText::backspace()
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor.par() != 0)
|
||||
recordUndo(Undo::DELETE, this, cursor.par() - 1, cursor.par());
|
||||
if (cursor().par() != 0)
|
||||
recordUndo(Undo::DELETE, this, cursor().par() - 1, cursor().par());
|
||||
|
||||
ParagraphList::iterator tmppit = cursorPar();
|
||||
// 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,
|
||||
// without the dreaded mechanism. (JMarc)
|
||||
if (cursor.par() != 0) {
|
||||
if (cursor().par() != 0) {
|
||||
// steps into the above paragraph.
|
||||
setCursorIntern(cursor.par() - 1,
|
||||
getPar(cursor.par() - 1)->size(),
|
||||
setCursorIntern(cursor().par() - 1,
|
||||
getPar(cursor().par() - 1)->size(),
|
||||
false);
|
||||
}
|
||||
|
||||
@ -1345,44 +1346,44 @@ void LyXText::backspace()
|
||||
&& cpit->getAlign() == tmppit->getAlign()) {
|
||||
mergeParagraph(bufparams, buf.paragraphs(), cpit);
|
||||
|
||||
if (cursor.pos() && cpit->isSeparator(cursor.pos() - 1))
|
||||
cursor.pos(cursor.pos() - 1);
|
||||
if (cursor().pos() && cpit->isSeparator(cursor().pos() - 1))
|
||||
cursor().pos(cursor().pos() - 1);
|
||||
|
||||
// the counters may have changed
|
||||
updateCounters();
|
||||
setCursor(cursor.par(), cursor.pos(), false);
|
||||
setCursor(cursor().par(), cursor().pos(), false);
|
||||
}
|
||||
} else {
|
||||
// this is the code for a normal backspace, not pasting
|
||||
// any paragraphs
|
||||
recordUndo(Undo::DELETE, this, cursor.par());
|
||||
recordUndo(Undo::DELETE, this, cursor().par());
|
||||
// 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,
|
||||
// without the dreaded mechanism. (JMarc)
|
||||
setCursorIntern(cursor.par(), cursor.pos() - 1,
|
||||
false, cursor.boundary());
|
||||
cursorPar()->erase(cursor.pos());
|
||||
setCursorIntern(cursor().par(), cursor().pos() - 1,
|
||||
false, cursor().boundary());
|
||||
cursorPar()->erase(cursor().pos());
|
||||
}
|
||||
|
||||
lastpos = cursorPar()->size();
|
||||
if (cursor.pos() == lastpos)
|
||||
if (cursor().pos() == lastpos)
|
||||
setCurrentFont();
|
||||
|
||||
redoParagraph();
|
||||
setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
|
||||
setCursor(cursor().par(), cursor().pos(), false, cursor().boundary());
|
||||
}
|
||||
|
||||
|
||||
ParagraphList::iterator LyXText::cursorPar() const
|
||||
{
|
||||
return getPar(cursor.par());
|
||||
return getPar(cursor().par());
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
{
|
||||
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
|
||||
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
size_t pos = cursor.pos();
|
||||
size_t pos = cur.pos();
|
||||
|
||||
while (pos &&
|
||||
(pit->isSeparator(pos - 1) ||
|
||||
@ -1674,16 +1675,16 @@ void LyXText::cursorLeftOneWord(LyXCursor & cursor)
|
||||
--pos;
|
||||
}
|
||||
|
||||
cursor.par(parOffset(pit));
|
||||
cursor.pos(pos);
|
||||
cur.par(parOffset(pit));
|
||||
cur.pos(pos);
|
||||
}
|
||||
|
||||
|
||||
void LyXText::cursorRightOneWord(LyXCursor & cursor)
|
||||
void LyXText::cursorRightOneWord(LyXCursor & cur)
|
||||
{
|
||||
// treat floats, HFills and Insets as words
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type pos = cursor.pos();
|
||||
pos_type pos = cur.pos();
|
||||
|
||||
if (pos == pit->size() &&
|
||||
boost::next(pit) != paragraphs().end()) {
|
||||
@ -1700,8 +1701,8 @@ void LyXText::cursorRightOneWord(LyXCursor & cursor)
|
||||
}
|
||||
}
|
||||
|
||||
cursor.par(parOffset(pit));
|
||||
cursor.pos(pos);
|
||||
cur.par(parOffset(pit));
|
||||
cur.pos(pos);
|
||||
}
|
||||
|
||||
|
||||
@ -1854,13 +1855,13 @@ int LyXText::descent() const
|
||||
|
||||
int LyXText::cursorX() const
|
||||
{
|
||||
return cursorX(cursor);
|
||||
return cursorX(cursor());
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
LyXCursor & LyXText::cursor()
|
||||
{
|
||||
return cursor_;
|
||||
}
|
||||
|
||||
|
||||
LyXCursor const & LyXText::cursor() const
|
||||
{
|
||||
return cursor_;
|
||||
}
|
||||
|
||||
|
||||
LyXCursor & LyXText::anchor()
|
||||
{
|
||||
return anchor_;
|
||||
}
|
||||
|
||||
|
||||
LyXCursor const & LyXText::anchor() const
|
||||
{
|
||||
return anchor_;
|
||||
}
|
||||
|
||||
|
||||
|
132
src/text2.C
132
src/text2.C
@ -95,7 +95,7 @@ void LyXText::init(BufferView * bview)
|
||||
|
||||
redoParagraphs(beg, end);
|
||||
setCursorIntern(0, 0);
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
|
||||
updateCounters();
|
||||
}
|
||||
@ -217,7 +217,7 @@ void LyXText::setCharFont(
|
||||
InsetOld * LyXText::getInset() const
|
||||
{
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type const pos = cursor.pos();
|
||||
pos_type const pos = cursor().pos();
|
||||
|
||||
if (pos < pit->size() && pit->isInset(pos)) {
|
||||
return pit->getInset(pos);
|
||||
@ -236,7 +236,7 @@ bool LyXText::toggleInset()
|
||||
|
||||
// do we want to keep this?? (JMarc)
|
||||
if (!isHighlyEditableInset(inset))
|
||||
recUndo(cursor.par());
|
||||
recUndo(cursor().par());
|
||||
|
||||
if (inset->isOpen())
|
||||
inset->close();
|
||||
@ -428,7 +428,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
|
||||
if (!selection.set()) {
|
||||
// Determine basis font
|
||||
LyXFont layoutfont;
|
||||
if (cursor.pos() < cursorPar()->beginOfBody())
|
||||
if (cursor().pos() < cursorPar()->beginOfBody())
|
||||
layoutfont = getLabelFont(cursorPar());
|
||||
else
|
||||
layoutfont = getLayoutFont(cursorPar());
|
||||
@ -497,14 +497,14 @@ void LyXText::clearSelection()
|
||||
void LyXText::cursorHome()
|
||||
{
|
||||
ParagraphList::iterator cpit = cursorPar();
|
||||
setCursor(cpit, cpit->getRow(cursor.pos())->pos());
|
||||
setCursor(cpit, cpit->getRow(cursor().pos())->pos());
|
||||
}
|
||||
|
||||
|
||||
void LyXText::cursorEnd()
|
||||
{
|
||||
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
|
||||
// the final space
|
||||
setCursor(cpit, end == cpit->size() ? end : end - 1);
|
||||
@ -538,7 +538,7 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
|
||||
// Try implicit word selection
|
||||
// If there is a change in the language the implicit word selection
|
||||
// is disabled.
|
||||
LyXCursor resetCursor = cursor;
|
||||
LyXCursor resetCursor = cursor();
|
||||
bool implicitSelection =
|
||||
font.language() == ignore_language
|
||||
&& font.number() == LyXFont::IGNORE
|
||||
@ -551,8 +551,8 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
|
||||
//and cursor is set to the original position.
|
||||
if (implicitSelection) {
|
||||
clearSelection();
|
||||
cursor = resetCursor;
|
||||
selection.cursor = cursor;
|
||||
cursor() = resetCursor;
|
||||
anchor() = cursor();
|
||||
}
|
||||
}
|
||||
|
||||
@ -562,7 +562,7 @@ string LyXText::getStringToIndex()
|
||||
// Try implicit word selection
|
||||
// If there is a change in the language the implicit word selection
|
||||
// is disabled.
|
||||
LyXCursor const reset_cursor = cursor;
|
||||
LyXCursor const reset_cursor = cursor();
|
||||
bool const implicitSelection =
|
||||
selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
|
||||
|
||||
@ -575,8 +575,8 @@ string LyXText::getStringToIndex()
|
||||
idxstring = selectionAsString(*bv()->buffer(), false);
|
||||
|
||||
// Reset cursors to their original position.
|
||||
cursor = reset_cursor;
|
||||
selection.cursor = cursor;
|
||||
cursor() = reset_cursor;
|
||||
anchor() = cursor();
|
||||
|
||||
// Clear the implicit selection.
|
||||
if (implicitSelection)
|
||||
@ -919,9 +919,9 @@ void LyXText::insertInset(InsetOld * inset)
|
||||
if (!cursorPar()->insetAllowed(inset->lyxCode()))
|
||||
return;
|
||||
|
||||
recUndo(cursor.par());
|
||||
recUndo(cursor().par());
|
||||
freezeUndo();
|
||||
cursorPar()->insertInset(cursor.pos(), inset);
|
||||
cursorPar()->insertInset(cursor().pos(), inset);
|
||||
// Just to rebreak and refresh correctly.
|
||||
// The character will not be inserted a second time
|
||||
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
|
||||
// it anew. (Lgb)
|
||||
// we prefer the end for when tracking changes
|
||||
cursor.pos(endpos);
|
||||
cursor.par(parOffset(endpit));
|
||||
cursor().pos(endpos);
|
||||
cursor().par(parOffset(endpit));
|
||||
|
||||
// need a valid cursor. (Lgb)
|
||||
clearSelection();
|
||||
@ -1026,7 +1026,7 @@ void LyXText::pasteSelection(size_t sel_index)
|
||||
if (!CutAndPaste::checkPastePossible())
|
||||
return;
|
||||
|
||||
recUndo(cursor.par());
|
||||
recUndo(cursor().par());
|
||||
|
||||
ParagraphList::iterator endpit;
|
||||
PitPosPair ppp;
|
||||
@ -1036,7 +1036,7 @@ void LyXText::pasteSelection(size_t sel_index)
|
||||
boost::tie(ppp, endpit) =
|
||||
CutAndPaste::pasteSelection(*bv()->buffer(),
|
||||
paragraphs(),
|
||||
cursorPar(), cursor.pos(),
|
||||
cursorPar(), cursor().pos(),
|
||||
bv()->buffer()->params().textclass,
|
||||
sel_index, el);
|
||||
bufferErrors(*bv()->buffer(), el);
|
||||
@ -1046,7 +1046,7 @@ void LyXText::pasteSelection(size_t sel_index)
|
||||
|
||||
clearSelection();
|
||||
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
setCursor(ppp.first, ppp.second);
|
||||
setSelection();
|
||||
updateCounters();
|
||||
@ -1058,7 +1058,7 @@ void LyXText::setSelectionRange(lyx::pos_type length)
|
||||
if (!length)
|
||||
return;
|
||||
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
while (length--)
|
||||
cursorRight(true);
|
||||
setSelection();
|
||||
@ -1068,7 +1068,7 @@ void LyXText::setSelectionRange(lyx::pos_type length)
|
||||
// simple replacing. The font of the first selected character is used
|
||||
void LyXText::replaceSelectionWithString(string const & str)
|
||||
{
|
||||
recUndo(cursor.par());
|
||||
recUndo(cursor().par());
|
||||
freezeUndo();
|
||||
|
||||
// Get font setting before we cut
|
||||
@ -1096,10 +1096,10 @@ void LyXText::replaceSelectionWithString(string const & str)
|
||||
void LyXText::insertStringAsLines(string const & str)
|
||||
{
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type pos = cursor.pos();
|
||||
pos_type pos = cursor().pos();
|
||||
ParagraphList::iterator endpit = boost::next(cursorPar());
|
||||
|
||||
recUndo(cursor.par());
|
||||
recUndo(cursor().par());
|
||||
|
||||
// only to be sure, should not be neccessary
|
||||
clearSelection();
|
||||
@ -1107,7 +1107,7 @@ void LyXText::insertStringAsLines(string const & str)
|
||||
bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
|
||||
|
||||
redoParagraphs(cursorPar(), endpit);
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
setCursor(pit, pos);
|
||||
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 boundary)
|
||||
{
|
||||
LyXCursor old_cursor = cursor;
|
||||
LyXCursor old_cursor = cursor();
|
||||
setCursorIntern(par, pos, setfont, boundary);
|
||||
return deleteEmptyParagraphMechanism(old_cursor);
|
||||
}
|
||||
@ -1210,7 +1210,7 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
|
||||
void LyXText::setCursorIntern(paroffset_type par,
|
||||
pos_type pos, bool setfont, bool boundary)
|
||||
{
|
||||
setCursor(cursor, par, pos, boundary);
|
||||
setCursor(cursor(), par, pos, boundary);
|
||||
bv()->x_target(cursorX() + xo_);
|
||||
if (setfont)
|
||||
setCurrentFont();
|
||||
@ -1219,10 +1219,10 @@ void LyXText::setCursorIntern(paroffset_type par,
|
||||
|
||||
void LyXText::setCurrentFont()
|
||||
{
|
||||
pos_type pos = cursor.pos();
|
||||
pos_type pos = cursor().pos();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
|
||||
if (cursor.boundary() && pos > 0)
|
||||
if (cursor().boundary() && pos > 0)
|
||||
--pos;
|
||||
|
||||
if (pos > 0) {
|
||||
@ -1243,9 +1243,9 @@ void LyXText::setCurrentFont()
|
||||
current_font = pit->getFontSettings(bufparams, pos);
|
||||
real_current_font = getFont(pit, pos);
|
||||
|
||||
if (cursor.pos() == pit->size() &&
|
||||
bidi.isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
|
||||
!cursor.boundary()) {
|
||||
if (cursor().pos() == pit->size() &&
|
||||
bidi.isBoundary(*bv()->buffer(), *pit, cursor().pos()) &&
|
||||
!cursor().boundary()) {
|
||||
Language const * lang =
|
||||
pit->getParLanguage(bufparams);
|
||||
current_font.setLanguage(lang);
|
||||
@ -1362,8 +1362,8 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
|
||||
|
||||
void LyXText::setCursorFromCoordinates(int x, int y)
|
||||
{
|
||||
LyXCursor old_cursor = cursor;
|
||||
setCursorFromCoordinates(cursor, x, y);
|
||||
LyXCursor old_cursor = cursor();
|
||||
setCursorFromCoordinates(cursor(), x, y);
|
||||
setCurrentFont();
|
||||
deleteEmptyParagraphMechanism(old_cursor);
|
||||
}
|
||||
@ -1384,9 +1384,9 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
|
||||
|
||||
bool LyXText::checkAndActivateInset(bool front)
|
||||
{
|
||||
if (cursor.pos() == cursorPar()->size())
|
||||
if (cursor().pos() == cursorPar()->size())
|
||||
return false;
|
||||
InsetOld * inset = cursorPar()->getInset(cursor.pos());
|
||||
InsetOld * inset = cursorPar()->getInset(cursor().pos());
|
||||
if (!isHighlyEditableInset(inset))
|
||||
return false;
|
||||
inset->edit(bv(), front);
|
||||
@ -1416,7 +1416,7 @@ DispatchResult LyXText::moveRightIntern(bool front, bool activate_inset, bool se
|
||||
{
|
||||
ParagraphList::iterator c_par = cursorPar();
|
||||
if (boost::next(c_par) == paragraphs().end()
|
||||
&& cursor.pos() >= c_par->size())
|
||||
&& cursor().pos() >= c_par->size())
|
||||
return DispatchResult(false, FINISHED_RIGHT);
|
||||
if (activate_inset && checkAndActivateInset(front))
|
||||
return DispatchResult(true, true);
|
||||
@ -1430,7 +1430,7 @@ DispatchResult LyXText::moveRightIntern(bool front, bool activate_inset, bool se
|
||||
DispatchResult LyXText::moveLeftIntern(bool front,
|
||||
bool activate_inset, bool selecting)
|
||||
{
|
||||
if (cursor.par() == 0 && cursor.pos() <= 0)
|
||||
if (cursor().par() == 0 && cursor().pos() <= 0)
|
||||
return DispatchResult(false, FINISHED);
|
||||
cursorLeft(true);
|
||||
if (!selecting)
|
||||
@ -1463,18 +1463,18 @@ DispatchResult LyXText::moveDown()
|
||||
|
||||
bool LyXText::cursorLeft(bool internal)
|
||||
{
|
||||
if (cursor.pos() > 0) {
|
||||
bool boundary = cursor.boundary();
|
||||
setCursor(cursor.par(), cursor.pos() - 1, true, false);
|
||||
if (cursor().pos() > 0) {
|
||||
bool boundary = cursor().boundary();
|
||||
setCursor(cursor().par(), cursor().pos() - 1, true, false);
|
||||
if (!internal && !boundary &&
|
||||
bidi.isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos() + 1))
|
||||
setCursor(cursor.par(), cursor.pos() + 1, true, true);
|
||||
bidi.isBoundary(*bv()->buffer(), *cursorPar(), cursor().pos() + 1))
|
||||
setCursor(cursor().par(), cursor().pos() + 1, true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cursor.par() != 0) {
|
||||
if (cursor().par() != 0) {
|
||||
// steps into the paragraph above
|
||||
setCursor(cursor.par() - 1, boost::prior(cursorPar())->size());
|
||||
setCursor(cursor().par() - 1, boost::prior(cursorPar())->size());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1484,21 +1484,21 @@ bool LyXText::cursorLeft(bool internal)
|
||||
|
||||
bool LyXText::cursorRight(bool internal)
|
||||
{
|
||||
if (!internal && cursor.boundary()) {
|
||||
setCursor(cursor.par(), cursor.pos(), true, false);
|
||||
if (!internal && cursor().boundary()) {
|
||||
setCursor(cursor().par(), cursor().pos(), true, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cursor.pos() != cursorPar()->size()) {
|
||||
setCursor(cursor.par(), cursor.pos() + 1, true, false);
|
||||
if (cursor().pos() != cursorPar()->size()) {
|
||||
setCursor(cursor().par(), cursor().pos() + 1, true, false);
|
||||
if (!internal && bidi.isBoundary(*bv()->buffer(), *cursorPar(),
|
||||
cursor.pos()))
|
||||
setCursor(cursor.par(), cursor.pos(), true, true);
|
||||
cursor().pos()))
|
||||
setCursor(cursor().par(), cursor().pos(), true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cursor.par() + 1 != int(paragraphs().size())) {
|
||||
setCursor(cursor.par() + 1, 0);
|
||||
if (cursor().par() + 1 != int(paragraphs().size())) {
|
||||
setCursor(cursor().par() + 1, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1541,7 +1541,7 @@ void LyXText::cursorDown(bool selecting)
|
||||
void LyXText::cursorUpParagraph()
|
||||
{
|
||||
ParagraphList::iterator cpit = cursorPar();
|
||||
if (cursor.pos() > 0)
|
||||
if (cursor().pos() > 0)
|
||||
setCursor(cpit, 0);
|
||||
else if (cpit != paragraphs().begin())
|
||||
setCursor(boost::prior(cpit), 0);
|
||||
@ -1620,8 +1620,8 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
|
||||
// MISSING
|
||||
|
||||
// If the pos around the old_cursor were spaces, delete one of them.
|
||||
if (old_cursor.par() != cursor.par()
|
||||
|| old_cursor.pos() != cursor.pos()) {
|
||||
if (old_cursor.par() != cursor().par()
|
||||
|| old_cursor.pos() != cursor().pos()) {
|
||||
|
||||
// Only if the cursor has really moved
|
||||
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)
|
||||
#endif
|
||||
// correct all cursors held by the LyXText
|
||||
fixCursorAfterDelete(cursor, old_cursor);
|
||||
fixCursorAfterDelete(selection.cursor, old_cursor);
|
||||
fixCursorAfterDelete(cursor(), old_cursor);
|
||||
fixCursorAfterDelete(anchor(), old_cursor);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1655,7 +1655,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
|
||||
return false;
|
||||
|
||||
// only do our magic if we changed paragraph
|
||||
if (old_cursor.par() == cursor.par())
|
||||
if (old_cursor.par() == cursor().par())
|
||||
return false;
|
||||
|
||||
// record if we have deleted a paragraph
|
||||
@ -1670,30 +1670,30 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
|
||||
deleted = true;
|
||||
|
||||
bool selection_position_was_oldcursor_position =
|
||||
selection.cursor.par() == old_cursor.par()
|
||||
&& selection.cursor.pos() == old_cursor.pos();
|
||||
anchor().par() == old_cursor.par()
|
||||
&& anchor().pos() == old_cursor.pos();
|
||||
|
||||
tmpcursor = cursor;
|
||||
cursor = old_cursor; // that undo can restore the right cursor position
|
||||
tmpcursor = cursor();
|
||||
cursor() = old_cursor; // that undo can restore the right cursor position
|
||||
|
||||
ParagraphList::iterator endpit = boost::next(old_pit);
|
||||
while (endpit != paragraphs().end() && endpit->getDepth())
|
||||
++endpit;
|
||||
|
||||
recUndo(parOffset(old_pit), parOffset(endpit) - 1);
|
||||
cursor = tmpcursor;
|
||||
cursor() = tmpcursor;
|
||||
|
||||
// cache cursor pit
|
||||
ParagraphList::iterator tmppit = cursorPar();
|
||||
// delete old par
|
||||
paragraphs().erase(old_pit);
|
||||
// update cursor par offset
|
||||
cursor.par(parOffset(tmppit));
|
||||
cursor().par(parOffset(tmppit));
|
||||
redoParagraph();
|
||||
|
||||
if (selection_position_was_oldcursor_position) {
|
||||
// correct selection
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1702,7 +1702,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
|
||||
|
||||
if (old_pit->stripLeadingSpaces()) {
|
||||
redoParagraph(old_pit);
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
102
src/text3.C
102
src/text3.C
@ -91,16 +91,16 @@ namespace {
|
||||
|
||||
if (font.language() != ignore_language ||
|
||||
font.number() != LyXFont::IGNORE) {
|
||||
LyXCursor & cursor = text->cursor;
|
||||
LyXCursor & cur = text->cursor();
|
||||
Paragraph & par = *text->cursorPar();
|
||||
text->bidi.computeTables(par, *bv->buffer(),
|
||||
*par.getRow(cursor.pos()));
|
||||
if (cursor.boundary() !=
|
||||
*par.getRow(cur.pos()));
|
||||
if (cur.boundary() !=
|
||||
text->bidi.isBoundary(*bv->buffer(), par,
|
||||
cursor.pos(),
|
||||
cur.pos(),
|
||||
text->real_current_font))
|
||||
text->setCursor(cursor.par(), cursor.pos(),
|
||||
false, !cursor.boundary());
|
||||
text->setCursor(cur.par(), cur.pos(),
|
||||
false, !cur.boundary());
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ namespace {
|
||||
LyXText * lt = bv->getLyXText();
|
||||
|
||||
// if (!lt->selection.set())
|
||||
// lt->selection.cursor = lt->cursor;
|
||||
// lt->selection.cursor = lt->cursor();
|
||||
|
||||
if (selecting || lt->selection.mark())
|
||||
lt->setSelection();
|
||||
@ -294,7 +294,7 @@ bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
|
||||
{
|
||||
ParagraphList::iterator end = paragraphs().end();
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
pos_type pos = cursor.pos();
|
||||
pos_type pos = cursor().pos();
|
||||
|
||||
InsetOld * inset;
|
||||
do {
|
||||
@ -327,21 +327,21 @@ void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
|
||||
clearSelection();
|
||||
|
||||
string contents;
|
||||
if (same_content && cursor.pos() < cursorPar()->size()
|
||||
&& cursorPar()->isInset(cursor.pos())) {
|
||||
InsetOld const * inset = cursorPar()->getInset(cursor.pos());
|
||||
if (same_content && cursor().pos() < cursorPar()->size()
|
||||
&& cursorPar()->isInset(cursor().pos())) {
|
||||
InsetOld const * inset = cursorPar()->getInset(cursor().pos());
|
||||
if (find(codes.begin(), codes.end(), inset->lyxCode())
|
||||
!= codes.end())
|
||||
contents = static_cast<InsetCommand const *>(inset)->getContents();
|
||||
}
|
||||
|
||||
if (!gotoNextInset(codes, contents)) {
|
||||
if (cursor.pos() || cursorPar() != paragraphs().begin()) {
|
||||
LyXCursor tmp = cursor;
|
||||
cursor.par(0);
|
||||
cursor.pos(0);
|
||||
if (cursor().pos() || cursorPar() != paragraphs().begin()) {
|
||||
LyXCursor tmp = cursor();
|
||||
cursor().par(0);
|
||||
cursor().pos(0);
|
||||
if (!gotoNextInset(codes, contents)) {
|
||||
cursor = tmp;
|
||||
cursor() = tmp;
|
||||
bv()->owner()->message(_("No more insets"));
|
||||
}
|
||||
} else {
|
||||
@ -349,7 +349,7 @@ void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
|
||||
}
|
||||
}
|
||||
bv()->update();
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
}
|
||||
|
||||
|
||||
@ -543,7 +543,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
|
||||
case LFUN_RIGHTSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
if (rtl())
|
||||
cursorLeft(bv);
|
||||
else
|
||||
@ -553,7 +553,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
|
||||
case LFUN_LEFTSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
if (rtl())
|
||||
cursorRight(bv);
|
||||
else
|
||||
@ -563,56 +563,56 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
|
||||
case LFUN_UPSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorUp(true);
|
||||
finishChange(bv, true);
|
||||
break;
|
||||
|
||||
case LFUN_DOWNSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorDown(true);
|
||||
finishChange(bv, true);
|
||||
break;
|
||||
|
||||
case LFUN_UP_PARAGRAPHSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorUpParagraph();
|
||||
finishChange(bv, true);
|
||||
break;
|
||||
|
||||
case LFUN_DOWN_PARAGRAPHSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorDownParagraph();
|
||||
finishChange(bv, true);
|
||||
break;
|
||||
|
||||
case LFUN_PRIORSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorPrevious();
|
||||
finishChange(bv, true);
|
||||
break;
|
||||
|
||||
case LFUN_NEXTSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorNext();
|
||||
finishChange(bv, true);
|
||||
break;
|
||||
|
||||
case LFUN_HOMESEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorHome();
|
||||
finishChange(bv, true);
|
||||
break;
|
||||
|
||||
case LFUN_ENDSEL:
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorEnd();
|
||||
finishChange(bv, true);
|
||||
break;
|
||||
@ -634,7 +634,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_WORDSEL: {
|
||||
LyXCursor cur1 = cursor;
|
||||
LyXCursor cur1 = cursor();
|
||||
LyXCursor cur2;
|
||||
getWord(cur1, cur2, lyx::WHOLE_WORD);
|
||||
setCursor(cur1.par(), cur1.pos());
|
||||
@ -710,7 +710,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
lyx::pos_type body = cursorPar()->beginOfBody();
|
||||
|
||||
// Not allowed by LaTeX (labels or empty par)
|
||||
if (cursor.pos() <= body)
|
||||
if (cursor().pos() <= body)
|
||||
break;
|
||||
|
||||
replaceSelection(bv->getLyXText());
|
||||
@ -722,7 +722,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_DELETE:
|
||||
if (!selection.set()) {
|
||||
Delete();
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
// It is possible to make it a lot faster still
|
||||
// just comment out the line below...
|
||||
} else {
|
||||
@ -735,14 +735,14 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_DELETE_SKIP:
|
||||
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
|
||||
if (!selection.set()) {
|
||||
if (cursor.pos() == cursorPar()->size()) {
|
||||
if (cursor().pos() == cursorPar()->size()) {
|
||||
cursorRight(bv);
|
||||
cursorLeft(bv);
|
||||
Delete();
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
} else {
|
||||
Delete();
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
}
|
||||
} else {
|
||||
cutSelection(true, false);
|
||||
@ -755,7 +755,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
if (!selection.set()) {
|
||||
if (bv->owner()->getIntl().getTransManager().backspace()) {
|
||||
backspace();
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
// It is possible to make it a lot faster still
|
||||
// just comment out the line below...
|
||||
}
|
||||
@ -770,9 +770,9 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_BACKSPACE_SKIP:
|
||||
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
|
||||
if (!selection.set()) {
|
||||
LyXCursor cur = cursor;
|
||||
LyXCursor cur = cursor();
|
||||
backspace();
|
||||
selection.cursor = cur;
|
||||
anchor() = cur;
|
||||
} else {
|
||||
cutSelection(true, false);
|
||||
}
|
||||
@ -783,7 +783,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
replaceSelection(bv->getLyXText());
|
||||
breakParagraph(bv->buffer()->paragraphs(), 0);
|
||||
bv->update();
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
bv->switchKeyMap();
|
||||
bv->owner()->view_state_changed();
|
||||
break;
|
||||
@ -792,7 +792,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
replaceSelection(bv->getLyXText());
|
||||
breakParagraph(bv->buffer()->paragraphs(), 1);
|
||||
bv->update();
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
bv->switchKeyMap();
|
||||
bv->owner()->view_state_changed();
|
||||
break;
|
||||
@ -801,7 +801,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
// When at the beginning of a paragraph, remove
|
||||
// indentation and add a "defskip" at the top.
|
||||
// Otherwise, do the same as LFUN_BREAKPARAGRAPH.
|
||||
LyXCursor cur = cursor;
|
||||
LyXCursor cur = cursor();
|
||||
replaceSelection(bv->getLyXText());
|
||||
if (cur.pos() == 0) {
|
||||
ParagraphParameters & params = getPar(cur)->params();
|
||||
@ -813,7 +813,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
breakParagraph(bv->buffer()->paragraphs(), 0);
|
||||
}
|
||||
bv->update();
|
||||
selection.cursor = cur;
|
||||
anchor() = cur;
|
||||
bv->switchKeyMap();
|
||||
bv->owner()->view_state_changed();
|
||||
break;
|
||||
@ -924,7 +924,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_MARK_OFF:
|
||||
clearSelection();
|
||||
bv->update();
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cmd.message(N_("Mark off"));
|
||||
break;
|
||||
|
||||
@ -932,7 +932,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
clearSelection();
|
||||
selection.mark(true);
|
||||
bv->update();
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cmd.message(N_("Mark on"));
|
||||
break;
|
||||
|
||||
@ -944,7 +944,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
selection.mark(true);
|
||||
cmd.message(N_("Mark set"));
|
||||
}
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
bv->update();
|
||||
break;
|
||||
|
||||
@ -964,7 +964,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_TRANSPOSE_CHARS:
|
||||
recUndo(cursor.par());
|
||||
recUndo(cursor().par());
|
||||
redoParagraph();
|
||||
bv->update();
|
||||
break;
|
||||
@ -998,7 +998,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
if (in_inset_)
|
||||
return DispatchResult(false);
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorTop();
|
||||
finishChange(bv, true);
|
||||
break;
|
||||
@ -1007,7 +1007,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
if (in_inset_)
|
||||
return DispatchResult(false);
|
||||
if (!selection.set())
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorBottom();
|
||||
finishChange(bv, true);
|
||||
break;
|
||||
@ -1135,7 +1135,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
case LFUN_QUOTE: {
|
||||
replaceSelection(bv->getLyXText());
|
||||
ParagraphList::iterator pit = cursorPar();
|
||||
lyx::pos_type pos = cursor.pos();
|
||||
lyx::pos_type pos = cursor().pos();
|
||||
char c;
|
||||
if (!pos)
|
||||
c = ' ';
|
||||
@ -1171,7 +1171,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
for (int i = 0; i < datetmp_len; i++)
|
||||
insertChar(datetmp[i]);
|
||||
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
moveCursor(bv, false);
|
||||
break;
|
||||
}
|
||||
@ -1182,7 +1182,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
if (cmd.button() == mouse_button::button1) {
|
||||
selection_possible = true;
|
||||
cursorHome();
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
cursorEnd();
|
||||
setSelection();
|
||||
bv->haveSelection(selection.set());
|
||||
@ -1270,7 +1270,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
}
|
||||
|
||||
setCursorFromCoordinates(cmd.x, cmd.y);
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
finishUndo();
|
||||
bv->x_target(cursorX() + xo_);
|
||||
|
||||
@ -1340,7 +1340,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
|
||||
bv->owner()->getIntl().getTransManager().
|
||||
TranslateAndInsert(*cit, this);
|
||||
|
||||
selection.cursor = cursor;
|
||||
anchor() = cursor();
|
||||
moveCursor(bv, false);
|
||||
|
||||
// real_current_font.number can change so we need to
|
||||
|
@ -9,7 +9,6 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "textcursor.h"
|
||||
|
||||
@ -17,30 +16,33 @@
|
||||
LyXCursor const & TextCursor::selStart() const
|
||||
{
|
||||
if (!selection.set())
|
||||
return cursor;
|
||||
return std::min(selection.cursor, cursor);
|
||||
return cursor_;
|
||||
// can't use std::min as this creates a new object
|
||||
return anchor_ < cursor_ ? anchor_ : cursor_;
|
||||
}
|
||||
|
||||
|
||||
LyXCursor const & TextCursor::selEnd() const
|
||||
{
|
||||
if (!selection.set())
|
||||
return cursor;
|
||||
return std::max(selection.cursor, cursor);
|
||||
return cursor_;
|
||||
return anchor_ > cursor_ ? anchor_ : cursor_;
|
||||
}
|
||||
|
||||
|
||||
LyXCursor & TextCursor::selStart()
|
||||
{
|
||||
TextCursor const & t = *this;
|
||||
return const_cast<LyXCursor &>(t.selStart());
|
||||
if (!selection.set())
|
||||
return cursor_;
|
||||
return anchor_ < cursor_ ? anchor_ : cursor_;
|
||||
}
|
||||
|
||||
|
||||
LyXCursor & TextCursor::selEnd()
|
||||
{
|
||||
TextCursor const & t = *this;
|
||||
return const_cast<LyXCursor &>(t.selEnd());
|
||||
if (!selection.set())
|
||||
return cursor_;
|
||||
return anchor_ > cursor_ ? anchor_ : cursor_;
|
||||
}
|
||||
|
||||
|
||||
@ -48,18 +50,15 @@ void TextCursor::setSelection()
|
||||
{
|
||||
selection.set(true);
|
||||
// a selection with no contents is not a selection
|
||||
if (cursor.par() == selection.cursor.par() &&
|
||||
cursor.pos() == selection.cursor.pos())
|
||||
{
|
||||
if (cursor_.par() == anchor_.par() && cursor_.pos() == anchor_.pos())
|
||||
selection.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TextCursor::clearSelection()
|
||||
{
|
||||
selection.set(false);
|
||||
selection.mark(false);
|
||||
selection.cursor = cursor;
|
||||
anchor_ = cursor_;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,6 @@ struct Selection {
|
||||
void mark(bool m) {
|
||||
mark_ = m;
|
||||
}
|
||||
LyXCursor cursor; // the other end of the selection
|
||||
private:
|
||||
bool set_; // former selection
|
||||
bool mark_; // former mark_set
|
||||
@ -64,7 +63,9 @@ struct TextCursor {
|
||||
void clearSelection();
|
||||
|
||||
// actual cursor position
|
||||
LyXCursor cursor;
|
||||
LyXCursor cursor_;
|
||||
// the other end of the selection
|
||||
LyXCursor anchor_;
|
||||
|
||||
Selection selection;
|
||||
|
||||
|
14
src/undo.C
14
src/undo.C
@ -121,7 +121,7 @@ void recordUndo(Undo::undo_kind kind,
|
||||
int textnum;
|
||||
ParIterator pit = text2pit(buf, text, textnum);
|
||||
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;
|
||||
|
||||
// record the relevant paragraphs
|
||||
@ -178,12 +178,12 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo)
|
||||
<< std::endl;
|
||||
|
||||
// set cursor again to force the position to be the right one
|
||||
text->cursor.par(undo.cursor_par);
|
||||
text->cursor.pos(undo.cursor_pos);
|
||||
text->cursor().par(undo.cursor_par);
|
||||
text->cursor().pos(undo.cursor_pos);
|
||||
|
||||
// clear any selection
|
||||
text->clearSelection();
|
||||
text->selection.cursor = text->cursor;
|
||||
text->anchor() = text->cursor();
|
||||
text->updateCounters();
|
||||
|
||||
// rebreak the entire lyxtext
|
||||
@ -225,8 +225,8 @@ bool textUndoOrRedo(BufferView * bv,
|
||||
otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last);
|
||||
}
|
||||
LyXText * text = pit.text(buf);
|
||||
otherstack.top().cursor_pos = text->cursor.pos();
|
||||
otherstack.top().cursor_par = text->cursor.par();
|
||||
otherstack.top().cursor_pos = text->cursor().pos();
|
||||
otherstack.top().cursor_par = text->cursor().par();
|
||||
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)
|
||||
{
|
||||
recordUndo(kind, bv->text(), bv->text()->cursor.par());
|
||||
recordUndo(kind, bv->text(), bv->text()->cursor().par());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user