]> git.lyx.org Git - features.git/commitdiff
Fix crash reported on the list involving multicell selections. We have to
authorRichard Heck <rgheck@comcast.net>
Fri, 8 Aug 2008 21:26:18 +0000 (21:26 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 8 Aug 2008 21:26:18 +0000 (21:26 +0000)
be careful to check for that!

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26102 a592a061-630c-0410-9148-cb99ea01b6c8

src/Cursor.cpp
src/insets/InsetTabular.cpp
src/insets/InsetTabular.h

index b91322fe49c73ff1de00c6a4426a4ff600b3c49d..ad98883954a785e41cf3ed383eadb4d4074f691a 100644 (file)
@@ -1859,11 +1859,19 @@ docstring Cursor::selectionAsString(bool with_label) const
                ? AS_STR_LABEL | AS_STR_INSETS : AS_STR_INSETS;
 
        if (inTexted()) {
+               idx_type const startidx = selBegin().idx();
+               idx_type const endidx = selEnd().idx();
+               if (startidx != endidx) {
+                       // multicell selection
+                       InsetTabular * table = inset().asInsetTabular();
+                       LASSERT(table, return docstring());
+                       return table->asString(startidx, endidx);
+               }
+               
                ParagraphList const & pars = text()->paragraphs();
 
-               // should be const ...
-               pit_type startpit = selBegin().pit();
-               pit_type endpit = selEnd().pit();
+               pit_type const startpit = selBegin().pit();
+               pit_type const endpit = selEnd().pit();
                size_t const startpos = selBegin().pos();
                size_t const endpos = selEnd().pos();
 
index 8a056a1af3b248469111cc38ecaa7492e1db805d..1a53bb2cd4b01ff8920715161de93c4b65931e6b 100644 (file)
@@ -2742,6 +2742,26 @@ bool InsetTableCell::getStatus(Cursor & cur, FuncRequest const & cmd,
        return true;
 }
 
+docstring InsetTableCell::asString(bool intoInsets) 
+{
+       docstring retval;
+       if (paragraphs().empty())
+               return retval;
+       ParagraphList::const_iterator it = paragraphs().begin();
+       ParagraphList::const_iterator en = paragraphs().end();
+       bool first = true;
+       for (; it != en; ++it) {
+               if (!first)
+                       retval += "\n";
+               else
+                       first = false;
+               retval += it->asString(intoInsets ? AS_STR_INSETS : AS_STR_NONE);
+       }
+       return retval;
+}
+
+
+
 /////////////////////////////////////////////////////////////////////
 //
 // InsetTabular
@@ -4652,6 +4672,27 @@ bool InsetTabular::isRightToLeft(Cursor & cur) const
                                         parentpos).language()->rightToLeft();
 }
 
+docstring InsetTabular::asString(idx_type stidx, idx_type enidx, 
+                                 bool intoInsets)
+{
+       LASSERT(stidx <= enidx, return docstring());
+       docstring retval;
+       col_type const col1 = tabular.cellColumn(stidx);
+       col_type const col2 = tabular.cellColumn(enidx);
+       row_type const row1 = tabular.cellRow(stidx);
+       row_type const row2 = tabular.cellRow(enidx);
+       bool first = true;
+       for (col_type col = col1; col <= col2; col++)
+               for (row_type row = row1; row <= row2; row++) {
+                       if (!first)
+                               retval += "\n";
+                       else
+                               first = false;
+                       retval += tabular.cellInset(row, col)->asString(intoInsets);
+               }
+       return retval;
+}
+
 
 void InsetTabular::getSelection(Cursor & cur,
        row_type & rs, row_type & re, col_type & cs, col_type & ce) const
index 1b0971006ce554bed5f21db7261ac8b228de90df..44d7aa6338b988d6dd4547b50129cb201fbd4813 100644 (file)
@@ -643,6 +643,9 @@ public:
                FuncStatus & status) const;
        ///
        void toggleFixedWidth(bool fw) { isFixedWidth = fw; }
+       /// writes the contents of the cell as a string, optionally
+       /// descending into insets
+       docstring asString(bool intoInsets = true);
 private:
        /// unimplemented
        InsetTableCell();
@@ -818,6 +821,9 @@ public:
        virtual InsetTabular const * asInsetTabular() const { return this; }
        ///
        bool isRightToLeft(Cursor & cur) const;
+       /// writes the cells between stidx and enidx as a string, optionally
+       /// descending into the insets
+       docstring asString(idx_type stidx, idx_type enidx, bool intoInsets = true);
 
        //
        // Public structures and variables