Move blocks to the right position
This commit is contained in:
parent
7ede2e8054
commit
56802dc106
|
@ -583,18 +583,16 @@ function editor(root, inputData, options) {
|
|||
}
|
||||
|
||||
function blockMoveBackward(event) {
|
||||
stopEditing(root, store, currentEditor);
|
||||
stopEditing(root, store, currentEditor)
|
||||
|
||||
let item = cursor.getCurrent(store);
|
||||
let before = store.firstSameIndented(cursor.get(), item.indented)
|
||||
let beforeID = store.currentID(before);
|
||||
let beforeItem = store.value(beforeID);
|
||||
store.moveBefore(item.id, beforeID)
|
||||
// NOTE: should moveBefore adjust the indents of the children
|
||||
if (item.indented > beforeItem.indented) {
|
||||
item.indented = beforeItem.indented
|
||||
}
|
||||
cursor.set(store.index(item.id))
|
||||
let before = _.clamp(cursor.get() - 1, 0, store.length())
|
||||
let beforeId = store.currentID(before)
|
||||
let item = cursor.getCurrent(store)
|
||||
let [index, n] = store.moveBefore(item.id, beforeId)
|
||||
let beforeItem = store.value(beforeId)
|
||||
let dir = beforeItem ? (beforeItem.indented - item.indented) : -item.indented
|
||||
store.indent(index, n, dir)
|
||||
cursor.set(index)
|
||||
trigger('change')
|
||||
|
||||
return false
|
||||
|
@ -602,15 +600,16 @@ function editor(root, inputData, options) {
|
|||
|
||||
function blockMoveForward(event) {
|
||||
stopEditing(root, store, currentEditor);
|
||||
|
||||
let blockLen = store.lastHigherIndented(cursor.get()) - cursor.get()
|
||||
let before = _.clamp(cursor.get() + 1 + blockLen, 0, store.length())
|
||||
let beforeId = store.currentID(before)
|
||||
let item = cursor.getCurrent(store);
|
||||
let after = store.lastHigherIndented(cursor.get(), item.indented)
|
||||
after = store.lastHigherIndented(after, item.indented)
|
||||
store.moveBefore(item.id, store.currentID(after))
|
||||
|
||||
cursor.set(store.index(item.id))
|
||||
let [index, n] = store.moveBefore(item.id, beforeId)
|
||||
let beforeItem = store.value(beforeId)
|
||||
let dir = beforeItem ? (beforeItem.indented - item.indented) : -item.indented
|
||||
store.indent(index, n, dir)
|
||||
cursor.set(index)
|
||||
trigger('change')
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import _ from 'lodash';
|
||||
import util from './util'
|
||||
|
||||
let rotate = util.rotate;
|
||||
|
||||
/**
|
||||
|
@ -250,6 +251,8 @@ function Store(inputData) {
|
|||
* @param {int} dir
|
||||
*/
|
||||
function indent(first, len, dir) {
|
||||
if (len === 0 || dir === 0) return
|
||||
|
||||
let selection = idList.slice(first, first + len)
|
||||
|
||||
let result = _.reduce(selection, function (list, itemId) {
|
||||
|
@ -298,7 +301,7 @@ function Store(inputData) {
|
|||
rotate(idList, toIndex, fromIndex + n, fromIndex - toIndex)
|
||||
changed = true
|
||||
}
|
||||
return index(from)
|
||||
return [index(from), n]
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user