Better copy and paste
With thi change we now use a json representation to copy and paste list items.
This commit is contained in:
parent
10d6d7521a
commit
b8910f9aa6
|
@ -29,8 +29,9 @@ function connectContextMenu(editor) {
|
||||||
copy: {
|
copy: {
|
||||||
name: 'Copy',
|
name: 'Copy',
|
||||||
callback: function (key, opt) {
|
callback: function (key, opt) {
|
||||||
editor.copy(this, {recursive: true}).then(result => {
|
editor.flat(this).then(result => {
|
||||||
copy(renderTree(result).join("\n"))
|
let data = JSON.stringify(result);
|
||||||
|
copy(data)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
className: 'action-copy'
|
className: 'action-copy'
|
||||||
|
|
|
@ -108,6 +108,15 @@ function editor(root, inputData, options) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function flat(element) {
|
||||||
|
let item = $(element).parents('.list-item')
|
||||||
|
let id = item.attr('data-id')
|
||||||
|
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
resolve(store.flat(id));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function zoomin(element, opt) {
|
function zoomin(element, opt) {
|
||||||
let item = $(element).parents('.list-item')
|
let item = $(element).parents('.list-item')
|
||||||
let id = item.attr('data-id')
|
let id = item.attr('data-id')
|
||||||
|
@ -159,6 +168,7 @@ function editor(root, inputData, options) {
|
||||||
save,
|
save,
|
||||||
saveTree,
|
saveTree,
|
||||||
copy,
|
copy,
|
||||||
|
flat,
|
||||||
update,
|
update,
|
||||||
start,
|
start,
|
||||||
zoomin,
|
zoomin,
|
||||||
|
@ -477,26 +487,13 @@ function editor(root, inputData, options) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
let parentItem = $(this).parents('.list-item')
|
let pastedData = event.originalEvent.clipboardData.getData('text/plain')
|
||||||
let index = $(root).children('div.list-item').index(parentItem)
|
let items = JSON.parse(pastedData.toString());
|
||||||
let pastedData = event.originalEvent.clipboardData.getData('text')
|
|
||||||
let lines = pastedData.split(/\n/)
|
|
||||||
if (lines.length === 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let currentID = store.currentID(index);
|
let item = $(this).parents('.list-item')
|
||||||
let baseIndent = store.value(currentID).indented
|
let id = item.attr('data-id')
|
||||||
|
|
||||||
let newItems = _.filter(_.map(lines, function (line) {
|
store.insertAfter(id, ...items)
|
||||||
if (line.length === 0) return;
|
|
||||||
let matches = line.match(/(\s{4})/g)
|
|
||||||
let relIndent = matches ? matches.length : 0;
|
|
||||||
let newItem = newListItem(baseIndent + relIndent)
|
|
||||||
newItem.text = line.replace(/^\s+/, '')
|
|
||||||
return newItem
|
|
||||||
}))
|
|
||||||
store.insertAfter(currentID, ...newItems)
|
|
||||||
|
|
||||||
trigger('change')
|
trigger('change')
|
||||||
|
|
||||||
|
|
|
@ -156,8 +156,8 @@ function Store(inputData) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
let newId = ID()
|
let newId = ID()
|
||||||
item.id = newId
|
item.id = newId
|
||||||
values[newId] = item
|
|
||||||
}
|
}
|
||||||
|
values[item.id] = item
|
||||||
return item.id
|
return item.id
|
||||||
})
|
})
|
||||||
idList.splice(index + 1, 0, ...newItems)
|
idList.splice(index + 1, 0, ...newItems)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user