Skip to content

Commit d0c9272

Browse files
committed
fix(preprocess/contextmenu): fallback when regex doesn't find candicates
1 parent 761fe0f commit d0c9272

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/preprocess/preprocess.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,17 @@ func exposeAPIs_main(input string) string {
563563

564564
croppedInput := utils.FindFirstMatch(input, `.*value:"contextmenu"`)[0]
565565
react := utils.FindLastMatch(croppedInput, `([a-zA-Z_\$][\w\$]*)\.useRef`)[1]
566-
menu := utils.FindLastMatch(croppedInput, `menu:([\w_$]+)`)[1]
567-
trigger := utils.FindLastMatch(croppedInput, `trigger:([\w_$]+)`)[1]
568-
target := utils.FindLastMatch(croppedInput, `triggerRef:([\w_$]+)`)[1]
566+
candicates := utils.FindLastMatch(croppedInput, `\(\{[^}]*menu:([a-zA-Z_\$][\w\$]*),[^}]*trigger:([a-zA-Z_\$][\w\$]*),[^}]*triggerRef:([a-zA-Z_\$][\w\$]*)`)
567+
var menu, trigger, target string
568+
if len(candicates) == 0 {
569+
menu = "e.menu"
570+
trigger = "e.trigger"
571+
target = "e.triggerRef"
572+
} else {
573+
menu = candicates[1]
574+
trigger = candicates[2]
575+
target = candicates[3]
576+
}
569577

570578
utils.Replace(&input, `\(0,([\w_$]+)\.jsx\)\([\w_$]+\.[\w_$]+,\{value:"contextmenu"[^\}]+\}\)\}\)`, func(submatches ...string) string {
571579
return fmt.Sprintf("(0,%s.jsx)((Spicetify.ContextMenuV2._context||(Spicetify.ContextMenuV2._context=%s.createContext(null))).Provider,{value:{props:%s?.props,trigger:%s,target:%s},children:%s})", submatches[1], react, menu, trigger, target, submatches[0])

0 commit comments

Comments
 (0)