]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Run codespell on src/frontends
[lyx.git] / src / Text.cpp
index e060a6c9dd6d69e2dbf95f819063ae8f9bf23a6d..2be5b8602e31b831e765ea3f6081833709b6b4d3 100644 (file)
@@ -113,8 +113,7 @@ void breakParagraphConservative(BufferParams const & bparams,
        ParagraphList & pars, pit_type pit, pos_type pos)
 {
        // create a new paragraph
-       Paragraph & tmp = *pars.insert(lyx::next(pars.begin(), pit + 1),
-                                      Paragraph());
+       Paragraph & tmp = *pars.insert(pars.iterator_at(pit + 1), Paragraph());
        Paragraph & par = pars[pit];
 
        tmp.setInsetOwner(&par.inInset());
@@ -169,7 +168,7 @@ void mergeParagraph(BufferParams const & bparams,
        // move the change of the end-of-paragraph character
        par.setChange(par.size(), change);
 
-       pars.erase(lyx::next(pars.begin(), par_offset + 1));
+       pars.erase(pars.iterator_at(par_offset + 1));
 }
 
 
@@ -190,10 +189,8 @@ Text::Text(InsetText * owner, bool use_default_layout)
 Text::Text(InsetText * owner, Text const & text)
        : owner_(owner), pars_(text.pars_)
 {
-       ParagraphList::iterator const end = pars_.end();
-       ParagraphList::iterator it = pars_.begin();
-       for (; it != end; ++it)
-               it->setInsetOwner(owner);
+       for (auto & p : pars_)
+               p.setInsetOwner(owner);
 }
 
 
@@ -693,8 +690,7 @@ static void breakParagraph(Text & text, pit_type par_offset, pos_type pos,
        ParagraphList & pars = text.paragraphs();
        // create a new paragraph, and insert into the list
        ParagraphList::iterator tmp =
-               pars.insert(lyx::next(pars.begin(), par_offset + 1),
-                           Paragraph());
+               pars.insert(pars.iterator_at(par_offset + 1), Paragraph());
 
        Paragraph & par = pars[par_offset];
 
@@ -725,6 +721,7 @@ static void breakParagraph(Text & text, pit_type par_offset, pos_type pos,
 
                tmp->params().depth(par.params().depth());
                tmp->params().noindent(par.params().noindent());
+               tmp->params().spacing(par.params().spacing());
 
                // move everything behind the break position
                // to the new paragraph
@@ -868,12 +865,18 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str,
        pit_type pit = cur.pit();
        pos_type pos = cur.pos();
 
+       // The special chars we handle
+       map<wchar_t, InsetSpecialChar::Kind> specialchars;
+       specialchars[0x200c] = InsetSpecialChar::LIGATURE_BREAK;
+       specialchars[0x200b] = InsetSpecialChar::ALLOWBREAK;
+       specialchars[0x2026] = InsetSpecialChar::LDOTS;
+       specialchars[0x2011] = InsetSpecialChar::NOBREAKDASH;
+
        // insert the string, don't insert doublespace
        bool space_inserted = true;
-       for (docstring::const_iterator cit = str.begin();
-           cit != str.end(); ++cit) {
+       for (auto const & ch : str) {
                Paragraph & par = pars_[pit];
-               if (*cit == '\n') {
+               if (ch == '\n') {
                        if (inset().allowMultiPar() && (!par.empty() || par.allowEmpty())) {
                                lyx::breakParagraph(*this, pit, pos,
                                        par.layout().isEnvironment());
@@ -884,28 +887,35 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str,
                                continue;
                        }
                // do not insert consecutive spaces if !free_spacing
-               } else if ((*cit == ' ' || *cit == '\t') &&
+               } else if ((ch == ' ' || ch == '\t') &&
                           space_inserted && !par.isFreeSpacing()) {
                        continue;
-               } else if (*cit == '\t') {
+               } else if (ch == '\t') {
                        if (!par.isFreeSpacing()) {
                                // tabs are like spaces here
                                par.insertChar(pos, ' ', font, bparams.track_changes);
                                ++pos;
                                space_inserted = true;
                        } else {
-                               par.insertChar(pos, *cit, font, bparams.track_changes);
+                               par.insertChar(pos, ch, font, bparams.track_changes);
                                ++pos;
                                space_inserted = true;
                        }
-               } else if (!isPrintable(*cit)) {
-                       // Ignore unprintables
+               } else if (specialchars.find(ch) != specialchars.end()) {
+                       par.insertInset(pos, new InsetSpecialChar(specialchars.find(ch)->second),
+                                       font, bparams.track_changes ?
+                                               Change(Change::INSERTED)
+                                             : Change(Change::UNCHANGED));
+                       ++pos;
+                       space_inserted = false;
+               } else if (!isPrintable(ch)) {
+                       // Ignore (other) unprintables
                        continue;
                } else {
                        // just insert the character
-                       par.insertChar(pos, *cit, font, bparams.track_changes);
+                       par.insertChar(pos, ch, font, bparams.track_changes);
                        ++pos;
-                       space_inserted = (*cit == ' ');
+                       space_inserted = (ch == ' ');
                }
        }
        setCursor(cur, pit, pos);
@@ -1689,14 +1699,14 @@ bool Text::backspacePos0(Cursor & cur)
        if (cur.lastpos() == 0
            || (cur.lastpos() == 1 && par.isSeparator(0))) {
                cur.recordUndo(prevcur.pit());
-               plist.erase(lyx::next(plist.begin(), cur.pit()));
+               plist.erase(plist.iterator_at(cur.pit()));
                needsUpdate = true;
        }
        // is previous par empty?
        else if (prevcur.lastpos() == 0
                 || (prevcur.lastpos() == 1 && prevpar.isSeparator(0))) {
                cur.recordUndo(prevcur.pit());
-               plist.erase(lyx::next(plist.begin(), prevcur.pit()));
+               plist.erase(plist.iterator_at(prevcur.pit()));
                needsUpdate = true;
        }
        // FIXME: Do we really not want to allow this???
@@ -1733,7 +1743,8 @@ bool Text::backspace(Cursor & cur)
                Cursor prev_cur = cur;
                --prev_cur.pit();
 
-               if (!prev_cur.paragraph().isMergedOnEndOfParDeletion(cur.buffer()->params().track_changes)) {
+               if (cur.paragraph().size() > 0
+                   && !prev_cur.paragraph().isMergedOnEndOfParDeletion(cur.buffer()->params().track_changes)) {
                        cur.recordUndo(prev_cur.pit(), prev_cur.pit());
                        prev_cur.paragraph().setChange(prev_cur.lastpos(), Change(Change::DELETED));
                        setCursorIntern(cur, prev_cur.pit(), prev_cur.lastpos());
@@ -1767,7 +1778,7 @@ bool Text::backspace(Cursor & cur)
        needsUpdate |= handleBibitems(cur);
 
        // A singlePar update is not enough in this case.
-//             cur.screenUpdateFlags(Update::Force);
+       // cur.screenUpdateFlags(Update::Force);
        cur.top().setPitPos(cur.pit(), cur.pos());
 
        return needsUpdate;
@@ -1787,9 +1798,7 @@ bool Text::dissolveInset(Cursor & cur)
        // save position inside inset
        pos_type spos = cur.pos();
        pit_type spit = cur.pit();
-       ParagraphList plist;
-       if (cur.lastpit() != 0 || cur.lastpos() != 0)
-               plist = paragraphs();
+       bool const inset_non_empty = cur.lastpit() != 0 || cur.lastpos() != 0;
        cur.popBackward();
        // update cursor offset
        if (spit == 0)
@@ -1802,7 +1811,8 @@ bool Text::dissolveInset(Cursor & cur)
        ++cur.pos();
 
        Buffer & b = *cur.buffer();
-       if (!plist.empty()) {
+       // Is there anything in this text?
+       if (inset_non_empty) {
                // see bug 7319
                // we clear the cache so that we won't get conflicts with labels
                // that get pasted into the buffer. we should update this before
@@ -1812,13 +1822,16 @@ bool Text::dissolveInset(Cursor & cur)
                // but we'll try the cheaper solution here.
                cur.buffer()->clearReferenceCache();
 
+               ParagraphList & plist = paragraphs();
+               if (!lyxrc.ct_markup_copied)
+                       // Do not revive deleted text
+                       lyx::acceptChanges(plist, b.params());
+
                // ERT paragraphs have the Language latex_language.
                // This is invalid outside of ERT, so we need to
                // change it to the buffer language.
-               ParagraphList::iterator it = plist.begin();
-               ParagraphList::iterator it_end = plist.end();
-               for (; it != it_end; ++it)
-                       it->changeLanguage(b.params(), latex_language, b.language());
+               for (auto & p : plist)
+                       p.changeLanguage(b.params(), latex_language, b.language());
 
                /* If the inset is the only thing in paragraph and the layout
                 * is not plain, then the layout of the first paragraph of