]> git.lyx.org Git - lyx.git/blobdiff - src/Text2.cpp
Cleanup: Replace a bunch of Cursor arguments with DocIterators.
[lyx.git] / src / Text2.cpp
index c55b9e2a42afc02b80afd5bbfd5182bf21c6e200..5eedf4f3078bcf079c0844e8ec7924c8f8596f01 100644 (file)
@@ -503,16 +503,60 @@ void Text::insertInset(Cursor & cur, Inset * inset)
 
 
 // needed to insert the selection
-void Text::insertStringAsLines(Cursor & cur, docstring const & str)
+void Text::insertStringAsLines(DocIterator const & dit, docstring const & str,
+               Font const & font)
 {
-       cur.buffer()->insertStringAsLines(pars_, cur.pit(), cur.pos(),
-               cur.current_font, str, autoBreakRows_);
+       BufferParams const & bparams = owner_->buffer().params();
+       pit_type pit = dit.pit();
+       pos_type pos = dit.pos();
+
+       // insert the string, don't insert doublespace
+       bool space_inserted = true;
+       for (docstring::const_iterator cit = str.begin();
+           cit != str.end(); ++cit) {
+               Paragraph & par = pars_[pit];
+               if (*cit == '\n') {
+                       if (autoBreakRows_ && (!par.empty() || par.allowEmpty())) {
+                               lyx::breakParagraph(bparams, pars_, pit, pos,
+                                              par.layout().isEnvironment());
+                               ++pit;
+                               pos = 0;
+                               space_inserted = true;
+                       } else {
+                               continue;
+                       }
+                       // do not insert consecutive spaces if !free_spacing
+               } else if ((*cit == ' ' || *cit == '\t') &&
+                          space_inserted && !par.isFreeSpacing()) {
+                       continue;
+               } else if (*cit == '\t') {
+                       if (!par.isFreeSpacing()) {
+                               // tabs are like spaces here
+                               par.insertChar(pos, ' ', font, bparams.trackChanges);
+                               ++pos;
+                               space_inserted = true;
+                       } else {
+                               par.insertChar(pos, *cit, font, bparams.trackChanges);
+                               ++pos;
+                               space_inserted = true;
+                       }
+               } else if (!isPrintable(*cit)) {
+                       // Ignore unprintables
+                       continue;
+               } else {
+                       // just insert the character
+                       par.insertChar(pos, *cit, font, bparams.trackChanges);
+                       ++pos;
+                       space_inserted = (*cit == ' ');
+               }
+       }
 }
 
 
 // turn double CR to single CR, others are converted into one
 // blank. Then insertStringAsLines is called
-void Text::insertStringAsParagraphs(Cursor & cur, docstring const & str)
+void Text::insertStringAsParagraphs(DocIterator const & dit, docstring const & str,
+               Font const & font)
 {
        docstring linestr = str;
        bool newline_inserted = false;
@@ -533,7 +577,7 @@ void Text::insertStringAsParagraphs(Cursor & cur, docstring const & str)
                        newline_inserted = false;
                }
        }
-       insertStringAsLines(cur, linestr);
+       insertStringAsLines(dit, linestr, font);
 }