diff options
Diffstat (limited to 'src/new_fields/Doc.ts')
-rw-r--r-- | src/new_fields/Doc.ts | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 736e8e69d..ba01cfd9c 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -8,10 +8,10 @@ import { listSpec } from "./Schema"; import { ObjectField } from "./ObjectField"; import { RefField, FieldId } from "./RefField"; import { ToScriptString, SelfProxy, Parent, OnUpdate, Self, HandleUpdate, Update, Id } from "./FieldSymbols"; -import { scriptingGlobal } from "../client/util/Scripting"; +import { scriptingGlobal, CompileScript, Scripting } from "../client/util/Scripting"; import { List } from "./List"; import { DocumentType } from "../client/documents/Documents"; -import { ComputedField } from "./ScriptField"; +import { ComputedField, ScriptField } from "./ScriptField"; import { PrefetchProxy, ProxyField } from "./Proxy"; export namespace Field { @@ -390,10 +390,15 @@ export namespace Doc { } } export function MakeAlias(doc: Doc) { - if (!GetT(doc, "isPrototype", "boolean", true)) { - return Doc.MakeCopy(doc); + let alias = !GetT(doc, "isPrototype", "boolean", true) ? Doc.MakeCopy(doc) : Doc.MakeDelegate(doc); + let aliasNumber = Doc.GetProto(doc).aliasNumber = NumCast(Doc.GetProto(doc).aliasNumber) + 1; + let script = `return renameAlias(self, ${aliasNumber})`; + //let script = "StrCast(self.title).replace(/\\([0-9]*\\)/, \"\") + `(${n})`"; + let compiled = CompileScript(script, { params: { this: "Doc" }, capturedVariables: { self: doc }, typecheck: false }); + if (compiled.compiled) { + alias.title = new ComputedField(compiled); } - return Doc.MakeDelegate(doc); // bcz? + return alias; } // @@ -584,4 +589,7 @@ export namespace Doc { let index = manager.BrushedDoc.indexOf(doc); if (index !== -1) runInAction(() => manager.BrushedDoc.splice(index, 1)); } -}
\ No newline at end of file +} +Scripting.addGlobal(function renameAlias(doc: any, n: any) { + return StrCast(doc.title).replace(/\([0-9]*\)/, "") + `(${n})`; +});
\ No newline at end of file |