@@ -5,11 +5,9 @@ import type {
55 Matcher ,
66 Previewer ,
77 Renderer ,
8- Size ,
98 Sorter ,
109 Theme ,
1110} from "@vim-fall/core" ;
12- import type { GlobalConfig } from "@vim-fall/config/global-config" ;
1311import type { ItemPickerParams } from "@vim-fall/config/item-picker" ;
1412import {
1513 type Derivable ,
@@ -19,62 +17,42 @@ import {
1917 deriveArray ,
2018 deriveMap ,
2119} from "@vim-fall/config/derivable" ;
20+ import { unnullish } from "@lambdalisue/unnullish" ;
2221
2322import { type Action , defineAction } from "../../action.ts" ;
24- import { list } from "../source/list.ts" ;
2523import { fzf } from "../matcher/fzf.ts" ;
2624import { substring } from "../matcher/substring.ts" ;
2725import { regexp } from "../matcher/regexp.ts" ;
2826
29- type Actions < T extends Detail , A extends string > = ItemPickerParams <
30- T ,
31- A
32- > [ "actions" ] ;
33-
3427export type SubmatchOptions < T extends Detail , A extends string > = {
3528 /**
3629 * Actions available for the submatch picker.
3730 */
38- actions ?: DerivableMap < Actions < T , A > > ;
31+ actions ?: DerivableMap < ItemPickerParams < T , A > [ "actions" ] > ;
3932 /**
4033 * Default action to invoke.
4134 */
4235 defaultAction ?: A ;
4336 /**
4437 * Sorters to apply to matched items.
4538 */
46- sorters ?: DerivableArray < Sorter < T > [ ] > | null ;
39+ sorters ?: DerivableArray < readonly Sorter < T > [ ] > ;
4740 /**
4841 * Renderers to display matched items.
4942 */
50- renderers ?: DerivableArray < Renderer < T > [ ] > | null ;
43+ renderers ?: DerivableArray < readonly Renderer < T > [ ] > ;
5144 /**
5245 * Previewers for item previews.
5346 */
54- previewers ?: DerivableArray < Previewer < T > [ ] > | null ;
47+ previewers ?: DerivableArray < readonly Previewer < T > [ ] > ;
5548 /**
5649 * Coordinator to handle layout.
5750 */
58- coordinator ?: Derivable < Coordinator > | null ;
51+ coordinator ?: Derivable < Coordinator > ;
5952 /**
6053 * Theme to style the picker.
6154 */
62- theme ?: Derivable < Theme > | null ;
63- } ;
64-
65- type Context < T extends Detail , A extends string > = {
66- /**
67- * The screen size.
68- */
69- readonly screen : Size ;
70- /**
71- * The global configuration.
72- */
73- readonly globalConfig : GlobalConfig ;
74- /**
75- * The picker parameters.
76- */
77- readonly pickerParams : ItemPickerParams < T , A > & GlobalConfig ;
55+ theme ?: Derivable < Theme > ;
7856} ;
7957
8058/**
@@ -88,83 +66,35 @@ type Context<T extends Detail, A extends string> = {
8866 * @returns An action that performs submatching.
8967 */
9068export function submatch < T extends Detail , A extends string > (
91- matchers : DerivableArray < [ Matcher < T > , ...Matcher < T > [ ] ] > ,
69+ matchers : DerivableArray < readonly [ Matcher < T > , ...Matcher < T > [ ] ] > ,
9270 options : SubmatchOptions < T , A > = { } ,
9371) : Action < T > {
72+ const submatchParams = {
73+ matchers : deriveArray ( matchers ) ,
74+ actions : unnullish ( options . actions , deriveMap ) ,
75+ defaultAction : options . defaultAction ,
76+ sorters : unnullish ( options . sorters , deriveArray ) ,
77+ renderers : unnullish ( options . renderers , deriveArray ) ,
78+ previewers : unnullish ( options . previewers , deriveArray ) ,
79+ coordinator : unnullish ( options . coordinator , derive ) ,
80+ theme : unnullish ( options . theme , derive ) ,
81+ } ;
9482 return defineAction < T > (
95- async ( denops , { selectedItems, filteredItems, ...params } , { signal } ) => {
96- const context = getContext ( params ) ;
97-
98- const pickerParams : ItemPickerParams < T , string > & GlobalConfig = {
99- ...context . pickerParams ,
100- source : list ( selectedItems ?? filteredItems ) ,
101- matchers : deriveArray ( matchers ) ,
102- } ;
103-
104- if ( options . actions ) {
105- pickerParams . actions = deriveMap ( pickerParams . actions ) ;
106- }
107- if ( options . defaultAction ) {
108- pickerParams . defaultAction = options . defaultAction ;
109- }
110- if ( options . sorters !== undefined ) {
111- pickerParams . sorters = options . sorters
112- ? deriveArray ( options . sorters )
113- : undefined ;
114- }
115- if ( options . renderers !== undefined ) {
116- pickerParams . renderers = options . renderers
117- ? deriveArray ( options . renderers )
118- : undefined ;
119- }
120- if ( options . previewers !== undefined ) {
121- pickerParams . previewers = options . previewers
122- ? deriveArray ( options . previewers )
123- : undefined ;
124- }
125- if ( options . coordinator !== undefined ) {
126- pickerParams . coordinator = derive ( options . coordinator ) ??
127- context . globalConfig . coordinator ;
128- }
129- if ( options . theme !== undefined ) {
130- pickerParams . theme = derive ( options . theme ) ??
131- context . globalConfig . theme ;
132- }
133-
83+ async ( denops , params , { signal } ) => {
13484 const result = await denops . dispatch (
13585 "fall" ,
136- "picker:start" ,
137- [ ] ,
138- context . screen ,
139- pickerParams ,
86+ "submatch" ,
87+ params ,
88+ submatchParams ,
14089 { signal } ,
14190 ) ;
142-
14391 if ( result ) {
14492 return true ;
14593 }
14694 } ,
14795 ) ;
14896}
14997
150- /**
151- * Retrieves the context from the parameters object.
152- *
153- * @param params - Parameters that may contain the hidden context for submatch.
154- * @returns The extracted context.
155- * @throws If the required context is not present.
156- */
157- function getContext < T extends Detail , A extends string > (
158- params : unknown ,
159- ) : Context < T , A > {
160- if ( params && typeof params === "object" && "_submatchContext" in params ) {
161- return params . _submatchContext as Context < T , A > ;
162- }
163- throw new Error (
164- "[fall] Invoke params doesn't have required hidden context for submatch" ,
165- ) ;
166- }
167-
16898/**
16999 * Default submatching actions with common matchers.
170100 */
0 commit comments