#include "Cursor.h"
#include "CutAndPaste.h"
#include "DispatchResult.h"
-#include "Encoding.h"
#include "ErrorList.h"
#include "FuncRequest.h"
#include "factory.h"
#include "insets/InsetNewline.h"
#include "insets/InsetNewpage.h"
#include "insets/InsetArgument.h"
+#include "insets/InsetIPAMacro.h"
#include "insets/InsetSpace.h"
#include "insets/InsetSpecialChar.h"
#include "insets/InsetTabular.h"
+#include "support/convert.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/gettext.h"
tmp.setInsetOwner(&par.inInset());
tmp.makeSameLayout(par);
- LASSERT(pos <= par.size(), /**/);
+ LASSERT(pos <= par.size(), return);
if (pos < par.size()) {
// move everything behind the break position to the new paragraph
}
+int Text::getTocLevel(pit_type par_offset) const
+{
+ Paragraph const & par = pars_[par_offset];
+
+ if (par.layout().isEnvironment() && !isFirstInSequence(par_offset))
+ return Layout::NOT_IN_TOC;
+
+ return par.layout().toclevel;
+}
+
+
Font const Text::outerFont(pit_type par_offset) const
{
depth_type par_depth = pars_[par_offset].getDepth();
inset->read(lex);
inset->setBuffer(*buf);
par.insertInset(par.size(), inset.release(), font, change);
+ } else if (token == "\\IPAChar") {
+ auto_ptr<Inset> inset;
+ inset.reset(new InsetIPAChar);
+ inset->read(lex);
+ inset->setBuffer(*buf);
+ par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\backslash") {
par.appendChar('\\', font, change);
} else if (token == "\\LyXTable") {
public:
///
TextCompletionList(Cursor const & cur, WordList const * list)
- : buffer_(cur.buffer()), pos_(0), list_(list)
+ : buffer_(cur.buffer()), list_(list)
{}
///
virtual ~TextCompletionList() {}
///
Buffer const * buffer_;
///
- size_t pos_;
- ///
WordList const * list_;
};
void Text::breakParagraph(Cursor & cur, bool inverse_logic)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
Paragraph & cpar = cur.paragraph();
pit_type cpit = cur.pit();
return;
}
- // a layout change may affect also the following paragraph
- recUndo(cur, cur.pit(), undoSpan(cur.pit()) - 1);
+ cur.recordUndo();
// Always break behind a space
// It is better to erase the space (Dekel)
// same Paragraph one to the right and make a rebreak
void Text::insertChar(Cursor & cur, char_type c)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
cur.recordUndo(INSERT_UNDO);
"beginning of a paragraph. Please read the Tutorial."));
return;
}
+ // LASSERT: Is it safe to continue here?
LASSERT(cur.pos() > 0, /**/);
if ((par.isLineSeparator(cur.pos() - 1) || par.isNewline(cur.pos() - 1))
&& !par.isDeleted(cur.pos() - 1)) {
&& !par.isWordSeparator(cur.pos() - 2)
&& par.isWordSeparator(cur.pos() - 1)) {
// get the word in front of cursor
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
cur.paragraph().updateWords();
}
}
bool Text::cursorForwardOneWord(Cursor & cur)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
pos_type const lastpos = cur.lastpos();
pit_type pit = cur.pit();
else while (pos != lastpos && !par.isWordSeparator(pos))
++pos;
} else {
- LASSERT(pos < lastpos, /**/); // see above
+ LASSERT(pos < lastpos, return false); // see above
if (!par.isWordSeparator(pos))
while (pos != lastpos && !par.isWordSeparator(pos))
++pos;
bool Text::cursorBackwardOneWord(Cursor & cur)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
pit_type pit = cur.pit();
pos_type pos = cur.pos();
bool Text::cursorVisLeftOneWord(Cursor & cur)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
pos_type left_pos, right_pos;
bool left_is_letter, right_is_letter;
bool Text::cursorVisRightOneWord(Cursor & cur)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
pos_type left_pos, right_pos;
bool left_is_letter, right_is_letter;
void Text::selectWord(Cursor & cur, word_location loc)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
CursorSlice from = cur.top();
CursorSlice to = cur.top();
getWord(from, to, loc);
void Text::selectAll(Cursor & cur)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
if (cur.lastpos() == 0 && cur.lastpit() == 0)
return;
// If the cursor is at the beginning, make sure the cursor ends there
// selection is currently set
bool Text::selectWordWhenUnderCursor(Cursor & cur, word_location loc)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
if (cur.selection())
return false;
selectWord(cur, loc);
void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
if (!cur.selection()) {
bool const changed = cur.paragraph().isChanged(cur.pos());
void Text::deleteWordForward(Cursor & cur)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
if (cur.lastpos() == 0)
cursorForward(cur);
else {
void Text::deleteWordBackward(Cursor & cur)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
if (cur.lastpos() == 0)
cursorBackward(cur);
else {
// Kill to end of line.
void Text::changeCase(Cursor & cur, TextCase action)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
CursorSlice from;
CursorSlice to;
bool Text::backspacePos0(Cursor & cur)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
if (cur.pit() == 0)
return false;
bool Text::backspace(Cursor & cur)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
bool needsUpdate = false;
if (cur.pos() == 0) {
if (cur.pit() == 0)
return dissolveInset(cur);
- Paragraph & prev_par = pars_[cur.pit() - 1];
+ Cursor prev_cur = cur;
+ --prev_cur.pit();
- if (!prev_par.isMergedOnEndOfParDeletion(cur.buffer()->params().trackChanges)) {
- prev_par.setChange(prev_par.size(), Change(Change::DELETED));
- setCursorIntern(cur, cur.pit() - 1, prev_par.size());
+ if (!prev_cur.paragraph().isMergedOnEndOfParDeletion(cur.buffer()->params().trackChanges)) {
+ cur.recordUndo(ATOMIC_UNDO, prev_cur.pit(), prev_cur.pit());
+ prev_cur.paragraph().setChange(prev_cur.lastpos(), Change(Change::DELETED));
+ setCursorIntern(cur, prev_cur.pit(), prev_cur.lastpos());
return true;
}
// The cursor is at the beginning of a paragraph, so
// change it to the buffer language.
ParagraphList::iterator it = plist.begin();
ParagraphList::iterator it_end = plist.end();
- for (; it != it_end; it++)
+ for (; it != it_end; ++it)
it->changeLanguage(b.params(), latex_language, b.language());
pasteParagraphList(cur, plist, b.params().documentClassPtr(),
return res;
}
+
// Returns the current font and depth as a message.
docstring Text::currentState(Cursor const & cur) const
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
Buffer & buf = *cur.buffer();
Paragraph const & par = cur.paragraph();
odocstringstream os;
// For captions, we just take the caption type
Inset * caption_inset = cur.innerInsetOfType(CAPTION_CODE);
if (caption_inset) {
- string const & ftype = static_cast<InsetCaption *>(caption_inset)->type();
+ string const & ftype = static_cast<InsetCaption *>(caption_inset)->floattype();
FloatList const & fl = cur.buffer()->params().documentClass().floats();
if (fl.typeExist(ftype)) {
Floating const & flt = fl.getType(ftype);
if (!name.empty())
text = name + ':' + text;
- return text;
+ // We need a unique label
+ docstring label = text;
+ int i = 1;
+ while (cur.buffer()->insetLabel(label)) {
+ label = text + '-' + convert<docstring>(i);
+ ++i;
+ }
+
+ return label;
}
void Text::charsTranspose(Cursor & cur)
{
- LASSERT(this == cur.text(), /**/);
+ LBUFERR(this == cur.text());
pos_type pos = cur.pos();
bool Text::insertCompletion(Cursor & cur, docstring const & s, bool /*finished*/)
{
- LASSERT(cur.bv().cursor() == cur, /**/);
+ LBUFERR(cur.bv().cursor() == cur);
cur.insert(s);
cur.bv().cursor() = cur;
if (!(cur.result().screenUpdate() & Update::Force))