diff --git a/gdn-app/src/components/CNote.vue b/gdn-app/src/components/CNote.vue
index ca28302..3fd5620 100644
--- a/gdn-app/src/components/CNote.vue
+++ b/gdn-app/src/components/CNote.vue
@@ -143,11 +143,11 @@ function onInsertEditorMove(): void {
if (insertIndex.value === undefined) return;
if (ui.pinned.parentId) {
- notes.removeChild(ui.pinned.parentId, ui.pinned.segment);
+ notes.moveChild(ui.pinned.parentId, ui.pinned.segment, segment.id, insertIndex.value);
+ } else {
+ notes.addChild(segment.id, ui.pinned.segment.id, insertIndex.value);
}
- notes.addChild(segment.id, ui.pinned.segment.id, insertIndex.value);
-
onInsertEditorClose();
ui.unsetPinned();
}
@@ -208,28 +208,6 @@ function onInsertEditorCopy(): void {
-
-
-
-
-
-
-
-
-
-
@@ -237,6 +215,16 @@ function onInsertEditorCopy(): void {
+
+
+
+
+
+
+
+
+
+
{
note.children.splice(index, 1);
}
+ function moveChild(fromId: string, segment: Segment, toId: string, toIndex: number): void {
+ const from = getNote(fromId);
+ if (!from) return;
+
+ const to = getNote(toId);
+ if (!to) return;
+
+ // Find child index
+ let fromIndex = from.children.indexOf(segment.id);
+ for (let i = 0; i < segment.iteration; i++) {
+ fromIndex = from.children.indexOf(segment.id, fromIndex + 1);
+ }
+ if (fromIndex < 0) return;
+
+ // Fix off-by-one caused by the deletion
+ if (fromId === toId && fromIndex < toIndex) toIndex--;
+
+ from.children.splice(fromIndex, 1);
+ to.children.splice(toIndex, 0, segment.id);
+ }
+
return {
getNote,
getParents,
@@ -69,5 +90,6 @@ export const useNotesStore = defineStore("notes", () => {
clearNotes,
addChild,
removeChild,
+ moveChild,
};
});