diff --git a/editor/calculator.ts b/editor/calculator.ts index 6433cf5c..c50252ba 100644 --- a/editor/calculator.ts +++ b/editor/calculator.ts @@ -2423,7 +2423,23 @@ module TDev } if (k.primaryKind instanceof AST.LibraryRefKind) - s = s.filter(p => !(p)._extensionAction); + s = s.filter(p => !(p)._extensionAction); + + if (k.primaryKind.getName() == "data" && TheEditor.widgetEnabled("promoteRefactoring")) { + var e1 = this.mkIntelliItem(1e-10, Ticks.calcAddDataVar); + e1.matchAny = true; + e1.nameOverride = lf("new global var"); + e1.descOverride = lf("create new data variable"); + e1.cbOverride = () => { + var ds = TheEditor.freshVar(api.core.Number); + ds.setName(Script.freshName(this.searchApi.query() || "v")); + + this.insertToken(AST.mkPropRef(ds.getName())) + + TheEditor.addNode(ds); + }; + } + var downgradeConcat = false; if (k.definition != null) this.addGoTo(k.definition); @@ -2454,10 +2470,10 @@ module TDev s.push(api.core.StringConcatProp); // always available downgradeConcat = true; } - + s = s.filter(p => p.isBrowsable() && (!profile || profile.hasProperty(p))); s = Calculator.sortDecls(s); - + s.forEach((p: IProperty) => { if (p.getInfixPriority() > 0 && p.getParameters().length == 1) { // unary prefix operator; skip diff --git a/editor/intelliItem.ts b/editor/intelliItem.ts index 98a484bb..3556427e 100644 --- a/editor/intelliItem.ts +++ b/editor/intelliItem.ts @@ -20,7 +20,8 @@ module TDev public isAttachedTo:Kind = null; public usageKey:string; public cornerIcon:string; - public noButton:boolean; + public noButton: boolean; + public matchAny: boolean; public getName() { @@ -39,6 +40,7 @@ module TDev if (this.decl && this.decl.getKind() instanceof ThingSetKind) return 10; if (this.prop instanceof AST.LibraryRef) return 5; if (this.prop && !Script.canUseProperty(this.prop)) return -10; + if (this.matchAny) return -1e10; return 0; } @@ -266,6 +268,7 @@ module TDev // Returns match quality public match(terms:string[], fullName:string) { + if (this.matchAny) return this.score; if (!!this.prop) return IntelliItem.matchProp(this.prop, terms, fullName); if (terms.length == 0) return 1; var lowerName = this.getName().toLowerCase(); diff --git a/editor/searchApi.ts b/editor/searchApi.ts index 0c3b2637..ccaf15da 100644 --- a/editor/searchApi.ts +++ b/editor/searchApi.ts @@ -277,6 +277,8 @@ module TDev super.moveCarret(d); this.calc.onIntelliScroll(); } + + public query() : string { return this.searchBox.value; } private searchKey() { this.searchBox.placeholder = ""; diff --git a/rt/ticker.ts b/rt/ticker.ts index 39764308..fff62716 100644 --- a/rt/ticker.ts +++ b/rt/ticker.ts @@ -62,6 +62,7 @@ module TDev { calcPromoteToParameter, calcGoToDef, calcFindRefs, + calcAddDataVar, calcUnselect, calcExtend, calcReplaceInScript,