diff options
author | Fawn <fangrui_tong@brown.edu> | 2019-07-24 17:48:11 -0400 |
---|---|---|
committer | Fawn <fangrui_tong@brown.edu> | 2019-07-24 17:48:11 -0400 |
commit | 75070c4c2188823ed9a09816861d4f873574c9db (patch) | |
tree | f97f83b7cb51c32cd540fbfcc1f75d60c2aae681 /src/new_fields/Doc.ts | |
parent | 07e4ad670134213afc019bf84f765cdfc00a510a (diff) |
can move rows within expanded collection
Diffstat (limited to 'src/new_fields/Doc.ts')
-rw-r--r-- | src/new_fields/Doc.ts | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 5ae0753d8..eba1d4f04 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -267,21 +267,28 @@ export namespace Doc { export function AddDocToList(target: Doc, key: string, doc: Doc, relativeTo?: Doc, before?: boolean, first?: boolean, allowDuplicates?: boolean) { if (target[key] === undefined) { + console.log("target key undefined"); Doc.GetProto(target)[key] = new List<Doc>(); } let list = Cast(target[key], listSpec(Doc)); if (list) { + console.log("has list"); if (allowDuplicates !== true) { let pind = list.reduce((l, d, i) => d instanceof Doc && Doc.AreProtosEqual(d, doc) ? i : l, -1); if (pind !== -1) { list.splice(pind, 1); } } - if (first) list.splice(0, 0, doc); + if (first) { + console.log("is first"); + list.splice(0, 0, doc); + } else { + console.log("not first"); let ind = relativeTo ? list.indexOf(relativeTo) : -1; if (ind === -1) list.push(doc); else list.splice(before ? ind : ind + 1, 0, doc); + console.log("index", ind); } } return true; |