]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Spaces in typewriter font never expand in justified text
[lyx.git] / src / Text.cpp
index b00f10de0c72edf95851c1a93db0093044345d9f..0ca32a4e931847fbad9a89becf485192e8a2025c 100644 (file)
@@ -209,7 +209,7 @@ pit_type Text::outerHook(pit_type par_offset) const
 
        if (par.getDepth() == 0)
                return pars_.size();
-       return depthHook(par_offset, depth_type(par.getDepth() - 1));
+       return depthHook(par_offset, par.getDepth() - 1);
 }
 
 
@@ -369,7 +369,7 @@ InsetText const & Text::inset() const
 void Text::readParToken(Paragraph & par, Lexer & lex,
        string const & token, Font & font, Change & change, ErrorList & errorList)
 {
-       Buffer * buf = const_cast<Buffer *>(&owner_->buffer());
+       Buffer * buf = &owner_->buffer();
        BufferParams & bp = buf->params();
 
        if (token[0] != '\\') {
@@ -859,11 +859,12 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str,
        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;
+       static map<wchar_t, InsetSpecialChar::Kind> specialchars = {
+               { 0x200c, InsetSpecialChar::LIGATURE_BREAK },
+               { 0x200b, InsetSpecialChar::ALLOWBREAK },
+               { 0x2026, InsetSpecialChar::LDOTS },
+               { 0x2011, InsetSpecialChar::NOBREAKDASH }
+       };
 
        // insert the string, don't insert doublespace
        bool space_inserted = true;
@@ -894,12 +895,12 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str,
                                ++pos;
                                space_inserted = true;
                        }
-               } else if (specialchars.find(ch) != specialchars.end()) {
-                       if (par.insertInset(pos, new InsetSpecialChar(specialchars.find(ch)->second),
-                                       font, bparams.track_changes ?
-                                               Change(Change::INSERTED)
-                                                 : Change(Change::UNCHANGED)))
-                               ++pos;
+               } 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
@@ -1368,6 +1369,20 @@ void Text::selectWord(Cursor & cur, word_location loc)
 }
 
 
+void Text::expandWordSel(Cursor & cur)
+{
+       // get selection of word around cur
+       Cursor c = cur;
+       c.selection(false);
+       c.text()->selectWord(c, WHOLE_WORD);
+       // use the correct word boundary, depending on selection direction
+       if (cur.top() > cur.normalAnchor())
+               cur.pos() = c.selEnd().pos();
+       else
+               cur.pos() = c.selBegin().pos();
+}
+
+
 void Text::selectAll(Cursor & cur)
 {
        LBUFERR(this == cur.text());
@@ -1495,7 +1510,8 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
        }
 
        // finally, invoke the DEPM
-       deleteEmptyParagraphMechanism(begPit, endPit, cur.buffer()->params().track_changes);
+       deleteEmptyParagraphMechanism(begPit, endPit, begPos, endPos,
+                                     cur.buffer()->params().track_changes);
 
        cur.finishUndo();
        cur.clearSelection();
@@ -1880,6 +1896,7 @@ bool Text::dissolveInset(Cursor & cur)
                }
 
                pasteParagraphList(cur, plist, b.params().documentClassPtr(),
+                                  b.params().authors(),
                                   b.errorList("Paste"));
        }
 
@@ -2146,7 +2163,10 @@ docstring Text::currentState(CursorData const & cur, bool devel_mode) const
                if (!par.empty() && cur.pos() < par.size()) {
                        // Force output of code point, not character
                        size_t const c = par.getChar(cur.pos());
-                       os << _(", Char: 0x") << hex << c;
+                       if (c == META_INSET)
+                               os << ", Char: INSET";
+                       else
+                               os << _(", Char: 0x") << hex << c;
                }
                os << _(", Boundary: ") << cur.boundary();
 //             Row & row = cur.textRow();
@@ -2361,7 +2381,8 @@ void Text::setMacrocontextPosition(DocIterator const & pos)
 bool Text::completionSupported(Cursor const & cur) const
 {
        Paragraph const & par = cur.paragraph();
-       return !cur.selection()
+       return !cur.buffer()->isReadonly()
+               && !cur.selection()
                && cur.pos() > 0
                && (cur.pos() >= par.size() || par.isWordSeparator(cur.pos()))
                && !par.isWordSeparator(cur.pos() - 1);
@@ -2375,9 +2396,12 @@ CompletionList const * Text::createCompletionList(Cursor const & cur) const
 }
 
 
-bool Text::insertCompletion(Cursor & cur, docstring const & s, bool /*finished*/)
+bool Text::insertCompletion(Cursor & cur, docstring const & s)
 {
        LBUFERR(cur.bv().cursor() == cur);
+       if (cur.buffer()->isReadonly())
+               return false;
+       cur.recordUndo();
        cur.insert(s);
        cur.bv().cursor() = cur;
        if (!(cur.result().screenUpdate() & Update::Force))