+// needed to insert the selection
+void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
+ LyXFont const & fn,string const & str) const
+{
+ LyXLayout const & layout = textclasslist.Style(params.textclass,
+ par->getLayout());
+ LyXFont font = fn;
+
+ (void)par->checkInsertChar(font);
+ // insert the string, don't insert doublespace
+ bool space_inserted = true;
+ for(string::const_iterator cit = str.begin();
+ cit != str.end(); ++cit) {
+ if (*cit == '\n') {
+ if (par->size() || layout.keepempty) {
+ par->breakParagraph(params, pos,
+ layout.isEnvironment());
+ par = par->next();
+ pos = 0;
+ space_inserted = true;
+ } else {
+ continue;
+ }
+ // do not insert consecutive spaces if !free_spacing
+ } else if ((*cit == ' ' || *cit == '\t') &&
+ space_inserted && !layout.free_spacing &&
+ !par->isFreeSpacing())
+ {
+ continue;
+ } else if (*cit == '\t') {
+ if (!layout.free_spacing && !par->isFreeSpacing()) {
+ // tabs are like spaces here
+ par->insertChar(pos, ' ', font);
+ ++pos;
+ space_inserted = true;
+ } else {
+ const pos_type nb = 8 - pos % 8;
+ for (pos_type a = 0; a < nb ; ++a) {
+ par->insertChar(pos, ' ', font);
+ ++pos;
+ }
+ space_inserted = true;
+ }
+ } else if (!IsPrintable(*cit)) {
+ // Ignore unprintables
+ continue;
+ } else {
+ // just insert the character
+ par->insertChar(pos, *cit, font);
+ ++pos;
+ space_inserted = (*cit == ' ');
+ }
+
+ }
+}
+