Skip to content

Commit

Permalink
Change to update the document only when dragend occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Mar 30, 2023
1 parent 31e4015 commit 3f7258d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 5 additions & 6 deletions public/multi.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,19 @@ <h2>yorkie document</h2>
}

let dragIndex = -1;
let dropIndex = -1;
function handleDragStart(i) {
console.log('👻 drag start', i);
dragIndex = i;
}
function handleDragOver(e, i) {
e.preventDefault();
if (dragIndex === i) return;
console.log('👻 drag over', e, i);
swapTodo(dragIndex, i);
dragIndex = i;
dropIndex = i;
}
function handleDragEnd() {
console.log('👻 drag end');
if (dragIndex === dropIndex) return;
swapTodo(dragIndex, dropIndex);
dragIndex = -1;
dropIndex = -1;
}
function swapTodo(dragIdx, dropIdx) {
doc.update((root) => {
Expand Down
2 changes: 0 additions & 2 deletions src/document/operation/move_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ export class MoveOperation extends Operation {
const previousIndex = Number(array.subPathOf(this.createdAt));
array.moveAfter(this.prevCreatedAt, this.createdAt, this.getExecutedAt());
const index = Number(array.subPathOf(this.createdAt));
console.log(previousIndex, index);

return {
type: 'move',
element: this.getParentCreatedAt(),
Expand Down

0 comments on commit 3f7258d

Please sign in to comment.