]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Fix #10778 (issue with CJK and language nesting)
[lyx.git] / src / Text.cpp
index 67776a0d40df01a4cf8655c9f33a00188e29ccb3..4e593ddf23ca619f1bcf8d3a12cadd74abbca8da 100644 (file)
@@ -67,6 +67,7 @@
 #include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/lyxalgo.h"
+#include "support/lyxtime.h"
 #include "support/textutils.h"
 
 #include <sstream>
@@ -135,7 +136,7 @@ void breakParagraphConservative(BufferParams const & bparams,
        ParagraphList & pars, pit_type par_offset, pos_type pos)
 {
        // create a new paragraph
-       Paragraph & tmp = *pars.insert(next(pars.begin(), par_offset + 1),
+       Paragraph & tmp = *pars.insert(lyx::next(pars.begin(), par_offset + 1),
                                       Paragraph());
        Paragraph & par = pars[par_offset];
 
@@ -360,7 +361,7 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
        string const & token, Font & font, Change & change, ErrorList & errorList)
 {
        Buffer * buf = const_cast<Buffer *>(&owner_->buffer());
-       BufferParams const & bp = buf->params();
+       BufferParams & bp = buf->params();
 
        if (token[0] != '\\') {
                docstring dstr = lex.getDocString();
@@ -534,18 +535,25 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
                int aid;
                time_t ct;
                is >> aid >> ct;
-               BufferParams::AuthorMap const & am = bp.author_map;
+               BufferParams::AuthorMap const & am = bp.author_map_;
                if (am.find(aid) == am.end()) {
-                       errorList.push_back(ErrorItem(_("Change tracking error"),
-                                           bformat(_("Unknown author index for change: %1$d\n"), aid),
-                                           par.id(), 0, par.size()));
-                       change = Change(Change::UNCHANGED);
-               } else {
-                       if (token == "\\change_inserted")
-                               change = Change(Change::INSERTED, am.find(aid)->second, ct);
-                       else
-                               change = Change(Change::DELETED, am.find(aid)->second, ct);
+                       errorList.push_back(ErrorItem(
+                               _("Change tracking author index missing"),
+                               bformat(_("A change tracking author information for index "
+                                         "%1$d is missing. This can happen after a wrong "
+                                         "merge by a version control system. In this case, "
+                                         "either fix the merge, or have this information "
+                                         "missing until the corresponding tracked changes "
+                                         "are merged or this user edits the file again.\n"),
+                                       aid),
+                               par.id(), par.size(), par.size() + 1
+                               ));
+                       bp.addAuthor(Author(aid));
                }
+               if (token == "\\change_inserted")
+                       change = Change(Change::INSERTED, am.find(aid)->second, ct);
+               else
+                       change = Change(Change::DELETED, am.find(aid)->second, ct);
        } else {
                lex.eatLine();
                errorList.push_back(ErrorItem(_("Unknown token"),
@@ -661,7 +669,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(next(pars.begin(), par_offset + 1),
+               pars.insert(lyx::next(pars.begin(), par_offset + 1),
                            Paragraph());
 
        Paragraph & par = pars[par_offset];
@@ -756,12 +764,17 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
        Layout const & layout = cpar.layout();
 
        if (cur.lastpos() == 0 && !cpar.allowEmpty()) {
-               if (changeDepthAllowed(cur, DEC_DEPTH))
+               if (changeDepthAllowed(cur, DEC_DEPTH)) {
                        changeDepth(cur, DEC_DEPTH);
-               else {
+                       pit_type const prev = depthHook(cpit, cpar.getDepth());
+                       docstring const & lay = pars_[prev].layout().name();
+                       if (lay != layout.name())
+                               setLayout(cur, lay);
+               } else {
                        docstring const & lay = cur.paragraph().usePlainLayout()
                            ? tclass.plainLayoutName() : tclass.defaultLayoutName();
-                       setLayout(cur, lay);
+                       if (lay != layout.name())
+                               setLayout(cur, lay);
                }
                return;
        }
@@ -1043,7 +1056,7 @@ void Text::insertChar(Cursor & cur, char_type c)
 
        pos_type pos = cur.pos();
        if (!cur.paragraph().isPassThru() && owner_->lyxCode() != IPA_CODE &&
-           cur.current_font.fontInfo().family() != TYPEWRITER_FAMILY &&
+           cur.real_current_font.fontInfo().family() != TYPEWRITER_FAMILY &&
            c == '-' && pos > 0) {
                if (par.getChar(pos - 1) == '-') {
                        // convert "--" to endash
@@ -1055,11 +1068,6 @@ void Text::insertChar(Cursor & cur, char_type c)
                        par.eraseChar(pos - 1, cur.buffer()->params().track_changes);
                        c = 0x2014;
                        pos--;
-               } else if (par.getChar(pos - 1) == 0x2014) {
-                       // convert "----" to "-"
-                       par.eraseChar(pos - 1, cur.buffer()->params().track_changes);
-                       c = '-';
-                       pos--;
                }
        }
 
@@ -1103,7 +1111,7 @@ bool Text::cursorForwardOneWord(Cursor & cur)
        Paragraph const & par = cur.paragraph();
 
        // Paragraph boundary is a word boundary
-       if (pos == lastpos) {
+       if (pos == lastpos || (pos + 1 == lastpos && par.isEnvSeparator(pos))) {
                if (pit != cur.lastpit())
                        return setCursor(cur, pit + 1, 0);
                else
@@ -1136,6 +1144,10 @@ bool Text::cursorForwardOneWord(Cursor & cur)
                             ++pos;
        }
 
+       // Don't skip a separator inset at the end of a paragraph
+       if (pos == lastpos && pos && par.isEnvSeparator(pos - 1))
+               --pos;
+
        return setCursor(cur, pit, pos);
 }
 
@@ -1149,8 +1161,14 @@ bool Text::cursorBackwardOneWord(Cursor & cur)
        Paragraph & par = cur.paragraph();
 
        // Paragraph boundary is a word boundary
-       if (pos == 0 && pit != 0)
-               return setCursor(cur, pit - 1, getPar(pit - 1).size());
+       if (pos == 0 && pit != 0) {
+               Paragraph & prevpar = getPar(pit - 1);
+               pos = prevpar.size();
+               // Don't stop after an environment separator
+               if (pos && prevpar.isEnvSeparator(pos - 1))
+                       --pos;
+               return setCursor(cur, pit - 1, pos);
+       }
 
        if (lyxrc.mac_like_cursor_movement) {
                // Skip through punctuation and spaces.
@@ -1259,7 +1277,7 @@ void Text::selectWord(Cursor & cur, word_location loc)
 {
        LBUFERR(this == cur.text());
        CursorSlice from = cur.top();
-       CursorSlice to = cur.top();
+       CursorSlice to;
        getWord(from, to, loc);
        if (cur.top() != from)
                setCursor(cur, from.pit(), from.pos());
@@ -1593,6 +1611,7 @@ bool Text::erase(Cursor & cur)
                        return dissolveInset(cur);
 
                if (!par.isMergedOnEndOfParDeletion(cur.buffer()->params().track_changes)) {
+                       cur.recordUndo(DELETE_UNDO);
                        par.setChange(cur.pos(), Change(Change::DELETED));
                        cur.forwardPos();
                        needsUpdate = true;
@@ -1636,14 +1655,14 @@ bool Text::backspacePos0(Cursor & cur)
        if (cur.lastpos() == 0
            || (cur.lastpos() == 1 && par.isSeparator(0))) {
                cur.recordUndo(prevcur.pit());
-               plist.erase(next(plist.begin(), cur.pit()));
+               plist.erase(lyx::next(plist.begin(), 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(next(plist.begin(), prevcur.pit()));
+               plist.erase(lyx::next(plist.begin(), prevcur.pit()));
                needsUpdate = true;
        }
        // Pasting is not allowed, if the paragraphs have different
@@ -1883,13 +1902,11 @@ docstring Text::currentState(Cursor const & cur) const
        Change change = par.lookupChange(cur.pos());
 
        if (change.changed()) {
-               Author const & a = buf.params().authors().get(change.author);
-               os << _("Change: ") << a.name();
-               if (!a.email().empty())
-                       os << " (" << a.email() << ")";
-               // FIXME ctime is english, we should translate that
-               os << _(" at ") << ctime(&change.changetime);
-               os << " : ";
+               docstring const author =
+                       buf.params().authors().get(change.author).nameAndEmail();
+               docstring const date = formatted_datetime(change.changetime);
+               os << bformat(_("Changed by %1$s[[author]] on %2$s[[date]]. "),
+                             author, date);
        }
 
        // I think we should only show changes from the default