Skip to content

Commit e2fd1e6

Browse files
committed
feat(preprocess/contextmenu): simplify matches
1 parent c0bb5d8 commit e2fd1e6

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/preprocess/preprocess.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -561,20 +561,11 @@ func exposeAPIs_main(input string) string {
561561
return fmt.Sprintf("%s[Spicetify.ContextMenuV2.renderItems(),%s].flat()", submatches[1], submatches[2])
562562
})
563563

564-
croppedInput := utils.FindFirstMatch(input, `\({menu:[^,]+,.*?triggerRef:[^,]+,[^}]*}\).*value:"contextmenu"`)[0]
565-
566-
reactRef := utils.FindFirstMatch(croppedInput, `([\w_$]+)\.useRef`)
567-
var react, menu, trigger, target string
568-
if len(reactRef) == 1 {
569-
react = reactRef[0]
570-
} else {
571-
react = reactRef[1]
572-
}
573-
574-
menuCandidates := utils.FindMatch(croppedInput, `menu:([\w_$]+)`)
575-
menu = menuCandidates[0][1]
576-
trigger = utils.FindFirstMatch(croppedInput, `trigger:([\w_$]+)`)[1]
577-
target = utils.FindFirstMatch(croppedInput, `triggerRef:([\w_$]+)`)[1]
564+
croppedInput := utils.FindFirstMatch(input, `.*value:"contextmenu"`)[0]
565+
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]
578569

579570
utils.Replace(&input, `\(0,([\w_$]+)\.jsx\)\([\w_$]+\.[\w_$]+,\{value:"contextmenu"[^\}]+\}\)\}\)`, func(submatches ...string) string {
580571
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)