#include <boost/next_prior.hpp>
-using lyx::docstring;
-using lyx::odocstream;
-using lyx::pos_type;
+
+namespace lyx {
using std::endl;
using std::upper_bound;
};
special_phrase const special_phrases[] = {
- { "LyX", lyx::from_ascii("\\LyX{}"), false },
- { "TeX", lyx::from_ascii("\\TeX{}"), true },
- { "LaTeX2e", lyx::from_ascii("\\LaTeXe{}"), true },
- { "LaTeX", lyx::from_ascii("\\LaTeX{}"), true },
+ { "LyX", from_ascii("\\LyX{}"), false },
+ { "TeX", from_ascii("\\TeX{}"), true },
+ { "LaTeX2e", from_ascii("\\LaTeXe{}"), true },
+ { "LaTeX", from_ascii("\\LaTeX{}"), true },
};
size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
Paragraph::Pimpl::Pimpl(Pimpl const & p, Paragraph * owner)
- : params(p.params), owner_(owner)
+ : params(p.params), changes_(p.changes_), owner_(owner)
{
inset_owner = p.inset_owner;
fontlist = p.fontlist;
id_ = paragraph_id++;
-
- if (p.tracking())
- changes_.reset(new Changes(*p.changes_.get()));
}
void Paragraph::Pimpl::setContentsFromPar(Paragraph const & par)
{
owner_->text_ = par.text_;
- if (par.pimpl_->tracking()) {
- changes_.reset(new Changes(*(par.pimpl_->changes_.get())));
- }
+ // FIXME: change tracking (MG)
+ // check whether this method is really needed
+ changes_ = par.pimpl_->changes_;
}
bool Paragraph::Pimpl::isChanged(pos_type start, pos_type end) const
{
- // FIXME: change tracking (MG)
- if (!tracking())
- return false;
-
- return changes_->isChange(start, end);
+ return changes_.isChanged(start, end);
}
void Paragraph::Pimpl::setChange(Change const & change)
{
// FIXME: change tracking (MG)
- // changes_.set(change, 0, size());
+ // how about end-of-line? size()+1?
+ changes_.set(change, 0, size());
if (change.type == Change::UNCHANGED) { // only for UNCHANGED ???
for (pos_type i = 0; i < size(); ++i) {
if (owner_->isInset(i)) {
- // FIXME: change tracking (MG)
- // owner_->getInset(i)->setChange(change);
+ owner_->getInset(i)->setChange(change);
}
}
}
void Paragraph::Pimpl::setChange(pos_type pos, Change const & change)
{
- if (!tracking())
- return;
+ changes_.set(change, pos);
- changes_->set(change, pos);
+ // FIXME: change tracking (MG)
+ // do we have to set the change recursively?
+ if (pos < size() && owner_->isInset(pos)) {
+ owner_->getInset(pos)->setChange(change);
+ }
}
Change const Paragraph::Pimpl::lookupChange(pos_type pos) const
{
- if (!tracking())
- return Change(Change::UNCHANGED);
-
- return changes_->lookup(pos);
+ return changes_.lookup(pos);
}
void Paragraph::Pimpl::acceptChange(pos_type start, pos_type end)
{
- if (!tracking())
- return;
+ // FIXME: change tracking (MG)
+ return;
- if (!size()) {
- changes_.reset(new Changes(Change::UNCHANGED));
- return;
- }
+ // care for empty pars
lyxerr[Debug::CHANGES] << "acceptchange" << endl;
pos_type i = start;
case Change::INSERTED:
// FIXME: change tracking (MG)
- changes_->set(Change(Change::UNCHANGED), i);
+ changes_.set(Change(Change::UNCHANGED), i);
break;
case Change::DELETED:
// Suppress access to nonexistent
// "end-of-paragraph char":
if (i < size()) {
- erase(i);
+ eraseChar(i, false);
--end;
--i;
}
}
lyxerr[Debug::CHANGES] << "endacceptchange" << endl;
- changes_->reset(Change::UNCHANGED);
+ // FIXME: change tracking (MG)
+ // changes_.reset(Change::UNCHANGED);
}
void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end)
{
- if (!tracking())
- return;
+ // FIXME: change tracking (MG)
+ return;
- if (!size()) {
- changes_.reset(new Changes(Change::UNCHANGED));
- return;
- }
+ // care for empty pars
pos_type i = start;
case Change::INSERTED:
if (i < size()) {
- erase(i);
+ eraseChar(i, false);
--end;
--i;
}
case Change::DELETED:
// FIXME: change tracking (MG)
- changes_->set(Change(Change::UNCHANGED), i);
+ changes_.set(Change(Change::UNCHANGED), i);
// No real char at position size():
if (i < size() && owner_->isInset(i))
// FIXME: change tracking (MG)
break;
}
}
- changes_->reset(Change::UNCHANGED);
+ // FIXME: change tracking (MG)
+ // changes_.reset(Change::UNCHANGED);
}
{
BOOST_ASSERT(pos <= size());
- if (tracking()) {
- changes_->record(change, pos);
- }
+ // track change
+ changes_.insert(change, pos);
// This is actually very common when parsing buffers (and
// maybe inserting ascii text)
// Update the font table.
FontTable search_font(pos, LyXFont());
- for (FontList::iterator it = lower_bound(fontlist.begin(),
- fontlist.end(),
- search_font, matchFT());
+ for (FontList::iterator it
+ = lower_bound(fontlist.begin(), fontlist.end(), search_font, matchFT());
it != fontlist.end(); ++it)
{
it->pos(it->pos() + 1);
}
-void Paragraph::Pimpl::insertInset(pos_type pos,
- InsetBase * inset, Change const & change)
+void Paragraph::Pimpl::insertInset(pos_type pos, InsetBase * inset,
+ Change const & change)
{
BOOST_ASSERT(inset);
BOOST_ASSERT(pos <= size());
}
-void Paragraph::Pimpl::erase(pos_type pos)
+bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges)
{
- // FIXME: change tracking (MG)
- // do something like changes_->erase(i);
- // in one of the next patches, the two erase functions
- // will be merged but I don't want to break too many things at the same time :-)
+ BOOST_ASSERT(pos <= size());
+
+ if (trackChanges) {
+ Change::Type changetype(changes_.lookup(pos).type);
+
+ if (changetype == Change::UNCHANGED) {
+ setChange(pos, Change(Change::DELETED));
+ return false;
+ }
+
+ if (changetype == Change::DELETED)
+ return false;
+ }
+
+ // Don't physically access nonexistent end-of-paragraph char
+ if (pos == size()) {
+ // FIXME: change tracking (MG)
+ // how do we handle end-of-pars previously marked inserted?
+ return false;
+ }
+
+ // track change
+ changes_.erase(pos);
// if it is an inset, delete the inset entry
if (owner_->text_[pos] == Paragraph::META_INSET) {
// Update the insetlist
owner_->insetlist.decreasePosAfterPos(pos);
-}
-
-
-bool Paragraph::Pimpl::erase(pos_type pos, bool trackChanges)
-{
- // FIXME: change tracking (MG)
- BOOST_ASSERT(pos <= size());
-
- if (tracking()) {
- Change::Type changetype(changes_->lookup(pos).type);
-
- // only allow the actual removal if it was /new/ text
- if (changetype != Change::INSERTED) {
- changes_->record(Change(Change::DELETED), pos);
- if (pos < size() && owner_->isInset(pos))
- // FIXME: change tracking (MG)
- owner_->getInset(pos)->setChange(Change(Change::DELETED));
- return false;
- }
- }
-
- // Don't physically access nonexistent end-of-paragraph char
- if (pos < size()) {
- erase(pos);
- return true;
- }
- return false;
+ return true;
}
-int Paragraph::Pimpl::erase(pos_type start, pos_type end, bool trackChanges)
+int Paragraph::Pimpl::eraseChars(pos_type start, pos_type end, bool trackChanges)
{
pos_type i = start;
for (pos_type count = end - start; count; --count) {
- if (!erase(i, trackChanges))
+ if (!eraseChar(i, trackChanges))
++i;
}
return end - i;
column += 15;
break;
- case '±': case '²': case '³':
- case '×': case '÷': case '¹':
- case '¬': case 'µ':
+ // The following characters could be written literally in latin1, but they
+ // would be wrongly converted on systems where char is signed, so we give
+ // the code points.
+ // This also makes us independant from the encoding of this source file.
+ case 0xb1: // ± PLUS-MINUS SIGN
+ case 0xb2: // ² SUPERSCRIPT TWO
+ case 0xb3: // ³ SUPERSCRIPT THREE
+ case 0xd7: // × MULTIPLICATION SIGN
+ case 0xf7: // ÷ DIVISION SIGN
+ case 0xb9: // ¹ SUPERSCRIPT ONE
+ case 0xac: // ¬ NOT SIGN
+ case 0xb5: // µ MICRO SIGN
if ((bparams.inputenc == "latin1" ||
bparams.inputenc == "latin9") ||
(bparams.inputenc == "auto" &&
column += 9;
break;
- case '£':
+ case 0xa3: // £ POUND SIGN
if (bparams.inputenc == "default") {
os << "\\pounds{}";
column += 8;
}
}
}
+
+
+} // namespace lyx