diff --git a/list-editor/index.js b/list-editor/index.js index 2842fc1..edcd1bf 100644 --- a/list-editor/index.js +++ b/list-editor/index.js @@ -509,21 +509,33 @@ function editor(root, inputData, options) { } let pastedData = event.originalEvent.clipboardData.getData('text/plain') - let items = JSON.parse(pastedData.toString()); + try { + let items = JSON.parse(pastedData.toString()); + let item = $(this).parents('.list-item') + let id = item.attr('data-id') - let item = $(this).parents('.list-item') - let id = item.attr('data-id') + // reset ids + _.each(items, item => { + item.id = null + }) - // reset ids - _.each(items, item => { - item.id = null - }) - - store.insertAfter(id, ...items) - - trigger('change') - - return false + store.insertAfter(id, ...items) + trigger('change') + return false + } catch (e) { + let items = pastedData.toString().split(/\n+/); + let item = $(this).parents('.list-item') + let id = item.attr('data-id') + const firstItem = store.value(id) + items = _.map(items, text => { + const item = newListItem(firstItem.indented) + item.text = text + return item + }) + store.insertAfter(id, ...items) + trigger('change') + return false + } }); function moveCursor(event, dir) {