diff --git a/toonz/sources/toonz/columncommand.cpp b/toonz/sources/toonz/columncommand.cpp index 07221fe..a6cf920 100644 --- a/toonz/sources/toonz/columncommand.cpp +++ b/toonz/sources/toonz/columncommand.cpp @@ -794,6 +794,7 @@ void ColumnCmd::copyColumns(const std::set &indices) { void ColumnCmd::pasteColumns(std::set &indices, const StageObjectsData *data) { + // indices will be updated here by inserted column ids after pasting bool isPaste = pasteColumnsWithoutUndo(&indices, true, data); if (!isPaste) return; TUndoManager::manager()->add(new PasteColumnsUndo(indices)); diff --git a/toonz/sources/toonz/columnselection.cpp b/toonz/sources/toonz/columnselection.cpp index bbb81bc..aded4f4 100644 --- a/toonz/sources/toonz/columnselection.cpp +++ b/toonz/sources/toonz/columnselection.cpp @@ -65,21 +65,26 @@ bool TColumnSelection::isEmpty() const { return m_indices.empty(); } void TColumnSelection::copyColumns() { ColumnCmd::copyColumns(m_indices); } //----------------------------------------------------------------------------- - -void TColumnSelection::pasteColumns() { ColumnCmd::pasteColumns(m_indices); } +// pasteColumns will insert columns before the first column in the selection +void TColumnSelection::pasteColumns() { + std::set indices; + if (isEmpty()) // in case that no columns are selected + indices.insert(0); + else + indices.insert(*m_indices.begin()); + ColumnCmd::pasteColumns(indices); +} //----------------------------------------------------------------------------- - +// pasteColumnsAbove will insert columns after the last column in the selection void TColumnSelection::pasteColumnsAbove() { std::set indices; - std::set::iterator it; - - for (it = m_indices.begin(); it != m_indices.end(); it++) { - int newIdx = *it + 1; - indices.insert(newIdx); - } - - ColumnCmd::pasteColumns(indices, 0); + if (isEmpty()) { // in case that no columns are selected + TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); + indices.insert(xsh->getFirstFreeColumnIndex()); + } else + indices.insert(*m_indices.rbegin() + 1); + ColumnCmd::pasteColumns(indices); } //-----------------------------------------------------------------------------