hopefully this one is ok thanks john -- "Please let's not resume the argument with the usual whining about how this feature will wipe out humanity or bring us to the promised land." - Charles Campbell on magic words in Subject: headers
Index: src/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.189 diff -u -r1.189 ChangeLog --- src/ChangeLog 2001/06/12 16:42:07 1.189 +++ src/ChangeLog 2001/06/12 23:09:40 @@ -1,3 +1,15 @@ +2001-06-13 John Levon <[EMAIL PROTECTED]> + + * CutAndPaste.C: spaces -> tabs + + * lyxfind.C: + * lyxparagraph.h: + * lyxtext.h: + * paragraph.C: + * text2.C: split text->SelectionAsString and + paragraph->String into WithLabels and no-labels versions, + fixes bug when pasting ASCII outside of LyX (bug #228457) + 2001-06-12 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> * gettext.C: include LString.h even when --disable-nls is on. Index: src/CutAndPaste.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/CutAndPaste.C,v retrieving revision 1.31 diff -u -r1.31 CutAndPaste.C --- src/CutAndPaste.C 2001/05/30 13:53:25 1.31 +++ src/CutAndPaste.C 2001/06/12 23:09:41 @@ -56,17 +56,17 @@ // Perhaps it even should take a parameter? (Lgb) void DeleteBuffer() { - if (!buf) + if (!buf) return; - LyXParagraph * tmppar; + LyXParagraph * tmppar; - while (buf) { + while (buf) { tmppar = buf; buf = buf->next(); delete tmppar; - } - buf = 0; + } + buf = 0; } } // namespace anon @@ -320,11 +320,11 @@ LyXTextClassList::size_type c2, LyXParagraph * par) { - int ret = 0; - if (!par || c1 == c2) + int ret = 0; + if (!par || c1 == c2) return ret; - while (par) { + while (par) { string const name = textclasslist.NameOfLayout(c1, par->layout); int lay = 0; @@ -350,14 +350,13 @@ par->InsertInset(0, new_inset); } par = par->next(); - } - return ret; + } + return ret; } bool CutAndPaste::checkPastePossible(LyXParagraph *) { - if (!buf) return false; - - return true; + if (!buf) return false; + return true; } Index: src/lyxfind.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfind.C,v retrieving revision 1.7 diff -u -r1.7 lyxfind.C --- src/lyxfind.C 2001/05/31 02:23:41 1.7 +++ src/lyxfind.C 2001/06/12 23:09:59 @@ -47,7 +47,7 @@ // if nothing selected or selection does not equal search string // search and select next occurance and return if no replaceall - if (searchstr!=bv->text->selectionAsString(bv->buffer())) { + if (searchstr!=bv->text->selectionAsStringWithLabels(bv->buffer())) { LyXFind(bv, searchstr, casesens, matchwrd, fw); if (!replaceall) return replace_count; Index: src/lyxparagraph.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxparagraph.h,v retrieving revision 1.78 diff -u -r1.78 lyxparagraph.h --- src/lyxparagraph.h 2001/05/30 13:53:30 1.78 +++ src/lyxparagraph.h 2001/06/12 23:09:59 @@ -111,8 +111,10 @@ /// string const String(Buffer const *, bool label); - /// + /// return as string not including labels string const String(Buffer const *, size_type beg, size_type end); + /// return as string, including labels + string const StringWithLabels(Buffer const *, size_type beg, size_type end); /// void writeFile(Buffer const *, std::ostream &, BufferParams const &, Index: src/lyxtext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v retrieving revision 1.67 diff -u -r1.67 lyxtext.h --- src/lyxtext.h 2001/05/31 02:23:41 1.67 +++ src/lyxtext.h 2001/06/12 23:10:00 @@ -262,6 +262,8 @@ void ClearSelection(BufferView *) const; /// string const selectionAsString(Buffer const *) const; + /// + string const selectionAsStringWithLabels(Buffer const *) const; /// just selects the word the cursor is in void SelectWord(BufferView *); Index: src/paragraph.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v retrieving revision 1.141 diff -u -r1.141 paragraph.C --- src/paragraph.C 2001/06/07 14:51:17 1.141 +++ src/paragraph.C 2001/06/12 23:10:02 @@ -2297,6 +2297,7 @@ { BufferParams const & bparams = buffer->params; string s; + if (label && !params.labelString().empty()) s += params.labelString() + ' '; string::size_type const len = s.size(); @@ -2326,19 +2327,32 @@ { std::ostringstream ost; - if (beg == 0 && !params.labelString().empty()) - ost << params.labelString() << ' '; - for (LyXParagraph::size_type i = beg; i < end; ++i) { value_type const c = GetUChar(buffer->params, i); if (IsPrintable(c)) ost << c; - else if (c == META_INSET) { + else if (c == META_INSET) GetInset(i)->Ascii(buffer, ost); - } } return ost.str().c_str(); +} + + +string const LyXParagraph::StringWithLabels(Buffer const * buffer, + LyXParagraph::size_type beg, + LyXParagraph::size_type end) +{ + std::ostringstream ost; + + if (beg == 0 && !params.labelString().empty()) + ost << params.labelString() << ' '; + + string str(ost.str().c_str()); + + str += String(buffer, beg, end); + + return str; } Index: src/text2.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.130 diff -u -r1.130 text2.C --- src/text2.C 2001/05/31 22:34:05 1.130 +++ src/text2.C 2001/06/12 23:10:13 @@ -1112,8 +1112,8 @@ // Special handling if the whole selection is within one paragraph if (selection.start.par() == selection.end.par()) { result += selection.start.par()->String(buffer, - selection.start.pos(), - selection.end.pos()); + selection.start.pos(), + selection.end.pos()); return result; } @@ -1129,7 +1129,8 @@ LyXCursor tmpcur(selection.start); tmpcur.par(tmpcur.par()->next()); while (tmpcur.par() != selection.end.par()) { - result += tmpcur.par()->String(buffer, 0, tmpcur.par()->size()) + "\n\n"; + result += tmpcur.par()->String(buffer, 0, + tmpcur.par()->size()) + "\n\n"; tmpcur.par(tmpcur.par()->next()); // Or NextAfterFootnote?? } @@ -1139,7 +1140,44 @@ return result; } + +string const LyXText::selectionAsStringWithLabels(Buffer const * buffer) const +{ + if (!selection.set()) return string(); + string result; + + // Special handling if the whole selection is within one paragraph + if (selection.start.par() == selection.end.par()) { + result += selection.start.par()->StringWithLabels(buffer, + selection.start.pos(), + selection.end.pos()); + return result; + } + + // The selection spans more than one paragraph + + // First paragraph in selection + result += selection.start.par()->StringWithLabels(buffer, + selection.start.pos(), + selection.start.par()->size()) + + "\n\n"; + + // The paragraphs in between (if any) + LyXCursor tmpcur(selection.start); + tmpcur.par(tmpcur.par()->next()); + while (tmpcur.par() != selection.end.par()) { + result += tmpcur.par()->StringWithLabels(buffer, 0, + tmpcur.par()->size()) + "\n\n"; + tmpcur.par(tmpcur.par()->next()); // Or NextAfterFootnote?? + } + + // Last paragraph in selection + result += selection.end.par()->StringWithLabels(buffer, 0, +selection.end.pos()); + + return result; +} + void LyXText::ClearSelection(BufferView * /*bview*/) const { selection.set(false);