mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-13 22:49:20 +00:00
add LCursor & parameter to cursor moving functions
additional small stuff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8424 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4da45fc728
commit
df974a3904
@ -264,7 +264,7 @@ bool BufferView::insertLyXFile(string const & filen)
|
|||||||
string const fname = MakeAbsPath(filen);
|
string const fname = MakeAbsPath(filen);
|
||||||
|
|
||||||
cursor().clearSelection();
|
cursor().clearSelection();
|
||||||
text()->breakParagraph(buffer()->paragraphs());
|
text()->breakParagraph(cursor());
|
||||||
|
|
||||||
bool res = buffer()->readFile(fname, text()->cursorPar());
|
bool res = buffer()->readFile(fname, text()->cursorPar());
|
||||||
resize();
|
resize();
|
||||||
@ -299,7 +299,9 @@ void BufferView::setCursorFromRow(int row)
|
|||||||
if (tmpid == -1)
|
if (tmpid == -1)
|
||||||
text()->setCursor(0, 0);
|
text()->setCursor(0, 0);
|
||||||
else
|
else
|
||||||
text()->setCursor(buffer()->getParFromID(tmpid).pit(), tmppos);
|
text()->setCursor(
|
||||||
|
text()->parOffset(buffer()->getParFromID(tmpid).pit()),
|
||||||
|
tmppos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -334,7 +336,7 @@ void BufferView::replaceWord(string const & replacestring)
|
|||||||
|
|
||||||
// Go back so that replacement string is also spellchecked
|
// Go back so that replacement string is also spellchecked
|
||||||
for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
|
for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
|
||||||
t->cursorLeft(this);
|
t->cursorLeft(cursor(), this);
|
||||||
|
|
||||||
// FIXME: should be done through LFUN
|
// FIXME: should be done through LFUN
|
||||||
buffer()->markDirty();
|
buffer()->markDirty();
|
||||||
@ -417,7 +419,7 @@ void BufferView::setCursor(ParIterator const & par,
|
|||||||
(*positions[i].it)->inset->edit(cur, true);
|
(*positions[i].it)->inset->edit(cur, true);
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
LyXText * lt = par.text(*buffer());
|
LyXText * lt = par.text(*buffer());
|
||||||
lt->setCursor(par.pit(), pos);
|
lt->setCursor(lt->parOffset(par.pit()), pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -449,7 +451,7 @@ void BufferView::putSelectionAt(PosIterator const & cur,
|
|||||||
if (par.inset())
|
if (par.inset())
|
||||||
top_y(par.outerPar()->y);
|
top_y(par.outerPar()->y);
|
||||||
update();
|
update();
|
||||||
text->setCursor(cur.pit(), cur.pos());
|
text->setCursor(text->parOffset(cur.pit()), cur.pos());
|
||||||
cursor().updatePos();
|
cursor().updatePos();
|
||||||
|
|
||||||
if (length) {
|
if (length) {
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
#include "undo.h"
|
#include "undo.h"
|
||||||
#include "vspace.h"
|
#include "vspace.h"
|
||||||
|
|
||||||
#include "insets/insetfloatlist.h"
|
|
||||||
#include "insets/insetref.h"
|
#include "insets/insetref.h"
|
||||||
|
|
||||||
#include "frontends/Alert.h"
|
#include "frontends/Alert.h"
|
||||||
@ -346,7 +345,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
|
|||||||
|
|
||||||
// Don't forget to update the Layout
|
// Don't forget to update the Layout
|
||||||
if (buffer_)
|
if (buffer_)
|
||||||
owner_->setLayout(bv_->text()->cursorPar()->layout()->name());
|
owner_->setLayout(bv_->text()->getPar(0)->layout()->name());
|
||||||
|
|
||||||
if (lyx::graphics::Previews::activated() && buffer_)
|
if (lyx::graphics::Previews::activated() && buffer_)
|
||||||
lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
|
lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
|
||||||
@ -684,7 +683,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
|
|||||||
if (par == buffer_->par_iterator_end())
|
if (par == buffer_->par_iterator_end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bv_->text()->setCursor(par.pit(),
|
bv_->text()->setCursor(bv_->text()->parOffset(par.pit()),
|
||||||
min(par->size(), saved_positions[i].par_pos));
|
min(par->size(), saved_positions[i].par_pos));
|
||||||
|
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
@ -745,15 +744,6 @@ void BufferView::Pimpl::stuffClipboard(string const & stuff) const
|
|||||||
|
|
||||||
InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
|
InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
CursorSlice cursor = bv_->getLyXText()->cursor;
|
|
||||||
Buffer::inset_iterator it =
|
|
||||||
find_if(Buffer::inset_iterator(
|
|
||||||
cursorPar(), cursor().pos()),
|
|
||||||
buffer_->inset_iterator_end(),
|
|
||||||
lyx::compare_memfun(&Inset::lyxCode, code));
|
|
||||||
return it != buffer_->inset_iterator_end() ? (*it) : 0;
|
|
||||||
#else
|
|
||||||
// Ok, this is a little bit too brute force but it
|
// Ok, this is a little bit too brute force but it
|
||||||
// should work for now. Better infrastructure is coming. (Lgb)
|
// should work for now. Better infrastructure is coming. (Lgb)
|
||||||
|
|
||||||
@ -788,7 +778,6 @@ InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1063,32 +1052,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_FLOAT_LIST:
|
|
||||||
if (tclass.floats().typeExist(cmd.argument)) {
|
|
||||||
InsetBase * inset = new InsetFloatList(cmd.argument);
|
|
||||||
|
|
||||||
// not quite sure if we want this...
|
|
||||||
bv_->text()->recUndo(bv_->text()->cursor().par());
|
|
||||||
freezeUndo();
|
|
||||||
|
|
||||||
cur.clearSelection();
|
|
||||||
bv_->text()->breakParagraph(bv_->buffer()->paragraphs());
|
|
||||||
|
|
||||||
if (!bv_->text()->cursorPar()->empty()) {
|
|
||||||
bv_->text()->cursorLeft(true);
|
|
||||||
bv_->text()->breakParagraph(bv_->buffer()->paragraphs());
|
|
||||||
}
|
|
||||||
|
|
||||||
bv_->text()->setLayout(tclass.defaultLayoutName());
|
|
||||||
bv_->text()->setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
|
|
||||||
bv_->getLyXText()->insertInset(inset);
|
|
||||||
unFreezeUndo();
|
|
||||||
} else {
|
|
||||||
lyxerr << "Non-existent float type: "
|
|
||||||
<< cmd.argument << endl;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LFUN_PARAGRAPH_APPLY:
|
case LFUN_PARAGRAPH_APPLY:
|
||||||
setParagraphParams(*bv_, cmd.argument);
|
setParagraphParams(*bv_, cmd.argument);
|
||||||
break;
|
break;
|
||||||
|
@ -1,4 +1,19 @@
|
|||||||
|
|
||||||
|
2004-02-12 André Pönitz <poenitz@gmx.net>
|
||||||
|
|
||||||
|
* lyxtext.h:
|
||||||
|
* text.C:
|
||||||
|
* text2.C:
|
||||||
|
* text3.C: add LCursor & parameter to most cursor movement functions
|
||||||
|
|
||||||
|
* cursor.[Ch]: add textRow() needed members
|
||||||
|
|
||||||
|
* BufferView.C:
|
||||||
|
* BufferView_pimpl.C:
|
||||||
|
* paragraph.[Ch]:
|
||||||
|
* BufferView.C:
|
||||||
|
* BufferView_pimpl.C: adjust
|
||||||
|
|
||||||
2004-02-11 André Pönitz <poenitz@gmx.net>
|
2004-02-11 André Pönitz <poenitz@gmx.net>
|
||||||
|
|
||||||
* lyxfunc.C:
|
* lyxfunc.C:
|
||||||
|
12
src/cursor.C
12
src/cursor.C
@ -482,6 +482,18 @@ Paragraph const & LCursor::paragraph() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Row & LCursor::textRow()
|
||||||
|
{
|
||||||
|
return *paragraph().getRow(pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Row const & LCursor::textRow() const
|
||||||
|
{
|
||||||
|
return *paragraph().getRow(pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LCursor::par_type LCursor::lastpar() const
|
LCursor::par_type LCursor::lastpar() const
|
||||||
{
|
{
|
||||||
return inMathed() ? 0 : text()->paragraphs().size() - 1;
|
return inMathed() ? 0 : text()->paragraphs().size() - 1;
|
||||||
|
16
src/cursor.h
16
src/cursor.h
@ -25,18 +25,16 @@ class FuncRequest;
|
|||||||
class InsetTabular;
|
class InsetTabular;
|
||||||
class LyXText;
|
class LyXText;
|
||||||
class Paragraph;
|
class Paragraph;
|
||||||
|
class Row;
|
||||||
|
|
||||||
|
|
||||||
// these should go
|
// these should go
|
||||||
class MathHullInset;
|
class MathHullInset;
|
||||||
class PainterInfo;
|
|
||||||
class MathUnknownInset;
|
class MathUnknownInset;
|
||||||
class MathGridInset;
|
class MathGridInset;
|
||||||
|
|
||||||
|
|
||||||
// only needed for gcc 2.95, remove when support terminated
|
// only needed for gcc 2.95, remove when support terminated
|
||||||
|
|
||||||
|
|
||||||
template <typename A, typename B>
|
template <typename A, typename B>
|
||||||
bool ptr_cmp(A const * a, B const * b)
|
bool ptr_cmp(A const * a, B const * b)
|
||||||
{
|
{
|
||||||
@ -218,14 +216,18 @@ public:
|
|||||||
|
|
||||||
//
|
//
|
||||||
// text-specific part
|
// text-specific part
|
||||||
///
|
/// see comment for boundary_ below
|
||||||
bool boundary() const { return current().boundary(); }
|
bool boundary() const { return current().boundary(); }
|
||||||
///
|
/// see comment for boundary_ below
|
||||||
bool & boundary() { return current().boundary(); }
|
bool & boundary() { return current().boundary(); }
|
||||||
///
|
/// the paragraph we're in
|
||||||
Paragraph & paragraph();
|
Paragraph & paragraph();
|
||||||
///
|
/// the paragraph we're in
|
||||||
Paragraph const & paragraph() const;
|
Paragraph const & paragraph() const;
|
||||||
|
/// the row in the paragraph we're in
|
||||||
|
Row & textRow();
|
||||||
|
/// the row in the paragraph we're in
|
||||||
|
Row const & textRow() const;
|
||||||
///
|
///
|
||||||
LyXText * text() const;
|
LyXText * text() const;
|
||||||
///
|
///
|
||||||
|
@ -69,7 +69,7 @@ public:
|
|||||||
LyXFont const & font, bool toggleall);
|
LyXFont const & font, bool toggleall);
|
||||||
|
|
||||||
/// what you expect when pressing <enter> at cursor position
|
/// what you expect when pressing <enter> at cursor position
|
||||||
void breakParagraph(ParagraphList & paragraphs, char keep_layout = 0);
|
void breakParagraph(LCursor & cur, char keep_layout = 0);
|
||||||
|
|
||||||
/** set layout over selection and make a total rebreak of
|
/** set layout over selection and make a total rebreak of
|
||||||
those paragraphs
|
those paragraphs
|
||||||
@ -169,8 +169,6 @@ public:
|
|||||||
/// reject selected change
|
/// reject selected change
|
||||||
void rejectChange();
|
void rejectChange();
|
||||||
|
|
||||||
///
|
|
||||||
void setCursor(ParagraphList::iterator pit, lyx::pos_type pos);
|
|
||||||
/// returns true if par was empty and was removed
|
/// returns true if par was empty and was removed
|
||||||
bool setCursor(lyx::paroffset_type par, lyx::pos_type pos,
|
bool setCursor(lyx::paroffset_type par, lyx::pos_type pos,
|
||||||
bool setfont = true, bool boundary = false);
|
bool setfont = true, bool boundary = false);
|
||||||
@ -194,37 +192,37 @@ public:
|
|||||||
///
|
///
|
||||||
void edit(LCursor & cur, int x, int y);
|
void edit(LCursor & cur, int x, int y);
|
||||||
///
|
///
|
||||||
void cursorUp(bool selecting = false);
|
void cursorUp(LCursor & cur, bool selecting = false);
|
||||||
///
|
///
|
||||||
void cursorDown(bool selecting = false);
|
void cursorDown(LCursor & cur, bool selecting = false);
|
||||||
///
|
///
|
||||||
bool cursorLeft(bool internal = true);
|
bool cursorLeft(LCursor & cur, bool internal = true);
|
||||||
///
|
///
|
||||||
bool cursorRight(bool internal = true);
|
bool cursorRight(LCursor & cur, bool internal = true);
|
||||||
///
|
///
|
||||||
void cursorLeftOneWord();
|
void cursorLeftOneWord(LCursor & cur);
|
||||||
///
|
///
|
||||||
void cursorRightOneWord();
|
void cursorRightOneWord(LCursor & cur);
|
||||||
///
|
///
|
||||||
void cursorUpParagraph();
|
void cursorUpParagraph(LCursor & cur);
|
||||||
///
|
///
|
||||||
void cursorDownParagraph();
|
void cursorDownParagraph(LCursor & cur);
|
||||||
///
|
///
|
||||||
void cursorHome();
|
void cursorHome(LCursor & cur);
|
||||||
///
|
///
|
||||||
void cursorEnd();
|
void cursorEnd(LCursor & cur);
|
||||||
///
|
///
|
||||||
void cursorPrevious();
|
void cursorPrevious(LCursor & cur);
|
||||||
///
|
///
|
||||||
void cursorNext();
|
void cursorNext(LCursor & cur);
|
||||||
///
|
///
|
||||||
void cursorTop();
|
void cursorTop(LCursor & cur);
|
||||||
///
|
///
|
||||||
void cursorBottom();
|
void cursorBottom(LCursor & cur);
|
||||||
///
|
///
|
||||||
void Delete();
|
void Delete(LCursor & cur);
|
||||||
///
|
///
|
||||||
void backspace();
|
void backspace(LCursor & cur);
|
||||||
///
|
///
|
||||||
bool selectWordWhenUnderCursor(lyx::word_location);
|
bool selectWordWhenUnderCursor(lyx::word_location);
|
||||||
///
|
///
|
||||||
@ -342,27 +340,23 @@ public:
|
|||||||
|
|
||||||
///
|
///
|
||||||
double spacing(Paragraph const &) const;
|
double spacing(Paragraph const &) const;
|
||||||
///
|
|
||||||
void cursorLeftOneWord(CursorSlice &);
|
|
||||||
///
|
|
||||||
void cursorRightOneWord(CursorSlice &);
|
|
||||||
|
|
||||||
///
|
///
|
||||||
DispatchResult moveRight();
|
DispatchResult moveRight(LCursor & cur);
|
||||||
///
|
///
|
||||||
DispatchResult moveLeft();
|
DispatchResult moveLeft(LCursor & cur);
|
||||||
///
|
///
|
||||||
DispatchResult moveRightIntern(bool front,
|
DispatchResult moveRightIntern(LCursor & cur, bool front,
|
||||||
bool activate_inset, bool selecting);
|
bool activate_inset, bool selecting);
|
||||||
///
|
///
|
||||||
DispatchResult moveLeftIntern(bool front,
|
DispatchResult moveLeftIntern(LCursor & cur, bool front,
|
||||||
bool activate_inset, bool selecting);
|
bool activate_inset, bool selecting);
|
||||||
///
|
///
|
||||||
DispatchResult moveUp();
|
DispatchResult moveUp(LCursor & cur);
|
||||||
///
|
///
|
||||||
DispatchResult moveDown();
|
DispatchResult moveDown(LCursor & cur);
|
||||||
///
|
///
|
||||||
bool checkAndActivateInset(bool front);
|
bool checkAndActivateInset(LCursor & cur, bool front);
|
||||||
|
|
||||||
///
|
///
|
||||||
void write(Buffer const & buf, std::ostream & os) const;
|
void write(Buffer const & buf, std::ostream & os) const;
|
||||||
@ -442,11 +436,11 @@ private:
|
|||||||
///
|
///
|
||||||
void setCounter(Buffer const &, ParagraphList::iterator pit);
|
void setCounter(Buffer const &, ParagraphList::iterator pit);
|
||||||
///
|
///
|
||||||
void deleteWordForward();
|
void deleteWordForward(LCursor & cur);
|
||||||
///
|
///
|
||||||
void deleteWordBackward();
|
void deleteWordBackward(LCursor & cur);
|
||||||
///
|
///
|
||||||
void deleteLineForward();
|
void deleteLineForward(LCursor & cur);
|
||||||
|
|
||||||
/// sets row.end to the pos value *after* which a row should break.
|
/// sets row.end to the pos value *after* which a row should break.
|
||||||
/// for example, the pos after which isNewLine(pos) == true
|
/// for example, the pos after which isNewLine(pos) == true
|
||||||
|
@ -1830,6 +1830,18 @@ RowList::iterator Paragraph::getRow(pos_type pos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RowList::const_iterator Paragraph::getRow(pos_type pos) const
|
||||||
|
{
|
||||||
|
RowList::const_iterator rit = rows.end();
|
||||||
|
RowList::const_iterator const begin = rows.begin();
|
||||||
|
|
||||||
|
for (--rit; rit != begin && rit->pos() > pos; --rit)
|
||||||
|
;
|
||||||
|
|
||||||
|
return rit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t Paragraph::row(pos_type pos) const
|
size_t Paragraph::row(pos_type pos) const
|
||||||
{
|
{
|
||||||
RowList::const_iterator rit = rows.end();
|
RowList::const_iterator rit = rows.end();
|
||||||
|
@ -330,6 +330,8 @@ public:
|
|||||||
///
|
///
|
||||||
RowList::iterator getRow(lyx::pos_type pos);
|
RowList::iterator getRow(lyx::pos_type pos);
|
||||||
///
|
///
|
||||||
|
RowList::const_iterator getRow(lyx::pos_type pos) const;
|
||||||
|
///
|
||||||
size_t row(lyx::pos_type pos) const;
|
size_t row(lyx::pos_type pos) const;
|
||||||
|
|
||||||
///
|
///
|
||||||
|
284
src/text.C
284
src/text.C
@ -752,31 +752,33 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
void LyXText::breakParagraph(LCursor & cur, 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();
|
Paragraph & cpar = cur.paragraph();
|
||||||
if (cursor().pos() && cursor().pos() != cpit->size()
|
ParagraphList::iterator cpit = getPar(cur.par());
|
||||||
&& cpit->isChangeEdited(0, cursor().pos()))
|
|
||||||
|
if (cur.pos() != 0 && cur.pos() != cur.lastpos()
|
||||||
|
&& cpar.isChangeEdited(0, cur.pos()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LyXTextClass const & tclass =
|
LyXTextClass const & tclass =
|
||||||
bv()->buffer()->params().getLyXTextClass();
|
bv()->buffer()->params().getLyXTextClass();
|
||||||
LyXLayout_ptr const & layout = cpit->layout();
|
LyXLayout_ptr const & layout = cpar.layout();
|
||||||
|
|
||||||
// this is only allowed, if the current paragraph is not empty
|
// this is only allowed, if the current paragraph is not empty
|
||||||
// or caption and if it has not the keepempty flag active
|
// or caption and if it has not the keepempty flag active
|
||||||
if (cpit->empty() && !cpit->allowEmpty()
|
if (cur.lastpos() == 0 && !cpar.allowEmpty()
|
||||||
&& layout->labeltype != LABEL_SENSITIVE)
|
&& layout->labeltype != LABEL_SENSITIVE)
|
||||||
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(cur.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 (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos()))
|
||||||
cpit->erase(cursor().pos());
|
cpar.erase(cur.pos());
|
||||||
|
|
||||||
// break the paragraph
|
// break the paragraph
|
||||||
if (keep_layout)
|
if (keep_layout)
|
||||||
@ -788,16 +790,16 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
|
|||||||
// breakParagraph call should return a bool if it inserts the
|
// breakParagraph call should return a bool if it inserts the
|
||||||
// paragraph before or behind and we should react on that one
|
// paragraph before or behind and we should react on that one
|
||||||
// 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 = cpar.allowEmpty() && cpar.empty();
|
||||||
::breakParagraph(bv()->buffer()->params(), paragraphs, cpit,
|
::breakParagraph(bv()->buffer()->params(), paragraphs(), cpit,
|
||||||
cursor().pos(), keep_layout);
|
cur.pos(), keep_layout);
|
||||||
|
|
||||||
cpit = cursorPar();
|
cpit = getPar(cur.par());
|
||||||
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 (!cur.pos())
|
||||||
// set to standard-layout
|
// set to standard-layout
|
||||||
cpit->applyLayout(tclass.defaultLayout());
|
cpit->applyLayout(tclass.defaultLayout());
|
||||||
else
|
else
|
||||||
@ -809,11 +811,10 @@ 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());
|
if (cur.pos() != 0 && cur.textRow().pos() == cur.pos()
|
||||||
if (cursor().pos() && crit->pos() == cursor().pos()
|
&& !cpit->isNewline(cur.pos() - 1))
|
||||||
&& !cpit->isNewline(cursor().pos() - 1))
|
|
||||||
{
|
{
|
||||||
cursorLeft(bv());
|
cursorLeft(cur, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!next_par->empty() && next_par->isNewline(0))
|
while (!next_par->empty() && next_par->isNewline(0))
|
||||||
@ -825,10 +826,10 @@ 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 (cur.pos() != 0 || isempty)
|
||||||
setCursor(next_par, 0);
|
setCursor(cur.par() + 1, 0);
|
||||||
else
|
else
|
||||||
setCursor(cpit, 0);
|
setCursor(cur.par(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1080,20 +1081,39 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
|
|||||||
// the cursor set functions have a special mechanism. When they
|
// the cursor set functions have a special mechanism. When they
|
||||||
// realize, that you left an empty paragraph, they will delete it.
|
// realize, that you left an empty paragraph, they will delete it.
|
||||||
|
|
||||||
void LyXText::cursorRightOneWord()
|
void LyXText::cursorRightOneWord(LCursor & cur)
|
||||||
{
|
{
|
||||||
cursorRightOneWord(cursor());
|
if (cur.pos() == cur.lastpos() && cur.par() != cur.lastpar()) {
|
||||||
setCursor(cursorPar(), cursor().pos());
|
++cur.par();
|
||||||
|
cur.pos() = 0;
|
||||||
|
} else {
|
||||||
|
// Skip through initial nonword stuff.
|
||||||
|
// Treat floats and insets as words.
|
||||||
|
while (cur.pos() != cur.lastpos() && !cur.paragraph().isWord(cur.pos()))
|
||||||
|
++cur.pos();
|
||||||
|
// Advance through word.
|
||||||
|
while (cur.pos() != cur.lastpos() && cur.paragraph().isWord(cur.pos()))
|
||||||
|
++cur.pos();
|
||||||
|
}
|
||||||
|
setCursor(cur.par(), cur.pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Skip initial whitespace at end of word and move cursor to *start*
|
void LyXText::cursorLeftOneWord(LCursor & cur)
|
||||||
// of prior word, not to end of next prior word.
|
|
||||||
void LyXText::cursorLeftOneWord()
|
|
||||||
{
|
{
|
||||||
CursorSlice tmpcursor = cursor();
|
if (cur.pos() == 0 && cur.par() != 0) {
|
||||||
cursorLeftOneWord(tmpcursor);
|
--cur.par();
|
||||||
setCursor(getPar(tmpcursor), tmpcursor.pos());
|
cur.pos() = cur.lastpos();
|
||||||
|
} else {
|
||||||
|
// Skip through initial nonword stuff.
|
||||||
|
// Treat floats and insets as words.
|
||||||
|
while (cur.pos() != 0 && !cur.paragraph().isWord(cur.pos() - 1))
|
||||||
|
--cur.pos();
|
||||||
|
// Advance through word.
|
||||||
|
while (cur.pos() != 0 && cur.paragraph().isWord(cur.pos() - 1))
|
||||||
|
--cur.pos();
|
||||||
|
}
|
||||||
|
setCursor(cur.par(), cur.pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1164,18 +1184,14 @@ void LyXText::rejectChange()
|
|||||||
|
|
||||||
|
|
||||||
// Delete from cursor up to the end of the current or next word.
|
// Delete from cursor up to the end of the current or next word.
|
||||||
void LyXText::deleteWordForward()
|
void LyXText::deleteWordForward(LCursor & cur)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
if (cur.lastpos() == 0)
|
||||||
if (cursorPar()->empty())
|
cursorRight(cur, true);
|
||||||
cursorRight(true);
|
|
||||||
else {
|
else {
|
||||||
CursorSlice tmpcursor = cursor();
|
|
||||||
cur.selection() = true; // to avoid deletion
|
|
||||||
cursorRightOneWord();
|
|
||||||
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursor() = tmpcursor;
|
cur.selection() = true;
|
||||||
|
cursorRightOneWord(cur);
|
||||||
cur.setSelection();
|
cur.setSelection();
|
||||||
cutSelection(true, false);
|
cutSelection(true, false);
|
||||||
}
|
}
|
||||||
@ -1183,18 +1199,14 @@ void LyXText::deleteWordForward()
|
|||||||
|
|
||||||
|
|
||||||
// Delete from cursor to start of current or prior word.
|
// Delete from cursor to start of current or prior word.
|
||||||
void LyXText::deleteWordBackward()
|
void LyXText::deleteWordBackward(LCursor & cur)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
if (cur.lastpos() == 0)
|
||||||
if (cursorPar()->empty())
|
cursorLeft(cur, true);
|
||||||
cursorLeft(true);
|
|
||||||
else {
|
else {
|
||||||
CursorSlice tmpcursor = cursor();
|
|
||||||
cur.selection() = true; // to avoid deletion
|
|
||||||
cursorLeftOneWord();
|
|
||||||
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursor() = tmpcursor;
|
cur.selection() = true;
|
||||||
|
cursorLeftOneWord(cur);
|
||||||
cur.setSelection();
|
cur.setSelection();
|
||||||
cutSelection(true, false);
|
cutSelection(true, false);
|
||||||
}
|
}
|
||||||
@ -1202,23 +1214,19 @@ void LyXText::deleteWordBackward()
|
|||||||
|
|
||||||
|
|
||||||
// Kill to end of line.
|
// Kill to end of line.
|
||||||
void LyXText::deleteLineForward()
|
void LyXText::deleteLineForward(LCursor & cur)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
if (cur.lastpos() == 0) {
|
||||||
if (cursorPar()->empty()) {
|
|
||||||
// Paragraph is empty, so we just go to the right
|
// Paragraph is empty, so we just go to the right
|
||||||
cursorRight(true);
|
cursorRight(cur, true);
|
||||||
} else {
|
} else {
|
||||||
CursorSlice tmpcursor = cursor();
|
|
||||||
cur.selection() = true; // to avoid deletion
|
|
||||||
cursorEnd();
|
|
||||||
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
|
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursor() = tmpcursor;
|
cur.selection() = true; // to avoid deletion
|
||||||
|
cursorEnd(cur);
|
||||||
cur.setSelection();
|
cur.setSelection();
|
||||||
// What is this test for ??? (JMarc)
|
// What is this test for ??? (JMarc)
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
deleteWordForward();
|
deleteWordForward(cur);
|
||||||
else
|
else
|
||||||
cutSelection(true, false);
|
cutSelection(true, false);
|
||||||
}
|
}
|
||||||
@ -1275,30 +1283,26 @@ void LyXText::changeCase(LyXText::TextCase action)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::Delete()
|
void LyXText::Delete(LCursor & cur)
|
||||||
{
|
{
|
||||||
// this is a very easy implementation
|
// this is a very simple implementation
|
||||||
CursorSlice old_cursor = cursor();
|
|
||||||
|
|
||||||
// just move to the right
|
// just move to the right
|
||||||
cursorRight(true);
|
|
||||||
|
|
||||||
// if you had success make a backspace
|
// if you had success make a backspace
|
||||||
if (old_cursor.par() != cursor().par()
|
size_t oldpar = cur.par();
|
||||||
|| old_cursor.pos() != cursor().pos()) {
|
if (cursorRight(cur, true)) {
|
||||||
recordUndo(bv()->cursor(), Undo::DELETE, old_cursor.par());
|
recordUndo(cur, Undo::DELETE, oldpar);
|
||||||
backspace();
|
backspace(cur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::backspace()
|
void LyXText::backspace(LCursor & cur)
|
||||||
{
|
{
|
||||||
// Get the font that is used to calculate the baselineskip
|
// Get the font that is used to calculate the baselineskip
|
||||||
ParagraphList::iterator pit = cursorPar();
|
ParagraphList::iterator pit = cursorPar();
|
||||||
pos_type lastpos = pit->size();
|
pos_type lastpos = pit->size();
|
||||||
|
|
||||||
if (cursor().pos() == 0) {
|
if (cur.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.
|
||||||
@ -1316,26 +1320,26 @@ 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 (cur.par() != 0) {
|
||||||
cursorLeft(bv());
|
cursorLeft(cur, true);
|
||||||
// the layout things can change the height of a row !
|
// the layout things can change the height of a row !
|
||||||
redoParagraph();
|
redoParagraph();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor().par() != 0)
|
if (cur.par() != 0)
|
||||||
recordUndo(bv()->cursor(), Undo::DELETE, cursor().par() - 1);
|
recordUndo(cur, Undo::DELETE, cur.par() - 1);
|
||||||
|
|
||||||
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 (cur.par() != 0) {
|
||||||
// steps into the above paragraph.
|
// steps into the above paragraph.
|
||||||
setCursorIntern(cursor().par() - 1,
|
setCursorIntern(cur.par() - 1,
|
||||||
getPar(cursor().par() - 1)->size(),
|
getPar(cur.par() - 1)->size(),
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1354,32 +1358,31 @@ 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 (cur.pos() != 0 && cpit->isSeparator(cur.pos() - 1))
|
||||||
cursor().pos(cursor().pos() - 1);
|
--cur.pos();
|
||||||
|
|
||||||
// the counters may have changed
|
// the counters may have changed
|
||||||
updateCounters();
|
updateCounters();
|
||||||
setCursor(cursor().par(), cursor().pos(), false);
|
setCursor(cur.par(), cur.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(bv()->cursor(), Undo::DELETE);
|
recordUndo(cur, Undo::DELETE);
|
||||||
// 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(cur.par(), cur.pos() - 1,
|
||||||
false, cursor().boundary());
|
false, cur.boundary());
|
||||||
cursorPar()->erase(cursor().pos());
|
cur.paragraph().erase(cur.pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
lastpos = cursorPar()->size();
|
if (cur.pos() == cur.lastpos())
|
||||||
if (cursor().pos() == lastpos)
|
|
||||||
setCurrentFont();
|
setCurrentFont();
|
||||||
|
|
||||||
redoParagraph();
|
redoParagraph();
|
||||||
setCursor(cursor().par(), cursor().pos(), false, cursor().boundary());
|
setCursor(cur.par(), cur.pos(), false, cur.boundary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1599,7 +1602,7 @@ void LyXText::draw(PainterInfo & pi, int x, int y) const
|
|||||||
|
|
||||||
|
|
||||||
// only used for inset right now. should also be used for main text
|
// only used for inset right now. should also be used for main text
|
||||||
void LyXText::drawSelection(PainterInfo & pi, int x, int y) const
|
void LyXText::drawSelection(PainterInfo &, int x, int y) const
|
||||||
{
|
{
|
||||||
lyxerr << "LyXText::drawSelection at " << x << " " << y << endl;
|
lyxerr << "LyXText::drawSelection at " << x << " " << y << endl;
|
||||||
}
|
}
|
||||||
@ -1618,78 +1621,19 @@ bool LyXText::isFirstRow(ParagraphList::iterator pit, Row const & row) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorLeftOneWord(CursorSlice & cur)
|
void LyXText::getWord(CursorSlice & from, CursorSlice & to,
|
||||||
|
word_location const loc)
|
||||||
{
|
{
|
||||||
// treat HFills, floats and Insets as words
|
Paragraph & from_par = *getPar(from);
|
||||||
|
|
||||||
ParagraphList::iterator pit = cursorPar();
|
|
||||||
size_t pos = cur.pos();
|
|
||||||
|
|
||||||
while (pos &&
|
|
||||||
(pit->isSeparator(pos - 1) ||
|
|
||||||
pit->isKomma(pos - 1) ||
|
|
||||||
pit->isNewline(pos - 1)) &&
|
|
||||||
!(pit->isHfill(pos - 1) ||
|
|
||||||
pit->isInset(pos - 1)))
|
|
||||||
--pos;
|
|
||||||
|
|
||||||
if (pos &&
|
|
||||||
(pit->isInset(pos - 1) ||
|
|
||||||
pit->isHfill(pos - 1))) {
|
|
||||||
--pos;
|
|
||||||
} else if (!pos) {
|
|
||||||
if (pit != paragraphs().begin()) {
|
|
||||||
--pit;
|
|
||||||
pos = pit->size();
|
|
||||||
}
|
|
||||||
} else { // Here, cur != 0
|
|
||||||
while (pos > 0 && pit->isWord(pos - 1))
|
|
||||||
--pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
cur.par(parOffset(pit));
|
|
||||||
cur.pos(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorRightOneWord(CursorSlice & cur)
|
|
||||||
{
|
|
||||||
// treat floats, HFills and Insets as words
|
|
||||||
ParagraphList::iterator pit = cursorPar();
|
|
||||||
pos_type pos = cur.pos();
|
|
||||||
|
|
||||||
if (pos == pit->size() &&
|
|
||||||
boost::next(pit) != paragraphs().end()) {
|
|
||||||
++pit;
|
|
||||||
pos = 0;
|
|
||||||
} else {
|
|
||||||
// Skip through initial nonword stuff.
|
|
||||||
while (pos < pit->size() && !pit->isWord(pos)) {
|
|
||||||
++pos;
|
|
||||||
}
|
|
||||||
// Advance through word.
|
|
||||||
while (pos < pit->size() && pit->isWord(pos)) {
|
|
||||||
++pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur.par(parOffset(pit));
|
|
||||||
cur.pos(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LyXText::getWord(CursorSlice & from, CursorSlice & to, word_location const loc)
|
|
||||||
{
|
|
||||||
ParagraphList::iterator from_par = getPar(from);
|
|
||||||
switch (loc) {
|
switch (loc) {
|
||||||
case lyx::WHOLE_WORD_STRICT:
|
case lyx::WHOLE_WORD_STRICT:
|
||||||
if (from.pos() == 0 || from.pos() == from_par->size()
|
if (from.pos() == 0 || from.pos() == from_par.size()
|
||||||
|| from_par->isSeparator(from.pos())
|
|| from_par.isSeparator(from.pos())
|
||||||
|| from_par->isKomma(from.pos())
|
|| from_par.isKomma(from.pos())
|
||||||
|| from_par->isNewline(from.pos())
|
|| from_par.isNewline(from.pos())
|
||||||
|| from_par->isSeparator(from.pos() - 1)
|
|| from_par.isSeparator(from.pos() - 1)
|
||||||
|| from_par->isKomma(from.pos() - 1)
|
|| from_par.isKomma(from.pos() - 1)
|
||||||
|| from_par->isNewline(from.pos() - 1)) {
|
|| from_par.isNewline(from.pos() - 1)) {
|
||||||
to = from;
|
to = from;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1697,14 +1641,14 @@ void LyXText::getWord(CursorSlice & from, CursorSlice & to, word_location const
|
|||||||
|
|
||||||
case lyx::WHOLE_WORD:
|
case lyx::WHOLE_WORD:
|
||||||
// Move cursor to the beginning, when not already there.
|
// Move cursor to the beginning, when not already there.
|
||||||
if (from.pos() && !from_par->isSeparator(from.pos() - 1)
|
if (from.pos() && !from_par.isSeparator(from.pos() - 1)
|
||||||
&& !(from_par->isKomma(from.pos() - 1)
|
&& !(from_par.isKomma(from.pos() - 1)
|
||||||
|| from_par->isNewline(from.pos() - 1)))
|
|| from_par.isNewline(from.pos() - 1)))
|
||||||
cursorLeftOneWord(from);
|
cursorLeftOneWord(bv()->cursor());
|
||||||
break;
|
break;
|
||||||
case lyx::PREVIOUS_WORD:
|
case lyx::PREVIOUS_WORD:
|
||||||
// always move the cursor to the beginning of previous word
|
// always move the cursor to the beginning of previous word
|
||||||
cursorLeftOneWord(from);
|
cursorLeftOneWord(bv()->cursor());
|
||||||
break;
|
break;
|
||||||
case lyx::NEXT_WORD:
|
case lyx::NEXT_WORD:
|
||||||
lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
|
lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
|
||||||
@ -1714,15 +1658,15 @@ void LyXText::getWord(CursorSlice & from, CursorSlice & to, word_location const
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
to = from;
|
to = from;
|
||||||
ParagraphList::iterator to_par = getPar(to);
|
Paragraph & to_par = *getPar(to);
|
||||||
while (to.pos() < to_par->size()
|
while (to.pos() < to_par.size()
|
||||||
&& !to_par->isSeparator(to.pos())
|
&& !to_par.isSeparator(to.pos())
|
||||||
&& !to_par->isKomma(to.pos())
|
&& !to_par.isKomma(to.pos())
|
||||||
&& !to_par->isNewline(to.pos())
|
&& !to_par.isNewline(to.pos())
|
||||||
&& !to_par->isHfill(to.pos())
|
&& !to_par.isHfill(to.pos())
|
||||||
&& !to_par->isInset(to.pos()))
|
&& !to_par.isInset(to.pos()))
|
||||||
{
|
{
|
||||||
to.pos(to.pos() + 1);
|
++to.pos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
142
src/text2.C
142
src/text2.C
@ -441,33 +441,30 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
|
|||||||
// the cursor set functions have a special mechanism. When they
|
// the cursor set functions have a special mechanism. When they
|
||||||
// realize you left an empty paragraph, they will delete it.
|
// realize you left an empty paragraph, they will delete it.
|
||||||
|
|
||||||
void LyXText::cursorHome()
|
void LyXText::cursorHome(LCursor & cur)
|
||||||
{
|
{
|
||||||
ParagraphList::iterator cpit = cursorPar();
|
setCursor(cur.par(), cur.textRow().pos());
|
||||||
setCursor(cpit, cpit->getRow(cursor().pos())->pos());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorEnd()
|
void LyXText::cursorEnd(LCursor & cur)
|
||||||
{
|
{
|
||||||
ParagraphList::iterator cpit = cursorPar();
|
|
||||||
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);
|
pos_type const end = cur.textRow().endpos();
|
||||||
|
setCursor(cur.par(), end == cur.lastpos() ? end : end - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorTop()
|
void LyXText::cursorTop(LCursor &)
|
||||||
{
|
{
|
||||||
setCursor(paragraphs().begin(), 0);
|
setCursor(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorBottom()
|
void LyXText::cursorBottom(LCursor & cur)
|
||||||
{
|
{
|
||||||
ParagraphList::iterator lastpit = boost::prior(paragraphs().end());
|
setCursor(cur.lastpar(), boost::prior(paragraphs().end())->size());
|
||||||
setCursor(lastpit, lastpit->size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -878,7 +875,7 @@ void LyXText::insertInset(InsetBase * inset)
|
|||||||
// and fails if the cursor is behind the inset and getInset
|
// and fails if the cursor is behind the inset and getInset
|
||||||
// does not return the inset!
|
// does not return the inset!
|
||||||
if (isHighlyEditableInset(inset))
|
if (isHighlyEditableInset(inset))
|
||||||
cursorLeft(true);
|
cursorLeft(bv()->cursor(), true);
|
||||||
|
|
||||||
unFreezeUndo();
|
unFreezeUndo();
|
||||||
}
|
}
|
||||||
@ -997,7 +994,7 @@ void LyXText::pasteSelection(size_t sel_index)
|
|||||||
|
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
setCursor(ppp.first, ppp.second);
|
setCursor(parOffset(ppp.first), ppp.second);
|
||||||
cur.setSelection();
|
cur.setSelection();
|
||||||
updateCounters();
|
updateCounters();
|
||||||
}
|
}
|
||||||
@ -1011,7 +1008,7 @@ void LyXText::setSelectionRange(lyx::pos_type length)
|
|||||||
LCursor & cur = bv()->cursor();
|
LCursor & cur = bv()->cursor();
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
while (length--)
|
while (length--)
|
||||||
cursorRight(true);
|
cursorRight(cur, true);
|
||||||
cur.setSelection();
|
cur.setSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1059,7 +1056,7 @@ void LyXText::insertStringAsLines(string const & str)
|
|||||||
|
|
||||||
redoParagraphs(cursorPar(), endpit);
|
redoParagraphs(cursorPar(), endpit);
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
setCursor(pit, pos);
|
setCursor(parOffset(pit), pos);
|
||||||
cur.setSelection();
|
cur.setSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1092,12 +1089,6 @@ void LyXText::insertStringAsParagraphs(string const & str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::setCursor(ParagraphList::iterator pit, pos_type pos)
|
|
||||||
{
|
|
||||||
setCursor(parOffset(pit), 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)
|
||||||
{
|
{
|
||||||
@ -1363,91 +1354,87 @@ void LyXText::edit(LCursor & cur, int x, int y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LyXText::checkAndActivateInset(bool front)
|
bool LyXText::checkAndActivateInset(LCursor & cur, bool front)
|
||||||
{
|
{
|
||||||
if (cursor().pos() == cursorPar()->size())
|
if (cur.pos() == cur.lastpos())
|
||||||
return false;
|
return false;
|
||||||
InsetBase * inset = cursorPar()->getInset(cursor().pos());
|
InsetBase * inset = cur.nextInset();
|
||||||
if (!isHighlyEditableInset(inset))
|
if (!isHighlyEditableInset(inset))
|
||||||
return false;
|
return false;
|
||||||
inset->edit(bv()->cursor(), front);
|
inset->edit(cur, front);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DispatchResult LyXText::moveRight()
|
DispatchResult LyXText::moveRight(LCursor & cur)
|
||||||
{
|
{
|
||||||
if (cursorPar()->isRightToLeftPar(bv()->buffer()->params()))
|
if (cur.paragraph().isRightToLeftPar(bv()->buffer()->params()))
|
||||||
return moveLeftIntern(false, true, false);
|
return moveLeftIntern(cur, false, true, false);
|
||||||
else
|
else
|
||||||
return moveRightIntern(true, true, false);
|
return moveRightIntern(cur, true, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DispatchResult LyXText::moveLeft()
|
DispatchResult LyXText::moveLeft(LCursor & cur)
|
||||||
{
|
{
|
||||||
if (cursorPar()->isRightToLeftPar(bv()->buffer()->params()))
|
if (cur.paragraph().isRightToLeftPar(bv()->buffer()->params()))
|
||||||
return moveRightIntern(true, true, false);
|
return moveRightIntern(cur, true, true, false);
|
||||||
else
|
else
|
||||||
return moveLeftIntern(false, true, false);
|
return moveLeftIntern(cur, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DispatchResult LyXText::moveRightIntern(bool front, bool activate_inset, bool selecting)
|
DispatchResult LyXText::moveRightIntern(LCursor & cur,
|
||||||
|
bool front, bool activate_inset, bool selecting)
|
||||||
{
|
{
|
||||||
ParagraphList::iterator c_par = cursorPar();
|
if (cur.par() == cur.lastpar() && cur.pos() == cur.lastpos())
|
||||||
if (boost::next(c_par) == paragraphs().end()
|
|
||||||
&& cursor().pos() >= c_par->size())
|
|
||||||
return DispatchResult(false, FINISHED_RIGHT);
|
return DispatchResult(false, FINISHED_RIGHT);
|
||||||
if (activate_inset && checkAndActivateInset(front))
|
if (activate_inset && checkAndActivateInset(cur, front))
|
||||||
return DispatchResult(true, true);
|
return DispatchResult(true, true);
|
||||||
cursorRight(true);
|
cursorRight(cur, true);
|
||||||
if (!selecting)
|
if (!selecting)
|
||||||
bv()->cursor().clearSelection();
|
cur.clearSelection();
|
||||||
return DispatchResult(true);
|
return DispatchResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DispatchResult LyXText::moveLeftIntern(bool front,
|
DispatchResult LyXText::moveLeftIntern(LCursor & cur,
|
||||||
bool activate_inset, bool selecting)
|
bool front, bool activate_inset, bool selecting)
|
||||||
{
|
{
|
||||||
if (cursor().par() == 0 && cursor().pos() <= 0)
|
if (cur.par() == 0 && cur.pos() == 0)
|
||||||
return DispatchResult(false, FINISHED);
|
return DispatchResult(false, FINISHED);
|
||||||
cursorLeft(true);
|
cursorLeft(cur, true);
|
||||||
if (!selecting)
|
if (!selecting)
|
||||||
bv()->cursor().clearSelection();
|
cur.clearSelection();
|
||||||
if (activate_inset && checkAndActivateInset(front))
|
if (activate_inset && checkAndActivateInset(cur, front))
|
||||||
return DispatchResult(true, true);
|
return DispatchResult(true, true);
|
||||||
return DispatchResult(true);
|
return DispatchResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DispatchResult LyXText::moveUp()
|
DispatchResult LyXText::moveUp(LCursor & cur)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
if (cur.par() == 0 && cur.row() == 0)
|
||||||
if (cur.par() == 0 && cursorRow() == firstRow())
|
|
||||||
return DispatchResult(false, FINISHED_UP);
|
return DispatchResult(false, FINISHED_UP);
|
||||||
cursorUp(false);
|
cursorUp(cur, false);
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
return DispatchResult(true);
|
return DispatchResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DispatchResult LyXText::moveDown()
|
DispatchResult LyXText::moveDown(LCursor & cur)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
if (cur.par() == cur.lastpar() && cur.textRow().endpos() == cur.lastpos())
|
||||||
if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
|
|
||||||
return DispatchResult(false, FINISHED_DOWN);
|
return DispatchResult(false, FINISHED_DOWN);
|
||||||
cursorDown(false);
|
cursorDown(cur, false);
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
return DispatchResult(true);
|
return DispatchResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LyXText::cursorLeft(bool internal)
|
bool LyXText::cursorLeft(LCursor & cur, bool internal)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
if (cur.pos() != 0) {
|
||||||
if (cur.pos() > 0) {
|
|
||||||
bool boundary = cur.boundary();
|
bool boundary = cur.boundary();
|
||||||
setCursor(cur.par(), cur.pos() - 1, true, false);
|
setCursor(cur.par(), cur.pos() - 1, true, false);
|
||||||
if (!internal && !boundary &&
|
if (!internal && !boundary &&
|
||||||
@ -1466,9 +1453,8 @@ bool LyXText::cursorLeft(bool internal)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LyXText::cursorRight(bool internal)
|
bool LyXText::cursorRight(LCursor & cur, bool internal)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
|
||||||
if (!internal && cur.boundary()) {
|
if (!internal && cur.boundary()) {
|
||||||
setCursor(cur.par(), cur.pos(), true, false);
|
setCursor(cur.par(), cur.pos(), true, false);
|
||||||
return true;
|
return true;
|
||||||
@ -1482,7 +1468,7 @@ bool LyXText::cursorRight(bool internal)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cur.par() + 1 != int(paragraphs().size())) {
|
if (cur.par() != cur.lastpar()) {
|
||||||
setCursor(cur.par() + 1, 0);
|
setCursor(cur.par() + 1, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1491,9 +1477,8 @@ bool LyXText::cursorRight(bool internal)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorUp(bool selecting)
|
void LyXText::cursorUp(LCursor & cur, bool selecting)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
|
||||||
Row const & row = *cursorRow();
|
Row const & row = *cursorRow();
|
||||||
int x = cur.x_target();
|
int x = cur.x_target();
|
||||||
int y = cursorY(cur.current()) - row.baseline() - 1;
|
int y = cursorY(cur.current()) - row.baseline() - 1;
|
||||||
@ -1507,13 +1492,12 @@ void LyXText::cursorUp(bool selecting)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorDown(bool selecting)
|
void LyXText::cursorDown(LCursor & cur, bool selecting)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
Row const & row = cur.textRow();
|
||||||
Row const & row = *cursorRow();
|
|
||||||
int x = cur.x_target();
|
int x = cur.x_target();
|
||||||
int y = cursorY(cur.current()) - row.baseline() + row.height() + 1;
|
int y = cursorY(cur.current()) - row.baseline() + row.height() + 1;
|
||||||
setCursorFromCoordinates(x, y);
|
setCursorFromCoordinates(cur.current(), x, y);
|
||||||
|
|
||||||
if (!selecting) {
|
if (!selecting) {
|
||||||
InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
|
InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
|
||||||
@ -1523,25 +1507,21 @@ void LyXText::cursorDown(bool selecting)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorUpParagraph()
|
void LyXText::cursorUpParagraph(LCursor & cur)
|
||||||
{
|
{
|
||||||
ParagraphList::iterator cpit = cursorPar();
|
if (cur.pos() > 0)
|
||||||
if (cursor().pos() > 0)
|
setCursor(cur.par(), 0);
|
||||||
setCursor(cpit, 0);
|
else if (cur.par() != 0)
|
||||||
else if (cpit != paragraphs().begin())
|
setCursor(cur.par() - 1, 0);
|
||||||
setCursor(boost::prior(cpit), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorDownParagraph()
|
void LyXText::cursorDownParagraph(LCursor & cur)
|
||||||
{
|
{
|
||||||
ParagraphList::iterator pit = cursorPar();
|
if (cur.par() != cur.lastpar())
|
||||||
ParagraphList::iterator next_pit = boost::next(pit);
|
setCursor(cur.par() + 1, 0);
|
||||||
|
|
||||||
if (next_pit != paragraphs().end())
|
|
||||||
setCursor(next_pit, 0);
|
|
||||||
else
|
else
|
||||||
setCursor(pit, pit->size());
|
setCursor(cur.par(), cur.lastpos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1557,7 +1537,7 @@ void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where)
|
|||||||
// if cursor position is after the place where the delete occured,
|
// if cursor position is after the place where the delete occured,
|
||||||
// update it
|
// update it
|
||||||
if (cur.pos() > where.pos())
|
if (cur.pos() > where.pos())
|
||||||
cur.pos(cur.pos()-1);
|
--cur.pos();
|
||||||
|
|
||||||
// check also if we don't want to set the cursor on a spot behind the
|
// check also if we don't want to set the cursor on a spot behind the
|
||||||
// pagragraph because we erased the last character.
|
// pagragraph because we erased the last character.
|
||||||
|
174
src/text3.C
174
src/text3.C
@ -24,6 +24,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "dispatchresult.h"
|
#include "dispatchresult.h"
|
||||||
#include "factory.h"
|
#include "factory.h"
|
||||||
|
#include "FloatList.h"
|
||||||
#include "funcrequest.h"
|
#include "funcrequest.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "intl.h"
|
#include "intl.h"
|
||||||
@ -41,6 +42,7 @@
|
|||||||
#include "frontends/LyXView.h"
|
#include "frontends/LyXView.h"
|
||||||
|
|
||||||
#include "insets/insetcommand.h"
|
#include "insets/insetcommand.h"
|
||||||
|
#include "insets/insetfloatlist.h"
|
||||||
#include "insets/insetnewline.h"
|
#include "insets/insetnewline.h"
|
||||||
#include "insets/insetspecialchar.h"
|
#include "insets/insetspecialchar.h"
|
||||||
#include "insets/insettext.h"
|
#include "insets/insettext.h"
|
||||||
@ -286,20 +288,19 @@ void LyXText::gotoInset(InsetOld_code code, bool same_content)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorPrevious()
|
void LyXText::cursorPrevious(LCursor & cur)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
|
||||||
pos_type cpos = cur.pos();
|
pos_type cpos = cur.pos();
|
||||||
lyx::paroffset_type cpar = cur.par();
|
lyx::paroffset_type cpar = cur.par();
|
||||||
|
|
||||||
int x = bv()->cursor().x_target();
|
int x = cur.x_target();
|
||||||
int y = bv()->top_y();
|
int y = bv()->top_y();
|
||||||
setCursorFromCoordinates(x, y);
|
setCursorFromCoordinates(x, y);
|
||||||
|
|
||||||
if (cpar == cur.par() && cpos == cur.pos()) {
|
if (cpar == cur.par() && cpos == cur.pos()) {
|
||||||
// we have a row which is taller than the workarea. The
|
// we have a row which is taller than the workarea. The
|
||||||
// simplest solution is to move to the previous row instead.
|
// simplest solution is to move to the previous row instead.
|
||||||
cursorUp(true);
|
cursorUp(cur, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bv()->updateScrollbar();
|
bv()->updateScrollbar();
|
||||||
@ -307,9 +308,8 @@ void LyXText::cursorPrevious()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LyXText::cursorNext()
|
void LyXText::cursorNext(LCursor & cur)
|
||||||
{
|
{
|
||||||
LCursor & cur = bv()->cursor();
|
|
||||||
pos_type cpos = cur.pos();
|
pos_type cpos = cur.pos();
|
||||||
lyx::paroffset_type cpar = cur.par();
|
lyx::paroffset_type cpar = cur.par();
|
||||||
|
|
||||||
@ -320,7 +320,7 @@ void LyXText::cursorNext()
|
|||||||
if (cpar == cur.par() && cpos == cur.pos()) {
|
if (cpar == cur.par() && cpos == cur.pos()) {
|
||||||
// we have a row which is taller than the workarea. The
|
// we have a row which is taller than the workarea. The
|
||||||
// simplest solution is to move to the next row instead.
|
// simplest solution is to move to the next row instead.
|
||||||
cursorDown(true);
|
cursorDown(cur, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bv()->updateScrollbar();
|
bv()->updateScrollbar();
|
||||||
@ -413,19 +413,19 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
|
|
||||||
case LFUN_DELETE_WORD_FORWARD:
|
case LFUN_DELETE_WORD_FORWARD:
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
deleteWordForward();
|
deleteWordForward(cur);
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_DELETE_WORD_BACKWARD:
|
case LFUN_DELETE_WORD_BACKWARD:
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
deleteWordBackward();
|
deleteWordBackward(cur);
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_DELETE_LINE_FORWARD:
|
case LFUN_DELETE_LINE_FORWARD:
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
deleteLineForward();
|
deleteLineForward(cur);
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -433,9 +433,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
if (!cur.mark())
|
if (!cur.mark())
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
if (rtl())
|
if (rtl())
|
||||||
cursorLeftOneWord();
|
cursorLeftOneWord(cur);
|
||||||
else
|
else
|
||||||
cursorRightOneWord();
|
cursorRightOneWord(cur);
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -443,23 +443,23 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
if (!cur.mark())
|
if (!cur.mark())
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
if (rtl())
|
if (rtl())
|
||||||
cursorRightOneWord();
|
cursorRightOneWord(cur);
|
||||||
else
|
else
|
||||||
cursorLeftOneWord();
|
cursorLeftOneWord(cur);
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_BEGINNINGBUF:
|
case LFUN_BEGINNINGBUF:
|
||||||
if (!cur.mark())
|
if (!cur.mark())
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
cursorTop();
|
cursorTop(cur);
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_ENDBUF:
|
case LFUN_ENDBUF:
|
||||||
if (!cur.mark())
|
if (!cur.mark())
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
cursorBottom();
|
cursorBottom(cur);
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -467,9 +467,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
if (rtl())
|
if (rtl())
|
||||||
cursorLeft(true);
|
cursorLeft(cur, true);
|
||||||
else
|
else
|
||||||
cursorRight(true);
|
cursorRight(cur, true);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -477,65 +477,65 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
if (rtl())
|
if (rtl())
|
||||||
cursorRight(true);
|
cursorRight(cur, true);
|
||||||
else
|
else
|
||||||
cursorLeft(true);
|
cursorLeft(cur, true);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_UPSEL:
|
case LFUN_UPSEL:
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorUp(true);
|
cursorUp(cur, true);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_DOWNSEL:
|
case LFUN_DOWNSEL:
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorDown(true);
|
cursorDown(cur, true);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_UP_PARAGRAPHSEL:
|
case LFUN_UP_PARAGRAPHSEL:
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorUpParagraph();
|
cursorUpParagraph(cur);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_DOWN_PARAGRAPHSEL:
|
case LFUN_DOWN_PARAGRAPHSEL:
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorDownParagraph();
|
cursorDownParagraph(cur);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_PRIORSEL:
|
case LFUN_PRIORSEL:
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorPrevious();
|
cursorPrevious(cur);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_NEXTSEL:
|
case LFUN_NEXTSEL:
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorNext();
|
cursorNext(cur);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_HOMESEL:
|
case LFUN_HOMESEL:
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorHome();
|
cursorHome(cur);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_ENDSEL:
|
case LFUN_ENDSEL:
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorEnd();
|
cursorEnd(cur);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -543,9 +543,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
if (rtl())
|
if (rtl())
|
||||||
cursorLeftOneWord();
|
cursorLeftOneWord(cur);
|
||||||
else
|
else
|
||||||
cursorRightOneWord();
|
cursorRightOneWord(cur);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -553,9 +553,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
if (rtl())
|
if (rtl())
|
||||||
cursorRightOneWord();
|
cursorRightOneWord(cur);
|
||||||
else
|
else
|
||||||
cursorLeftOneWord();
|
cursorLeftOneWord(cur);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -567,31 +567,31 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
|
|
||||||
case LFUN_RIGHT:
|
case LFUN_RIGHT:
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
return moveRight();
|
return moveRight(cur);
|
||||||
|
|
||||||
case LFUN_LEFT:
|
case LFUN_LEFT:
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
return moveLeft();
|
return moveLeft(cur);
|
||||||
|
|
||||||
case LFUN_UP:
|
case LFUN_UP:
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
return moveUp();
|
return moveUp(cur);
|
||||||
|
|
||||||
case LFUN_DOWN:
|
case LFUN_DOWN:
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
return moveDown();
|
return moveDown(cur);
|
||||||
|
|
||||||
case LFUN_UP_PARAGRAPH:
|
case LFUN_UP_PARAGRAPH:
|
||||||
if (!cur.mark())
|
if (!cur.mark())
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
cursorUpParagraph();
|
cursorUpParagraph(cur);
|
||||||
finishChange(cur);
|
finishChange(cur);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_DOWN_PARAGRAPH:
|
case LFUN_DOWN_PARAGRAPH:
|
||||||
if (!cur.mark())
|
if (!cur.mark())
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
cursorDownParagraph();
|
cursorDownParagraph(cur);
|
||||||
finishChange(cur, false);
|
finishChange(cur, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -599,31 +599,32 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
if (!cur.mark())
|
if (!cur.mark())
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
finishChange(cur, false);
|
finishChange(cur, false);
|
||||||
if (cur.par() == 0 && cursorRow() == firstRow())
|
if (cur.par() == 0 && cur.textRow().pos() == 0)
|
||||||
return DispatchResult(false, FINISHED_UP);
|
return DispatchResult(false, FINISHED_UP);
|
||||||
cursorPrevious();
|
cursorPrevious(cur);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_NEXT:
|
case LFUN_NEXT:
|
||||||
if (!cur.mark())
|
if (!cur.mark())
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
finishChange(cur, false);
|
finishChange(cur, false);
|
||||||
if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
|
if (cur.par() == cur.lastpar()
|
||||||
|
&& cur.textRow().endpos() == cur.lastpos())
|
||||||
return DispatchResult(false, FINISHED_DOWN);
|
return DispatchResult(false, FINISHED_DOWN);
|
||||||
cursorNext();
|
cursorNext(cur);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_HOME:
|
case LFUN_HOME:
|
||||||
if (!cur.mark())
|
if (!cur.mark())
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
cursorHome();
|
cursorHome(cur);
|
||||||
finishChange(cur, false);
|
finishChange(cur, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_END:
|
case LFUN_END:
|
||||||
if (!cur.mark())
|
if (!cur.mark())
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
cursorEnd();
|
cursorEnd(cur);
|
||||||
finishChange(cur, false);
|
finishChange(cur, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -639,7 +640,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
|
|
||||||
case LFUN_DELETE:
|
case LFUN_DELETE:
|
||||||
if (!cur.selection()) {
|
if (!cur.selection()) {
|
||||||
Delete();
|
Delete(cur);
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
// 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...
|
||||||
@ -653,15 +654,12 @@ DispatchResult LyXText::dispatch(LCursor & cur, 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 (!cur.selection()) {
|
if (!cur.selection()) {
|
||||||
if (cursor().pos() == cursorPar()->size()) {
|
if (cur.pos() == cur.lastpos()) {
|
||||||
cursorRight(bv);
|
cursorRight(cur, true);
|
||||||
cursorLeft(bv);
|
cursorLeft(cur, true);
|
||||||
Delete();
|
|
||||||
cur.resetAnchor();
|
|
||||||
} else {
|
|
||||||
Delete();
|
|
||||||
cur.resetAnchor();
|
|
||||||
}
|
}
|
||||||
|
Delete(cur);
|
||||||
|
cur.resetAnchor();
|
||||||
} else {
|
} else {
|
||||||
cutSelection(true, false);
|
cutSelection(true, false);
|
||||||
}
|
}
|
||||||
@ -672,7 +670,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
case LFUN_BACKSPACE:
|
case LFUN_BACKSPACE:
|
||||||
if (!cur.selection()) {
|
if (!cur.selection()) {
|
||||||
if (bv->owner()->getIntl().getTransManager().backspace()) {
|
if (bv->owner()->getIntl().getTransManager().backspace()) {
|
||||||
backspace();
|
backspace(cur);
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
// 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...
|
||||||
@ -690,7 +688,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
if (!cur.selection()) {
|
if (!cur.selection()) {
|
||||||
#warning look here
|
#warning look here
|
||||||
//CursorSlice cur = cursor();
|
//CursorSlice cur = cursor();
|
||||||
backspace();
|
backspace(cur);
|
||||||
//anchor() = cur;
|
//anchor() = cur;
|
||||||
} else {
|
} else {
|
||||||
cutSelection(true, false);
|
cutSelection(true, false);
|
||||||
@ -700,7 +698,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
|
|
||||||
case LFUN_BREAKPARAGRAPH:
|
case LFUN_BREAKPARAGRAPH:
|
||||||
replaceSelection(this);
|
replaceSelection(this);
|
||||||
breakParagraph(bv->buffer()->paragraphs(), 0);
|
breakParagraph(cur, 0);
|
||||||
bv->update();
|
bv->update();
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
bv->switchKeyMap();
|
bv->switchKeyMap();
|
||||||
@ -709,7 +707,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
|
|
||||||
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
|
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
|
||||||
replaceSelection(this);
|
replaceSelection(this);
|
||||||
breakParagraph(bv->buffer()->paragraphs(), 1);
|
breakParagraph(cur, 1);
|
||||||
bv->update();
|
bv->update();
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
bv->switchKeyMap();
|
bv->switchKeyMap();
|
||||||
@ -721,16 +719,15 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
// 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.
|
||||||
#warning look here
|
#warning look here
|
||||||
// CursorSlice cur = cursor();
|
|
||||||
replaceSelection(this);
|
replaceSelection(this);
|
||||||
if (cur.pos() == 0) {
|
if (cur.pos() == 0) {
|
||||||
ParagraphParameters & params = getPar(cur.current())->params();
|
ParagraphParameters & params = cur.paragraph().params();
|
||||||
setParagraph(
|
setParagraph(
|
||||||
params.spacing(),
|
params.spacing(),
|
||||||
params.align(),
|
params.align(),
|
||||||
params.labelWidthString(), 1);
|
params.labelWidthString(), 1);
|
||||||
} else {
|
} else {
|
||||||
breakParagraph(bv->buffer()->paragraphs(), 0);
|
breakParagraph(cur, 0);
|
||||||
}
|
}
|
||||||
bv->update();
|
bv->update();
|
||||||
// anchor() = cur;
|
// anchor() = cur;
|
||||||
@ -740,11 +737,11 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case LFUN_PARAGRAPH_SPACING: {
|
case LFUN_PARAGRAPH_SPACING: {
|
||||||
ParagraphList::iterator pit = cursorPar();
|
Paragraph & par = cur.paragraph();
|
||||||
Spacing::Space cur_spacing = pit->params().spacing().getSpace();
|
Spacing::Space cur_spacing = par.params().spacing().getSpace();
|
||||||
float cur_value = 1.0;
|
float cur_value = 1.0;
|
||||||
if (cur_spacing == Spacing::Other)
|
if (cur_spacing == Spacing::Other)
|
||||||
cur_value = pit->params().spacing().getValue();
|
cur_value = par.params().spacing().getValue();
|
||||||
|
|
||||||
istringstream is(cmd.argument);
|
istringstream is(cmd.argument);
|
||||||
string tmp;
|
string tmp;
|
||||||
@ -774,7 +771,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
<< cmd.argument << endl;
|
<< cmd.argument << endl;
|
||||||
}
|
}
|
||||||
if (cur_spacing != new_spacing || cur_value != new_value) {
|
if (cur_spacing != new_spacing || cur_value != new_value) {
|
||||||
pit->params().spacing(Spacing(new_spacing, new_value));
|
par.params().spacing(Spacing(new_spacing, new_value));
|
||||||
redoParagraph();
|
redoParagraph();
|
||||||
bv->update();
|
bv->update();
|
||||||
}
|
}
|
||||||
@ -890,7 +887,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
return DispatchResult(false);
|
return DispatchResult(false);
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorTop();
|
cursorTop(cur);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -899,7 +896,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
return DispatchResult(false);
|
return DispatchResult(false);
|
||||||
if (!cur.selection())
|
if (!cur.selection())
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorBottom();
|
cursorBottom(cur);
|
||||||
finishChange(cur, true);
|
finishChange(cur, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1070,9 +1067,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
case LFUN_MOUSE_TRIPLE:
|
case LFUN_MOUSE_TRIPLE:
|
||||||
if (cmd.button() == mouse_button::button1) {
|
if (cmd.button() == mouse_button::button1) {
|
||||||
selection_possible = true;
|
selection_possible = true;
|
||||||
cursorHome();
|
cursorHome(cur);
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
cursorEnd();
|
cursorEnd(cur);
|
||||||
cur.setSelection();
|
cur.setSelection();
|
||||||
bv->haveSelection(cur.selection());
|
bv->haveSelection(cur.selection());
|
||||||
}
|
}
|
||||||
@ -1107,9 +1104,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
// FIXME: shouldn't be top-text-specific
|
// FIXME: shouldn't be top-text-specific
|
||||||
if (cursorrow == cursorRow() && !in_inset_) {
|
if (cursorrow == cursorRow() && !in_inset_) {
|
||||||
if (cmd.y - bv->top_y() >= bv->workHeight())
|
if (cmd.y - bv->top_y() >= bv->workHeight())
|
||||||
cursorDown(true);
|
cursorDown(cur, true);
|
||||||
else if (cmd.y - bv->top_y() < 0)
|
else if (cmd.y - bv->top_y() < 0)
|
||||||
cursorUp(true);
|
cursorUp(cur, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't set anchor_
|
// don't set anchor_
|
||||||
@ -1450,31 +1447,31 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
case LFUN_FINISHED_LEFT:
|
case LFUN_FINISHED_LEFT:
|
||||||
lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
|
lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
|
||||||
cur.pop(cur.currentDepth());
|
cur.pop(cur.currentDepth());
|
||||||
cur.bv().cursor() = cur;
|
|
||||||
if (rtl())
|
if (rtl())
|
||||||
cursorLeft(true);
|
cursorLeft(cur, true);
|
||||||
|
cur.bv().cursor() = cur;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_FINISHED_RIGHT:
|
case LFUN_FINISHED_RIGHT:
|
||||||
lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
|
lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
|
||||||
cur.pop(cur.currentDepth());
|
cur.pop(cur.currentDepth());
|
||||||
cur.bv().cursor() = cur;
|
|
||||||
if (!rtl())
|
if (!rtl())
|
||||||
cursorRight(true);
|
cursorRight(cur, true);
|
||||||
|
cur.bv().cursor() = cur;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_FINISHED_UP:
|
case LFUN_FINISHED_UP:
|
||||||
lyxerr << "handle LFUN_FINISHED_UP" << endl;
|
lyxerr << "handle LFUN_FINISHED_UP" << endl;
|
||||||
cur.pop(cur.currentDepth());
|
cur.pop(cur.currentDepth());
|
||||||
|
cursorUp(cur, true);
|
||||||
cur.bv().cursor() = cur;
|
cur.bv().cursor() = cur;
|
||||||
cursorUp(true);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_FINISHED_DOWN:
|
case LFUN_FINISHED_DOWN:
|
||||||
lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
|
lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
|
||||||
cur.pop(cur.currentDepth());
|
cur.pop(cur.currentDepth());
|
||||||
|
cursorDown(cur, true);
|
||||||
cur.bv().cursor() = cur;
|
cur.bv().cursor() = cur;
|
||||||
cursorDown(true);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_LAYOUT_PARAGRAPH: {
|
case LFUN_LAYOUT_PARAGRAPH: {
|
||||||
@ -1524,6 +1521,31 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
|
|||||||
.TranslateAndInsert(cmd.argument[0], this);
|
.TranslateAndInsert(cmd.argument[0], this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LFUN_FLOAT_LIST: {
|
||||||
|
LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
|
||||||
|
if (tclass.floats().typeExist(cmd.argument)) {
|
||||||
|
// not quite sure if we want this...
|
||||||
|
recordUndo(cur);
|
||||||
|
freezeUndo();
|
||||||
|
cur.clearSelection();
|
||||||
|
breakParagraph(cur);
|
||||||
|
|
||||||
|
if (cur.lastpos() != 0) {
|
||||||
|
cursorLeft(cur, true);
|
||||||
|
breakParagraph(cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
setLayout(tclass.defaultLayoutName());
|
||||||
|
setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
|
||||||
|
insertInset(new InsetFloatList(cmd.argument));
|
||||||
|
unFreezeUndo();
|
||||||
|
} else {
|
||||||
|
lyxerr << "Non-existent float type: "
|
||||||
|
<< cmd.argument << endl;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return DispatchResult(false);
|
return DispatchResult(false);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ void recordUndo(LCursor & cur, Undo::undo_kind kind,
|
|||||||
void recordUndo(LCursor & cur, Undo::undo_kind kind, lyx::paroffset_type from);
|
void recordUndo(LCursor & cur, Undo::undo_kind kind, lyx::paroffset_type from);
|
||||||
|
|
||||||
/// convienience: prepare undo for the single paragraph containing the cursor
|
/// convienience: prepare undo for the single paragraph containing the cursor
|
||||||
void recordUndo(LCursor & cur, Undo::undo_kind kind);
|
void recordUndo(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
|
||||||
|
|
||||||
/// convienience: prepare undo for the single paragraph containing the cursor
|
/// convienience: prepare undo for the single paragraph containing the cursor
|
||||||
void recordUndoFullDocument(LCursor & cur);
|
void recordUndoFullDocument(LCursor & cur);
|
||||||
|
Loading…
Reference in New Issue
Block a user