]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph_pimpl.C
LFUN_UNICODE_INSERT - unicode-insert
[lyx.git] / src / paragraph_pimpl.C
index 5d8055b963ade18ec07b28f2ecce69b028654f84..ff3bd2f2c3f2d729762577d8d5e2797fbfd83a1c 100644 (file)
@@ -82,15 +82,13 @@ void Paragraph::Pimpl::setContentsFromPar(Paragraph const & par)
 {
        owner_->text_ = par.text_;
        // 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)
-       return false;
-
        return changes_.isChanged(start, end);
 }
 
@@ -98,9 +96,7 @@ bool Paragraph::Pimpl::isChanged(pos_type start, pos_type end) const
 void Paragraph::Pimpl::setChange(Change const & change)
 {
        // FIXME: change tracking (MG)
-
-       return;
-
+       // how about end-of-line? size()+1?
        changes_.set(change, 0, size());
 
        if (change.type == Change::UNCHANGED) { // only for UNCHANGED ???
@@ -115,18 +111,18 @@ void Paragraph::Pimpl::setChange(Change const & change)
 
 void Paragraph::Pimpl::setChange(pos_type pos, Change const & change)
 {
-       // FIXME: change tracking (MG)
-       return;
-
        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
 {
-       // FIXME: change tracking (MG)
-       return Change(Change::UNCHANGED);
-
        return changes_.lookup(pos);
 }
 
@@ -155,7 +151,7 @@ void Paragraph::Pimpl::acceptChange(pos_type start, pos_type end)
                                // Suppress access to nonexistent
                                // "end-of-paragraph char":
                                if (i < size()) {
-                                       erase(i);
+                                       eraseChar(i, false);
                                        --end;
                                        --i;
                                }
@@ -185,7 +181,7 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end)
 
                        case Change::INSERTED:
                                if (i < size()) {
-                                       erase(i);
+                                       eraseChar(i, false);
                                        --end;
                                        --i;
                                }
@@ -216,10 +212,8 @@ void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change const & cha
 {
        BOOST_ASSERT(pos <= size());
 
-       // FIXME: change tracking (MG)
-       if (false) {
-               changes_.record(change, pos);
-       }
+       // track change
+       changes_.insert(change, pos);
 
        // This is actually very common when parsing buffers (and
        // maybe inserting ascii text)
@@ -233,9 +227,8 @@ void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change const & cha
 
        // 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);
@@ -246,8 +239,8 @@ void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change const & cha
 }
 
 
-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());
@@ -260,12 +253,31 @@ void Paragraph::Pimpl::insertInset(pos_type pos,
 }
 
 
-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) {
@@ -306,42 +318,16 @@ void Paragraph::Pimpl::erase(pos_type pos)
 
        // Update the insetlist
        owner_->insetlist.decreasePosAfterPos(pos);
-}
-
-
-bool Paragraph::Pimpl::erase(pos_type pos, bool /*trackChanges*/)
-{
-       BOOST_ASSERT(pos <= size());
 
-       // FIXME: change tracking (MG)
-       if (false) {
-               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;
@@ -542,9 +528,18 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                        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" &&
@@ -618,7 +613,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
                        column += 9;
                        break;
 
-               case '£':
+               case 0xa3:    // £ POUND SIGN
                        if (bparams.inputenc == "default") {
                                os << "\\pounds{}";
                                column += 8;