@gtkx/testing 2.0.0-beta.12 → 2.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/act.d.ts +7 -1
- package/dist/act.d.ts.map +1 -1
- package/dist/act.js +54 -4
- package/dist/act.js.map +1 -1
- package/dist/bound-queries.d.ts +1 -1
- package/dist/bound-queries.d.ts.map +1 -1
- package/dist/bound-queries.js.map +1 -1
- package/dist/cleanup-registry.d.ts.map +1 -1
- package/dist/cleanup-registry.js +4 -1
- package/dist/cleanup-registry.js.map +1 -1
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +11 -2
- package/dist/fire-event.js.map +1 -1
- package/dist/harness-window.d.ts +8 -2
- package/dist/harness-window.d.ts.map +1 -1
- package/dist/harness-window.js +28 -5
- package/dist/harness-window.js.map +1 -1
- package/dist/internal.d.ts +5 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +5 -0
- package/dist/internal.js.map +1 -1
- package/dist/matchers.d.ts +4 -1
- package/dist/matchers.d.ts.map +1 -1
- package/dist/matchers.js +29 -9
- package/dist/matchers.js.map +1 -1
- package/dist/pretty-widget.d.ts +4 -2
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +7 -5
- package/dist/pretty-widget.js.map +1 -1
- package/dist/queries.d.ts +2 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +19 -6
- package/dist/queries.js.map +1 -1
- package/dist/register-test-hooks.js +8 -0
- package/dist/register-test-hooks.js.map +1 -1
- package/dist/render.d.ts +14 -6
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +46 -31
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.js.map +1 -1
- package/dist/types.d.ts +10 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/usage-error.d.ts +9 -0
- package/dist/usage-error.d.ts.map +1 -0
- package/dist/usage-error.js +13 -0
- package/dist/usage-error.js.map +1 -0
- package/dist/user-event/adjustment.d.ts.map +1 -1
- package/dist/user-event/adjustment.js +6 -5
- package/dist/user-event/adjustment.js.map +1 -1
- package/dist/user-event/click.d.ts +15 -7
- package/dist/user-event/click.d.ts.map +1 -1
- package/dist/user-event/click.js +165 -43
- package/dist/user-event/click.js.map +1 -1
- package/dist/user-event/controller.d.ts +10 -2
- package/dist/user-event/controller.d.ts.map +1 -1
- package/dist/user-event/controller.js +25 -3
- package/dist/user-event/controller.js.map +1 -1
- package/dist/user-event/dispatch.d.ts +1 -1
- package/dist/user-event/dispatch.d.ts.map +1 -1
- package/dist/user-event/dispatch.js +9 -6
- package/dist/user-event/dispatch.js.map +1 -1
- package/dist/user-event/editable-label-click.d.ts +5 -0
- package/dist/user-event/editable-label-click.d.ts.map +1 -0
- package/dist/user-event/editable-label-click.js +12 -0
- package/dist/user-event/editable-label-click.js.map +1 -0
- package/dist/user-event/event-wrapper.d.ts +11 -1
- package/dist/user-event/event-wrapper.d.ts.map +1 -1
- package/dist/user-event/event-wrapper.js +66 -12
- package/dist/user-event/event-wrapper.js.map +1 -1
- package/dist/user-event/gesture.d.ts.map +1 -1
- package/dist/user-event/gesture.js +67 -27
- package/dist/user-event/gesture.js.map +1 -1
- package/dist/user-event/index.d.ts +55 -18
- package/dist/user-event/index.d.ts.map +1 -1
- package/dist/user-event/index.js +42 -8
- package/dist/user-event/index.js.map +1 -1
- package/dist/user-event/keyboard.d.ts +27 -2
- package/dist/user-event/keyboard.d.ts.map +1 -1
- package/dist/user-event/keyboard.js +251 -30
- package/dist/user-event/keyboard.js.map +1 -1
- package/dist/user-event/list-row-click.d.ts +2 -1
- package/dist/user-event/list-row-click.d.ts.map +1 -1
- package/dist/user-event/list-row-click.js +10 -6
- package/dist/user-event/list-row-click.js.map +1 -1
- package/dist/user-event/native-click.d.ts +2 -1
- package/dist/user-event/native-click.d.ts.map +1 -1
- package/dist/user-event/native-click.js +16 -2
- package/dist/user-event/native-click.js.map +1 -1
- package/dist/user-event/pointer.d.ts +5 -3
- package/dist/user-event/pointer.d.ts.map +1 -1
- package/dist/user-event/pointer.js +72 -27
- package/dist/user-event/pointer.js.map +1 -1
- package/dist/user-event/selection.d.ts.map +1 -1
- package/dist/user-event/selection.js +46 -15
- package/dist/user-event/selection.js.map +1 -1
- package/dist/user-event/state.d.ts +2 -1
- package/dist/user-event/state.d.ts.map +1 -1
- package/dist/user-event/state.js +1 -1
- package/dist/user-event/state.js.map +1 -1
- package/dist/user-event/tab-view-click.d.ts +8 -0
- package/dist/user-event/tab-view-click.d.ts.map +1 -0
- package/dist/user-event/tab-view-click.js +37 -0
- package/dist/user-event/tab-view-click.js.map +1 -0
- package/dist/user-event/text.d.ts +3 -2
- package/dist/user-event/text.d.ts.map +1 -1
- package/dist/user-event/text.js +34 -14
- package/dist/user-event/text.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +13 -3
- package/dist/widget-accessible-properties.d.ts.map +1 -1
- package/dist/widget-accessible-properties.js +56 -17
- package/dist/widget-accessible-properties.js.map +1 -1
- package/dist/widget-target.d.ts.map +1 -1
- package/dist/widget-target.js +2 -1
- package/dist/widget-target.js.map +1 -1
- package/package.json +13 -8
- package/src/act.ts +70 -6
- package/src/bound-queries.ts +1 -1
- package/src/cleanup-registry.ts +5 -1
- package/src/fire-event.ts +17 -2
- package/src/harness-window.ts +37 -6
- package/src/internal.ts +5 -0
- package/src/matchers.ts +43 -9
- package/src/pretty-widget.ts +8 -5
- package/src/queries.ts +43 -10
- package/src/register-test-hooks.ts +11 -0
- package/src/render.tsx +56 -35
- package/src/role-helpers.ts +1 -1
- package/src/types.ts +11 -2
- package/src/usage-error.ts +16 -0
- package/src/user-event/adjustment.ts +11 -6
- package/src/user-event/click.ts +227 -47
- package/src/user-event/controller.ts +48 -3
- package/src/user-event/dispatch.ts +17 -7
- package/src/user-event/editable-label-click.ts +17 -0
- package/src/user-event/event-wrapper.ts +105 -14
- package/src/user-event/gesture.ts +101 -31
- package/src/user-event/index.ts +104 -36
- package/src/user-event/keyboard.ts +358 -35
- package/src/user-event/list-row-click.ts +12 -6
- package/src/user-event/native-click.ts +22 -3
- package/src/user-event/pointer.ts +101 -35
- package/src/user-event/selection.ts +71 -15
- package/src/user-event/state.ts +4 -2
- package/src/user-event/tab-view-click.ts +59 -0
- package/src/user-event/text.ts +39 -12
- package/src/widget-accessible-properties.ts +79 -18
- package/src/widget-target.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/user-event/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACvG,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAqB,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAuB,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AA2H1D,MAAM,QAAQ,GACV,CAAyB,MAA4D,EAAE,EAAE,CACzF,CAAC,MAAsB,EAAE,GAAG,IAAU,EAAiB,EAAE,CACrD,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,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QAAQ,CAAC,CAAC,MAAkB,EAAE,KAAa,EAAiB,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAC/G,OAAO,EAAE,KAAK,CACV,QAAQ,CAAC,CAAC,MAAkB,EAAE,KAAmB,EAAiB,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CACtG;KACJ,CAAC;AACN,CAAC;AAOD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAyC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { delay } from \"../timers.js\";\nimport { requireWidget } from \"../widget-target.js\";\nimport { scroll, slide } from \"./adjustment.js\";\nimport { click, dblClick, tripleClick } from \"./click.js\";\nimport { drag, dragAndDrop, drop, hover, longPress, rotate, swipe, unhover, zoom } from \"./gesture.js\";\nimport { keyboard, tab } from \"./keyboard.js\";\nimport { pointer, type PointerInput } from \"./pointer.js\";\nimport { deselectOptions, selectOptions } from \"./selection.js\";\nimport { createInitialState, type UserEventState } from \"./state.js\";\nimport { clear, copy, cut, paste, type } from \"./text.js\";\n\n/** Options shared by every helper on a {@link UserEvent} instance. */\ntype UserEventOptions = {\n /** Milliseconds to wait after each helper resolves; null, the default, waits not at all. */\n delay?: number | null | undefined;\n};\n\n/** User interactions exposed by {@link userEvent}. */\ntype UserEvent = {\n /** Creates an instance with shared keyboard and pointer state. */\n setup: (options?: UserEventOptions) => UserEvent;\n /** Activates or presses and releases a widget. */\n click: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof click> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Delivers a double-click gesture. */\n dblClick: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof dblClick> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Delivers a triple-click gesture. */\n tripleClick: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof tripleClick> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Moves focus forward or backward within the root. */\n tab: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof tab> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Types into an editable widget. */\n type: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof type> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Deletes all text from an editable widget. */\n clear: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof clear> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Copies the current selection. */\n copy: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof copy> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Cuts the current selection. */\n cut: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof cut> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Pastes text or clipboard contents. */\n paste: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof paste> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Selects positions without activating them. */\n selectOptions: typeof selectOptions;\n /** Unselects positions without activating them. */\n deselectOptions: typeof deselectOptions;\n /** Emits a motion `enter` on the widget, adding a motion controller when it has none. */\n hover: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof hover> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits a motion `leave` on the widget, adding a motion controller when it has none. */\n unhover: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof unhover> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits `angle-changed` on the widget's rotate gestures. */\n rotate: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof rotate> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits `scale-changed` on the widget's zoom gestures. */\n zoom: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof zoom> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits `swipe` with the given velocity on the widget's swipe gestures. */\n swipe: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof swipe> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits `pressed` at the given point on the widget's long-press gestures. */\n longPress: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof longPress> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Runs a begin, update, and end sequence on the widget's drag gestures, ending at the given offset. */\n drag: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof drag> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits `drop` with the given content on the widget's drop targets. */\n drop: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof drop> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Requires a drag source on the source widget, then emits `drop` with the content on the target's drop targets. */\n dragAndDrop: (\n source: Gtk.Accessible,\n target: Gtk.Accessible,\n ...args: Parameters<typeof dragAndDrop> extends [Gtk.Widget, Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits a jump `change-value` on a Gtk.Range so it moves to the given value. */\n slide: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof slide> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Adds the delta to the adjustments of the widget itself, or of its nearest scrollable ancestor. */\n scroll: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof scroll> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Sends a key sequence through GTK's propagation chain. */\n keyboard: (widget: Gtk.Accessible, input: string) => Promise<void>;\n /** Applies a pointer token while preserving held-button state. */\n pointer: (widget: Gtk.Accessible, input: PointerInput) => Promise<void>;\n};\n\nconst onWidget =\n <Args extends unknown[]>(helper: (widget: Gtk.Widget, ...args: Args) => Promise<void>) =>\n (target: Gtk.Accessible, ...args: Args): Promise<void> =>\n helper(requireWidget(target), ...args);\n\nconst onWidgetPair =\n <Args extends unknown[]>(helper: (source: Gtk.Widget, target: Gtk.Widget, ...args: Args) => Promise<void>) =>\n (source: Gtk.Accessible, target: Gtk.Accessible, ...args: Args): Promise<void> =>\n helper(requireWidget(source), requireWidget(target), ...args);\n\n/** User interactions that dispatch GTK events and gestures. */\nconst userEvent: UserEvent = {\n ...createInstance(createInitialState(), {}),\n setup: (options?: UserEventOptions): UserEvent => createInstance(createInitialState(), options ?? {}),\n};\n\nconst settle = (ms: number | null | undefined): Promise<void> => {\n if (ms === null || ms === undefined) {\n return Promise.resolve();\n }\n\n return delay(ms);\n};\n\nfunction createInstance(state: UserEventState, options: UserEventOptions): UserEvent {\n const after =\n <Args extends unknown[]>(helper: (...args: Args) => Promise<void>) =>\n async (...args: Args): Promise<void> => {\n await helper(...args);\n await settle(options.delay);\n };\n\n return {\n setup: (overrides?: UserEventOptions): UserEvent => createInstance(state, { ...options, ...overrides }),\n click: after(onWidget(click)),\n dblClick: after(onWidget(dblClick)),\n tripleClick: after(onWidget(tripleClick)),\n tab: after(onWidget(tab)),\n type: after(onWidget(type)),\n clear: after(onWidget(clear)),\n copy: after(onWidget(copy)),\n cut: after(onWidget(cut)),\n paste: after(onWidget(paste)),\n selectOptions: after(onWidget(selectOptions)),\n deselectOptions: after(onWidget(deselectOptions)),\n hover: after(onWidget(hover)),\n unhover: after(onWidget(unhover)),\n rotate: after(onWidget(rotate)),\n zoom: after(onWidget(zoom)),\n swipe: after(onWidget(swipe)),\n longPress: after(onWidget(longPress)),\n drag: after(onWidget(drag)),\n drop: after(onWidget(drop)),\n dragAndDrop: after(onWidgetPair(dragAndDrop)),\n slide: after(onWidget(slide)),\n scroll: after(onWidget(scroll)),\n keyboard: after(onWidget((widget: Gtk.Widget, input: string): Promise<void> => keyboard(state, widget, input))),\n pointer: after(\n onWidget((widget: Gtk.Widget, input: PointerInput): Promise<void> => pointer(state, widget, input)),\n ),\n };\n}\n\nexport type { ScrollDelta } from \"./adjustment.js\";\nexport type { DragOffset, DragOptions, DropContent, DropOptions } from \"./gesture.js\";\nexport type { TabOptions } from \"./keyboard.js\";\nexport type { PointerInput } from \"./pointer.js\";\nexport type { TypeOptions } from \"./text.js\";\nexport { resetClipboard } from \"./text.js\";\nexport { userEvent, type UserEvent, type UserEventOptions };\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/user-event/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACvG,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAqB,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAuB,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAoB,MAAM,WAAW,CAAC;AAkI5E,MAAM,mBAAmB,GAAG,CAAC,IAAkB,EAAwB,EAAE;IACrE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,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C,KAAK,CAAC,CAAC;QAC7B,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACrC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3B,WAAW,EAAE,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAC7C,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC7B,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/B,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACnG,OAAO,EAAE,KAAK,CACV,QAAQ,CAAC,CAAC,MAAkB,EAAE,KAAmB,EAAiB,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CACtG;KACJ,CAAC;AACN,CAAC;AAOD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EACH,mBAAmB,EACnB,SAAS,EACT,gBAAgB,GAKnB,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { delay } from \"../timers.js\";\nimport { usageError } from \"../usage-error.js\";\nimport { requireWidget } from \"../widget-target.js\";\nimport { scroll, slide } from \"./adjustment.js\";\nimport { click, dblClick, tripleClick } from \"./click.js\";\nimport { drag, dragAndDrop, drop, hover, longPress, rotate, swipe, unhover, zoom } from \"./gesture.js\";\nimport { focusedKeyWidget, heldModifiers, keyboard, tab } from \"./keyboard.js\";\nimport { pointer, type PointerInput } from \"./pointer.js\";\nimport { deselectOptions, selectOptions } from \"./selection.js\";\nimport { createInitialState, type UserEventState } from \"./state.js\";\nimport { clear, copy, cut, paste, type, type TypeOptions } from \"./text.js\";\n\n/** Options shared by every helper on a {@link UserEvent} instance. */\ntype UserEventOptions = {\n /** Milliseconds to wait after each helper resolves; null, the default, waits not at all. */\n delay?: number | null | undefined;\n};\n\n/** User interactions exposed by {@link userEvent}. */\ntype UserEvent = {\n /** Creates an instance with shared keyboard and pointer state. */\n setup: (options?: UserEventOptions) => UserEvent;\n /** Activates or presses and releases a widget. */\n click: (widget: Gtk.Accessible) => Promise<void>;\n /** Delivers a double-click gesture. */\n dblClick: (widget: Gtk.Accessible) => Promise<void>;\n /** Delivers a triple-click gesture. */\n tripleClick: (widget: Gtk.Accessible) => Promise<void>;\n /** Moves focus forward or backward within the root. */\n tab: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof tab> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /**\n * Types into an editable widget, inserting each character as its own edit. Keys named in braces, such as `{Enter}`, `{Backspace}` or `{Tab}`, are pressed\n * as `keyboard` presses them, and a doubled opening brace types a literal `{`. Once a key moves focus out of the\n * widget, as `{Tab}` does, the rest of the text goes to the newly focused widget.\n */\n type: (widget: Gtk.Accessible, text: string, options?: TypeOptions) => Promise<void>;\n /** Deletes all text from an editable widget. */\n clear: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof clear> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Copies the current selection. */\n copy: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof copy> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Cuts the current selection. */\n cut: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof cut> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Pastes text or clipboard contents. */\n paste: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof paste> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Selects positions without activating them. */\n selectOptions: typeof selectOptions;\n /** Unselects positions without activating them. */\n deselectOptions: typeof deselectOptions;\n /** Emits a motion `enter` on the widget, adding a motion controller when it has none. */\n hover: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof hover> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits a motion `leave` on the widget, adding a motion controller when it has none. */\n unhover: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof unhover> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits `angle-changed` on the rotate gestures of the widget or its nearest ancestor that has one. */\n rotate: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof rotate> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits `scale-changed` on the zoom gestures of the widget or its nearest ancestor that has one. */\n zoom: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof zoom> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits `swipe` with the given velocity on the swipe gestures of the widget or its nearest ancestor that has one. */\n swipe: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof swipe> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits `pressed` at the given point on the long-press gestures of the widget or its nearest ancestor that has one. */\n longPress: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof longPress> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /**\n * Runs a begin, update, and end sequence on the drag gestures of the widget or its nearest ancestor that has one,\n * ending at the given offset.\n */\n drag: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof drag> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits `drop` with the given content on the drop targets of the widget or its nearest ancestor that has one. */\n drop: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof drop> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /**\n * Begins a drag from the drag sources of the source widget or its nearest ancestor that has one, then emits `drop`\n * with the content on the drop targets of the target widget or its nearest ancestor that has one.\n */\n dragAndDrop: (\n source: Gtk.Accessible,\n target: Gtk.Accessible,\n ...args: Parameters<typeof dragAndDrop> extends [Gtk.Widget, Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Emits a jump `change-value` on a Gtk.Range so it moves to the given value. */\n slide: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof slide> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /** Adds the delta to the adjustments of the widget itself, or of its nearest scrollable ancestor. */\n scroll: (\n widget: Gtk.Accessible,\n ...args: Parameters<typeof scroll> extends [Gtk.Widget, ...infer Args] ? Args : never\n ) => Promise<void>;\n /**\n * Sends a key sequence through GTK's propagation chain, to the given widget or, without one, to the focused widget\n * of the active window. A given widget that can take focus, or passes it to a child as a menu button does to its\n * button, is focused first unless the focus is already inside it.\n */\n keyboard: {\n (input: string): Promise<void>;\n (widget: Gtk.Accessible, input: string): Promise<void>;\n };\n /** Applies a pointer token, such as `[MouseLeft]` or `[MouseRight>]`, while preserving held-button state. */\n pointer: (widget: Gtk.Accessible, input: PointerInput) => Promise<void>;\n};\n\ntype KeyboardArgs = [input: string] | [widget: Gtk.Accessible, input: string];\n\nconst resolveKeyboardArgs = (args: KeyboardArgs): [Gtk.Widget, string] => {\n const [first, input] = args;\n\n if (typeof first === \"string\") {\n return [focusedKeyWidget(), first];\n }\n\n if (input === undefined) {\n throw usageError(new TypeError(\"Expected a key sequence after the widget\"));\n }\n\n return [requireWidget(first), input];\n};\n\nconst onWidget =\n <Args extends unknown[]>(helper: (widget: Gtk.Widget, ...args: Args) => Promise<void>) =>\n (target: Gtk.Accessible, ...args: Args): Promise<void> =>\n helper(requireWidget(target), ...args);\n\nconst onWidgetPair =\n <Args extends unknown[]>(helper: (source: Gtk.Widget, target: Gtk.Widget, ...args: Args) => Promise<void>) =>\n (source: Gtk.Accessible, target: Gtk.Accessible, ...args: Args): Promise<void> =>\n helper(requireWidget(source), requireWidget(target), ...args);\n\nconst silently =\n <Args extends unknown[]>(helper: (...args: Args) => Promise<unknown>) =>\n async (...args: Args): Promise<void> => {\n await helper(...args);\n };\n\n/** Whether anything on the widget or its ancestors is known to have handled a click. */\ntype ClickReport = { isHandled: boolean };\n/** The keys of a sequence whose presses nothing handled, named as `keyboard` input names them. */\ntype KeyboardReport = { unhandledKeys: string[] };\n\nconst defaultState = createInitialState();\n\n/** User interactions that dispatch GTK events and gestures. */\nconst userEvent: UserEvent = {\n ...createInstance(defaultState, {}),\n setup: (options?: UserEventOptions): UserEvent => createInstance(createInitialState(), options ?? {}),\n};\n\n/**\n * `userEvent.click` and `userEvent.keyboard` with the default instance's state, reporting whether anything on the\n * target or its ancestors handled the input, and the modifiers that state still holds, for tools that tell an agent\n * when its input had no effect or will be modified.\n */\nconst userEventReports = {\n click: async (target: Gtk.Accessible): Promise<ClickReport> => ({\n isHandled: await click(defaultState, requireWidget(target)),\n }),\n keyboard: async (...args: KeyboardArgs): Promise<KeyboardReport> => ({\n unhandledKeys: await keyboard(defaultState, ...resolveKeyboardArgs(args)),\n }),\n heldModifiers: (): string[] => heldModifiers(defaultState),\n};\n\n/** Releases the modifiers and buttons the default instance still holds, so they do not carry into the next test. */\nconst resetUserEventState = (): void => {\n defaultState.modifierState = 0;\n defaultState.heldButtons.clear();\n};\n\nconst settle = (ms: number | null | undefined): Promise<void> => {\n if (ms === null || ms === undefined) {\n return Promise.resolve();\n }\n\n return delay(ms);\n};\n\nfunction createInstance(state: UserEventState, options: UserEventOptions): UserEvent {\n const after =\n <Args extends unknown[]>(helper: (...args: Args) => Promise<void>) =>\n async (...args: Args): Promise<void> => {\n await helper(...args);\n await settle(options.delay);\n };\n\n return {\n setup: (overrides?: UserEventOptions): UserEvent => createInstance(state, { ...options, ...overrides }),\n click: after(onWidget(silently((widget: Gtk.Widget) => click(state, widget)))),\n dblClick: after(onWidget(silently((widget: Gtk.Widget) => dblClick(state, widget)))),\n tripleClick: after(onWidget(silently((widget: Gtk.Widget) => tripleClick(state, widget)))),\n tab: after(onWidget(tab)),\n type: after(\n onWidget((widget: Gtk.Widget, text: string, options?: TypeOptions): Promise<void> =>\n type(state, widget, text, options),\n ),\n ),\n clear: after(onWidget(clear)),\n copy: after(onWidget(copy)),\n cut: after(onWidget(cut)),\n paste: after(onWidget(paste)),\n selectOptions: after(onWidget(selectOptions)),\n deselectOptions: after(onWidget(deselectOptions)),\n hover: after(onWidget(hover)),\n unhover: after(onWidget(unhover)),\n rotate: after(onWidget(rotate)),\n zoom: after(onWidget(zoom)),\n swipe: after(onWidget(swipe)),\n longPress: after(onWidget(longPress)),\n drag: after(onWidget(drag)),\n drop: after(onWidget(drop)),\n dragAndDrop: after(onWidgetPair(dragAndDrop)),\n slide: after(onWidget(slide)),\n scroll: after(onWidget(scroll)),\n keyboard: after(silently((...args: KeyboardArgs) => keyboard(state, ...resolveKeyboardArgs(args)))),\n pointer: after(\n onWidget((widget: Gtk.Widget, input: PointerInput): Promise<void> => pointer(state, widget, input)),\n ),\n };\n}\n\nexport type { ScrollDelta } from \"./adjustment.js\";\nexport type { DragOffset, DragOptions, DropContent, DropOptions } from \"./gesture.js\";\nexport type { TabOptions } from \"./keyboard.js\";\nexport type { PointerInput } from \"./pointer.js\";\nexport type { TypeOptions } from \"./text.js\";\nexport { resetClipboard } from \"./text.js\";\nexport {\n resetUserEventState,\n userEvent,\n userEventReports,\n type ClickReport,\n type KeyboardReport,\n type UserEvent,\n type UserEventOptions,\n};\n"]}
|
|
@@ -5,8 +5,33 @@ type TabOptions = {
|
|
|
5
5
|
/** Move focus backward instead of forward. */
|
|
6
6
|
isShiftHeld?: boolean;
|
|
7
7
|
};
|
|
8
|
+
type KeyAction = {
|
|
9
|
+
keyval: number;
|
|
10
|
+
isPress: boolean;
|
|
11
|
+
};
|
|
12
|
+
type TypedStep = {
|
|
13
|
+
text: string;
|
|
14
|
+
} | {
|
|
15
|
+
actions: KeyAction[];
|
|
16
|
+
};
|
|
17
|
+
/** The modifier keys pressed and not yet released, named as `keyboard` input names them. */
|
|
18
|
+
declare const heldModifiers: (state: UserEventState) => string[];
|
|
8
19
|
/** Moves focus within the widget's root. */
|
|
9
20
|
declare const tab: (widget: Gtk.Widget, options?: TabOptions) => Promise<void>;
|
|
10
|
-
declare const
|
|
11
|
-
|
|
21
|
+
declare const characterActions: (text: string) => KeyAction[];
|
|
22
|
+
declare const parseTypedInput: (input: string) => TypedStep[];
|
|
23
|
+
/**
|
|
24
|
+
* Returns a function that resolves the widget keys meant for `widget` reach now: the widget, or the widget outside it
|
|
25
|
+
* that focus has moved to since, as after a {Tab}.
|
|
26
|
+
*/
|
|
27
|
+
declare const followKeyFocus: (widget: Gtk.Widget) => (() => Gtk.Widget);
|
|
28
|
+
/** Applies the key actions and returns the keyvals of the presses, other than modifiers, that nothing handled. */
|
|
29
|
+
declare const applyKeyActions: (widget: Gtk.Widget, state: UserEventState, actions: KeyAction[]) => Promise<number[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Sends the key sequence and returns the keys, as `keyboard` input would name them, whose presses nothing on the
|
|
32
|
+
* widget, its focused descendant or their ancestors handled.
|
|
33
|
+
*/
|
|
34
|
+
declare const keyboard: (state: UserEventState, widget: Gtk.Widget, input: string) => Promise<string[]>;
|
|
35
|
+
declare const focusedKeyWidget: () => Gtk.Widget;
|
|
36
|
+
export { applyKeyActions, characterActions, focusedKeyWidget, followKeyFocus, heldModifiers, keyboard, parseTypedInput, tab, type TabOptions, type TypedStep, };
|
|
12
37
|
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/user-event/keyboard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/user-event/keyboard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAGpC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ACH,KAAK,UAAU,EACf,KAAK,SAAS,GACjB,CAAC"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import * as Gdk from "@gtkx/gi/gdk";
|
|
2
2
|
import * as Gio from "@gtkx/gi/gio";
|
|
3
3
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
4
|
+
import { getInstanceType, TYPE_INVALID, typeFromName, typeIsA } from "@gtkx/runtime";
|
|
4
5
|
import { hasSignalListener } from "@gtkx/runtime/internal";
|
|
5
6
|
import { getEditableDelegate } from "../editable.js";
|
|
6
7
|
import { fireEvent } from "../fire-event.js";
|
|
7
|
-
import { ancestors, descendants } from "../traversal.js";
|
|
8
|
+
import { ancestors, children, descendants } from "../traversal.js";
|
|
9
|
+
import { receivesEventsFor } from "./controller.js";
|
|
8
10
|
import { wrapEvent } from "./event-wrapper.js";
|
|
11
|
+
import { usageError } from "../usage-error.js";
|
|
12
|
+
import { getWidgetTypeName } from "../widget-getters.js";
|
|
13
|
+
import { activeToplevel, mappedToplevels } from "../window-state.js";
|
|
9
14
|
const lastActivatedShortcuts = new WeakMap();
|
|
10
15
|
const KEY_MAP = {
|
|
11
16
|
Enter: Gdk.KEY_Return,
|
|
@@ -40,6 +45,7 @@ const KEY_MAP = {
|
|
|
40
45
|
F12: Gdk.KEY_F12,
|
|
41
46
|
};
|
|
42
47
|
const KEY_CONTROLLER_SIGNALS = ["key-pressed", "key-released"];
|
|
48
|
+
const LITERAL_BRACE = "{{";
|
|
43
49
|
const MODIFIER_KEYVAL_TO_MASK = {
|
|
44
50
|
[Gdk.KEY_Shift_L]: Gdk.ModifierType.SHIFT_MASK,
|
|
45
51
|
[Gdk.KEY_Shift_R]: Gdk.ModifierType.SHIFT_MASK,
|
|
@@ -50,6 +56,14 @@ const MODIFIER_KEYVAL_TO_MASK = {
|
|
|
50
56
|
[Gdk.KEY_Meta_L]: Gdk.ModifierType.META_MASK,
|
|
51
57
|
[Gdk.KEY_Meta_R]: Gdk.ModifierType.META_MASK,
|
|
52
58
|
};
|
|
59
|
+
const MODIFIER_NAMES = [
|
|
60
|
+
["Control", Gdk.ModifierType.CONTROL_MASK],
|
|
61
|
+
["Shift", Gdk.ModifierType.SHIFT_MASK],
|
|
62
|
+
["Alt", Gdk.ModifierType.ALT_MASK],
|
|
63
|
+
["Meta", Gdk.ModifierType.META_MASK],
|
|
64
|
+
];
|
|
65
|
+
/** The modifier keys pressed and not yet released, named as `keyboard` input names them. */
|
|
66
|
+
const heldModifiers = (state) => MODIFIER_NAMES.filter(([, mask]) => (state.modifierState & mask) !== 0).map(([name]) => name);
|
|
53
67
|
/** Moves focus within the widget's root. */
|
|
54
68
|
const tab = (widget, options) => wrapEvent(widget, () => {
|
|
55
69
|
const direction = options?.isShiftHeld ? Gtk.DirectionType.TAB_BACKWARD : Gtk.DirectionType.TAB_FORWARD;
|
|
@@ -58,6 +72,10 @@ const tab = (widget, options) => wrapEvent(widget, () => {
|
|
|
58
72
|
root.childFocus(direction);
|
|
59
73
|
}
|
|
60
74
|
});
|
|
75
|
+
const characterKeyval = (keyName) => {
|
|
76
|
+
const [character, ...rest] = Array.from(keyName);
|
|
77
|
+
return character === undefined || rest.length > 0 ? undefined : Gdk.unicodeToKeyval(character.codePointAt(0) ?? 0);
|
|
78
|
+
};
|
|
61
79
|
const parseKeyToken = (token) => {
|
|
62
80
|
let keyName = token;
|
|
63
81
|
let isPress = true;
|
|
@@ -70,9 +88,9 @@ const parseKeyToken = (token) => {
|
|
|
70
88
|
keyName = keyName.slice(0, -1);
|
|
71
89
|
isRelease = false;
|
|
72
90
|
}
|
|
73
|
-
const keyval = KEY_MAP[keyName];
|
|
91
|
+
const keyval = KEY_MAP[keyName] ?? characterKeyval(keyName);
|
|
74
92
|
if (keyval === undefined) {
|
|
75
|
-
throw new Error(`Unknown key: {${keyName}}`);
|
|
93
|
+
throw usageError(new Error(`Unknown key: {${keyName}}`));
|
|
76
94
|
}
|
|
77
95
|
return { keyval, isPress, isRelease };
|
|
78
96
|
};
|
|
@@ -116,6 +134,34 @@ const parseKeyboardInput = (input) => {
|
|
|
116
134
|
}
|
|
117
135
|
return actions;
|
|
118
136
|
};
|
|
137
|
+
const characterActions = (text) => Array.from(text, (character) => parseCharAt(character, 0).actions).flat();
|
|
138
|
+
const parseTypedCharAt = (input, i) => {
|
|
139
|
+
const text = String.fromCodePoint(input.codePointAt(i) ?? 0);
|
|
140
|
+
return { step: { text }, next: i + text.length };
|
|
141
|
+
};
|
|
142
|
+
const parseTypedStepAt = (input, i) => {
|
|
143
|
+
if (input.startsWith(LITERAL_BRACE, i)) {
|
|
144
|
+
return { step: { text: "{" }, next: i + LITERAL_BRACE.length };
|
|
145
|
+
}
|
|
146
|
+
if (input[i] !== "{") {
|
|
147
|
+
return parseTypedCharAt(input, i);
|
|
148
|
+
}
|
|
149
|
+
const brace = parseBraceAt(input, i);
|
|
150
|
+
if (brace === null) {
|
|
151
|
+
throw usageError(new Error(`Unclosed key descriptor at ${String(i)} in "${input}"; type a literal { as {{`));
|
|
152
|
+
}
|
|
153
|
+
return { step: { actions: brace.actions }, next: brace.next };
|
|
154
|
+
};
|
|
155
|
+
const parseTypedInput = (input) => {
|
|
156
|
+
const steps = [];
|
|
157
|
+
let i = 0;
|
|
158
|
+
while (i < input.length) {
|
|
159
|
+
const { step, next } = parseTypedStepAt(input, i);
|
|
160
|
+
steps.push(step);
|
|
161
|
+
i = next;
|
|
162
|
+
}
|
|
163
|
+
return steps;
|
|
164
|
+
};
|
|
119
165
|
const updateModifierState = (state, action) => {
|
|
120
166
|
const mask = MODIFIER_KEYVAL_TO_MASK[action.keyval];
|
|
121
167
|
if (!mask) {
|
|
@@ -172,11 +218,10 @@ const managedShortcutHost = (manager, shortcut) => {
|
|
|
172
218
|
}
|
|
173
219
|
return null;
|
|
174
220
|
};
|
|
175
|
-
const isMovingFocus = (action) => action instanceof Gtk.SignalAction && action.getSignalName() === "move-focus";
|
|
176
221
|
const isShortcutLive = (host) => host.isSensitive() && host.getMapped();
|
|
177
222
|
const didRunShortcutAction = (shortcut, host, flags) => {
|
|
178
223
|
const action = shortcut.getAction();
|
|
179
|
-
if (action === null ||
|
|
224
|
+
if (action === null || !isShortcutLive(host)) {
|
|
180
225
|
return false;
|
|
181
226
|
}
|
|
182
227
|
return action.activate(flags, host, shortcut.getArguments());
|
|
@@ -242,26 +287,118 @@ const didDispatchAccelsOnWindow = (window, keyval, modifiers) => {
|
|
|
242
287
|
}
|
|
243
288
|
return false;
|
|
244
289
|
};
|
|
245
|
-
const didDispatchApplicationAccels = (
|
|
246
|
-
const root =
|
|
247
|
-
return root instanceof Gtk.Window &&
|
|
290
|
+
const didDispatchApplicationAccels = (target, keyval, modifiers) => {
|
|
291
|
+
const root = target.getRoot();
|
|
292
|
+
return (root instanceof Gtk.Window &&
|
|
293
|
+
receivesEventsFor(root, Gtk.PropagationLimit.SAME_NATIVE, target) &&
|
|
294
|
+
didDispatchAccelsOnWindow(root, keyval, modifiers));
|
|
295
|
+
};
|
|
296
|
+
const SEARCH_BAR_CAPTURE_NAME = "gtk-search-bar-capture";
|
|
297
|
+
const ENTRY_COMPLETION_CLASS = "entry-completion";
|
|
298
|
+
const FILE_CHOOSER_ENTRY_TYPE_NAME = "GtkFileChooserEntry";
|
|
299
|
+
const CELL_EDITABLE_TYPE_NAME = "GtkCellEditableWidget";
|
|
300
|
+
/**
|
|
301
|
+
* GTK has no public getter for a text view's own key controller (`gtk_text_view_get_key_controller` is private) and
|
|
302
|
+
* lists controllers newest first, so the last key controller is the one the text view added when it was created.
|
|
303
|
+
* Controllers that subclasses such as GtkSourceView add read the current event, which emulated keys lack.
|
|
304
|
+
*/
|
|
305
|
+
const isTextViewKeyController = (controller, widget) => controllersOn(widget)
|
|
306
|
+
.filter((current) => current instanceof Gtk.EventControllerKey)
|
|
307
|
+
.toArray()
|
|
308
|
+
.at(-1) === controller;
|
|
309
|
+
const isTextViewLibraryController = (controller, widget) => widget instanceof Gtk.TextView && !isTextViewKeyController(controller, widget);
|
|
310
|
+
const capturesKeysOf = (candidate, widget) => (candidate instanceof Gtk.SearchEntry || candidate instanceof Gtk.SearchBar) &&
|
|
311
|
+
candidate.getKeyCaptureWidget() === widget;
|
|
312
|
+
/**
|
|
313
|
+
* A search entry or search bar with a key capture widget adds a key controller to that widget, which forwards the
|
|
314
|
+
* current event to the entry. The search bar names its controller; the search entry leaves its own unnamed.
|
|
315
|
+
*/
|
|
316
|
+
const isSearchKeyCapture = (controller, widget) => {
|
|
317
|
+
const name = controller.getName();
|
|
318
|
+
return (name === SEARCH_BAR_CAPTURE_NAME ||
|
|
319
|
+
(name === null &&
|
|
320
|
+
(capturesKeysOf(widget, widget) ||
|
|
321
|
+
descendants(widget).some((candidate) => capturesKeysOf(candidate, widget)))));
|
|
248
322
|
};
|
|
249
|
-
const
|
|
323
|
+
const isFileChooserForwarder = (_controller, widget) => widget instanceof Gtk.FileChooserWidget || getWidgetTypeName(widget) === FILE_CHOOSER_ENTRY_TYPE_NAME;
|
|
324
|
+
/**
|
|
325
|
+
* Widget types from other libraries whose key controllers read the current event: WebKit filters it through its input
|
|
326
|
+
* method and passes it to the web process.
|
|
327
|
+
*/
|
|
328
|
+
const EVENT_READING_LIBRARY_TYPE_NAMES = ["WebKitWebViewBase"];
|
|
329
|
+
const isLibraryEventReader = (_controller, widget) => EVENT_READING_LIBRARY_TYPE_NAMES.some((name) => {
|
|
330
|
+
const type = typeFromName(name);
|
|
331
|
+
return type !== TYPE_INVALID && typeIsA(getInstanceType(widget), type);
|
|
332
|
+
});
|
|
333
|
+
const isDeprecatedPopup = (widget) => widget instanceof Gtk.Popover &&
|
|
334
|
+
(widget.getParent() instanceof Gtk.ComboBox || widget.hasCssClass(ENTRY_COMPLETION_CLASS));
|
|
335
|
+
const isDeprecatedWidgetForwarder = (_controller, widget) => widget instanceof Gtk.TreeView ||
|
|
336
|
+
getWidgetTypeName(widget) === CELL_EDITABLE_TYPE_NAME ||
|
|
337
|
+
isDeprecatedPopup(widget);
|
|
338
|
+
/**
|
|
339
|
+
* Key controllers GTK and its libraries add without a JavaScript listener whose handlers need the real key event,
|
|
340
|
+
* which emulated keys lack: they filter it through an input method, forward it with
|
|
341
|
+
* `gtk_event_controller_key_forward()` or read it directly, and log a critical without one. Emulated keys skip them;
|
|
342
|
+
* every other key controller receives the keys.
|
|
343
|
+
*/
|
|
344
|
+
const REAL_EVENT_KEY_HANDLERS = [
|
|
345
|
+
isTextViewLibraryController,
|
|
346
|
+
isSearchKeyCapture,
|
|
347
|
+
isFileChooserForwarder,
|
|
348
|
+
isDeprecatedWidgetForwarder,
|
|
349
|
+
isLibraryEventReader,
|
|
350
|
+
];
|
|
351
|
+
const needsRealKeyEvent = (controller, widget) => REAL_EVENT_KEY_HANDLERS.some((needsEvent) => needsEvent(controller, widget));
|
|
352
|
+
const SOURCE_COMPLETION_CONTROLLER_NAME = "gtk-source-completion";
|
|
353
|
+
const SOURCE_COMPLETION_LIST_TYPE_NAME = "GtkSourceCompletionList";
|
|
354
|
+
const SOURCE_COMPLETION_LIST_BOX_TYPE_NAME = "GtkSourceCompletionListBox";
|
|
355
|
+
/**
|
|
356
|
+
* GtkSourceView's completion adds a key controller to the view. While the completion list shows, the controller hides
|
|
357
|
+
* the list on {Escape} and forwards every other key to the list's box with `gtk_event_controller_key_forward()`, where
|
|
358
|
+
* the box's bindings move the selection and choose the selected proposal. Emulated keys have no event to forward, so
|
|
359
|
+
* they take the same path through the box's own controllers.
|
|
360
|
+
*/
|
|
361
|
+
const completionListFor = (controller, widget) => controller.getName() === SOURCE_COMPLETION_CONTROLLER_NAME
|
|
362
|
+
? (children(widget).find((child) => getWidgetTypeName(child) === SOURCE_COMPLETION_LIST_TYPE_NAME) ?? null)
|
|
363
|
+
: null;
|
|
364
|
+
const isKeyStopController = (controller, widget) => {
|
|
250
365
|
if (controller instanceof Gtk.ShortcutController) {
|
|
251
366
|
return controller.getScope() === Gtk.ShortcutScope.LOCAL;
|
|
252
367
|
}
|
|
253
|
-
return controller instanceof Gtk.EventControllerKey &&
|
|
368
|
+
return (controller instanceof Gtk.EventControllerKey &&
|
|
369
|
+
(hasSignalListener(controller, KEY_CONTROLLER_SIGNALS) || !needsRealKeyEvent(controller, widget)));
|
|
370
|
+
};
|
|
371
|
+
const keyStopFor = (controller, widget) => {
|
|
372
|
+
const completionList = completionListFor(controller, widget);
|
|
373
|
+
if (completionList !== null) {
|
|
374
|
+
return { widget, completionList };
|
|
375
|
+
}
|
|
376
|
+
return isKeyStopController(controller, widget) ? { widget, controller } : null;
|
|
254
377
|
};
|
|
255
|
-
const keyStopsInPhase = (widget, phase) => {
|
|
378
|
+
const keyStopsInPhase = (widget, phase, target) => {
|
|
256
379
|
const stops = [];
|
|
257
380
|
for (const controller of controllersOn(widget)) {
|
|
258
|
-
|
|
259
|
-
|
|
381
|
+
const stop = controller.getPropagationPhase() === phase &&
|
|
382
|
+
receivesEventsFor(widget, controller.getPropagationLimit(), target)
|
|
383
|
+
? keyStopFor(controller, widget)
|
|
384
|
+
: null;
|
|
385
|
+
if (stop !== null) {
|
|
386
|
+
stops.push(stop);
|
|
260
387
|
}
|
|
261
388
|
}
|
|
262
389
|
return stops;
|
|
263
390
|
};
|
|
391
|
+
const forwardedKeyStops = (target) => [Gtk.PropagationPhase.CAPTURE, Gtk.PropagationPhase.TARGET, Gtk.PropagationPhase.BUBBLE].flatMap((phase) => keyStopsInPhase(target, phase, target));
|
|
392
|
+
const focusWithin = (widget) => {
|
|
393
|
+
const root = widget.getRoot();
|
|
394
|
+
const focus = root instanceof Gtk.Window ? root.getFocus() : null;
|
|
395
|
+
return focus?.getMapped() === true && focus.isAncestor(widget) ? focus : null;
|
|
396
|
+
};
|
|
264
397
|
const propagationChain = (widget) => {
|
|
398
|
+
const focus = focusWithin(widget);
|
|
399
|
+
if (focus !== null) {
|
|
400
|
+
return [focus, ...ancestors(focus)];
|
|
401
|
+
}
|
|
265
402
|
const delegate = getEditableDelegate(widget);
|
|
266
403
|
const below = delegate === null ? [] : [delegate];
|
|
267
404
|
return [...below, widget, ...ancestors(widget)];
|
|
@@ -270,18 +407,32 @@ const keyPropagationChain = (widget) => {
|
|
|
270
407
|
const chain = propagationChain(widget);
|
|
271
408
|
const [eventWidget = widget] = chain;
|
|
272
409
|
return [
|
|
273
|
-
...chain.toReversed().flatMap((current) => keyStopsInPhase(current, Gtk.PropagationPhase.CAPTURE)),
|
|
274
|
-
...keyStopsInPhase(eventWidget, Gtk.PropagationPhase.TARGET),
|
|
275
|
-
...chain.flatMap((current) => keyStopsInPhase(current, Gtk.PropagationPhase.BUBBLE)),
|
|
410
|
+
...chain.toReversed().flatMap((current) => keyStopsInPhase(current, Gtk.PropagationPhase.CAPTURE, eventWidget)),
|
|
411
|
+
...keyStopsInPhase(eventWidget, Gtk.PropagationPhase.TARGET, eventWidget),
|
|
412
|
+
...chain.flatMap((current) => keyStopsInPhase(current, Gtk.PropagationPhase.BUBBLE, eventWidget)),
|
|
276
413
|
];
|
|
277
414
|
};
|
|
278
|
-
const
|
|
415
|
+
const didCompletionHandlePress = (completionList, keyval, modifiers) => {
|
|
416
|
+
if (!completionList.getVisible()) {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
if (keyval === Gdk.KEY_Escape) {
|
|
420
|
+
completionList.setVisible(false);
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
const box = descendants(completionList).find((descendant) => getWidgetTypeName(descendant) === SOURCE_COMPLETION_LIST_BOX_TYPE_NAME);
|
|
424
|
+
return box !== undefined && forwardedKeyStops(box).some((stop) => didStopHandlePress(stop, keyval, modifiers));
|
|
425
|
+
};
|
|
426
|
+
function didStopHandlePress(stop, keyval, modifiers) {
|
|
427
|
+
if ("completionList" in stop) {
|
|
428
|
+
return didCompletionHandlePress(stop.completionList, keyval, modifiers);
|
|
429
|
+
}
|
|
279
430
|
const { controller, widget } = stop;
|
|
280
431
|
if (controller instanceof Gtk.ShortcutController) {
|
|
281
432
|
return didActivateMatchingShortcut(controller, widget, keyval, modifiers);
|
|
282
433
|
}
|
|
283
434
|
return controller.emit("key-pressed", keyval, 0, modifiers);
|
|
284
|
-
}
|
|
435
|
+
}
|
|
285
436
|
const keyTargetFor = (widget) => {
|
|
286
437
|
const root = widget.getRoot();
|
|
287
438
|
return { root, focus: root instanceof Gtk.Window ? root.getFocus() : null };
|
|
@@ -292,7 +443,8 @@ const isKeyTargetInvalidated = (widget, target) => {
|
|
|
292
443
|
};
|
|
293
444
|
const didHandlePress = (widget, keyval, modifiers) => {
|
|
294
445
|
const target = keyTargetFor(widget);
|
|
295
|
-
|
|
446
|
+
const [eventWidget = widget] = propagationChain(widget);
|
|
447
|
+
if (didDispatchApplicationAccels(eventWidget, keyval, modifiers)) {
|
|
296
448
|
return true;
|
|
297
449
|
}
|
|
298
450
|
if (isKeyTargetInvalidated(widget, target)) {
|
|
@@ -307,31 +459,100 @@ const didHandlePress = (widget, keyval, modifiers) => {
|
|
|
307
459
|
};
|
|
308
460
|
const emitKeyReleased = (widget, keyval, modifiers) => {
|
|
309
461
|
for (const stop of keyPropagationChain(widget)) {
|
|
310
|
-
if (stop.controller instanceof Gtk.EventControllerKey) {
|
|
462
|
+
if ("controller" in stop && stop.controller instanceof Gtk.EventControllerKey) {
|
|
311
463
|
stop.controller.emit("key-released", keyval, 0, modifiers);
|
|
312
464
|
}
|
|
313
465
|
}
|
|
314
466
|
};
|
|
315
467
|
const applyKeyPress = async (widget, keyval, modifiers) => {
|
|
316
468
|
if (didHandlePress(widget, keyval, modifiers)) {
|
|
317
|
-
return;
|
|
469
|
+
return true;
|
|
318
470
|
}
|
|
319
471
|
if (keyval === Gdk.KEY_Return && widget instanceof Gtk.Editable) {
|
|
320
472
|
await fireEvent(widget, "activate");
|
|
473
|
+
return true;
|
|
321
474
|
}
|
|
475
|
+
return false;
|
|
322
476
|
};
|
|
323
|
-
const
|
|
477
|
+
const isUnhandledPress = async (widget, state, action) => {
|
|
324
478
|
updateModifierState(state, action);
|
|
325
|
-
if (action.isPress) {
|
|
326
|
-
|
|
479
|
+
if (!action.isPress) {
|
|
480
|
+
emitKeyReleased(widget, action.keyval, state.modifierState);
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
const isHandled = await applyKeyPress(widget, action.keyval, state.modifierState);
|
|
484
|
+
return !isHandled && MODIFIER_KEYVAL_TO_MASK[action.keyval] === undefined;
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* Returns a function that resolves the widget keys meant for `widget` reach now: the widget, or the widget outside it
|
|
488
|
+
* that focus has moved to since, as after a {Tab}.
|
|
489
|
+
*/
|
|
490
|
+
const followKeyFocus = (widget) => {
|
|
491
|
+
const start = keyTargetFor(widget);
|
|
492
|
+
return () => {
|
|
493
|
+
const { root, focus } = keyTargetFor(widget);
|
|
494
|
+
return root === start.root && focus !== null && focus !== start.focus && !focus.isAncestor(widget)
|
|
495
|
+
? focus
|
|
496
|
+
: widget;
|
|
497
|
+
};
|
|
498
|
+
};
|
|
499
|
+
/** Applies the key actions and returns the keyvals of the presses, other than modifiers, that nothing handled. */
|
|
500
|
+
const applyKeyActions = async (widget, state, actions) => {
|
|
501
|
+
const keyWidget = followKeyFocus(widget);
|
|
502
|
+
const unhandled = [];
|
|
503
|
+
for (const action of actions) {
|
|
504
|
+
if (await isUnhandledPress(keyWidget(), state, action)) {
|
|
505
|
+
unhandled.push(action.keyval);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return unhandled;
|
|
509
|
+
};
|
|
510
|
+
const keyLabel = (keyval) => {
|
|
511
|
+
const name = Object.keys(KEY_MAP).find((key) => KEY_MAP[key] === keyval);
|
|
512
|
+
const character = Gdk.keyvalToUnicode(keyval);
|
|
513
|
+
if (name !== undefined) {
|
|
514
|
+
return `{${name}}`;
|
|
515
|
+
}
|
|
516
|
+
return character === 0 ? `{${Gdk.keyvalName(keyval) ?? String(keyval)}}` : String.fromCodePoint(character);
|
|
517
|
+
};
|
|
518
|
+
const canTakeFocus = (widget) => widget.getFocusable() && widget.getCanFocus();
|
|
519
|
+
/**
|
|
520
|
+
* Focuses a target whose window has its focus elsewhere, as a user does before typing, so the window's own bindings
|
|
521
|
+
* such as {Space} and {Enter} activating the focus widget act on the target. An entry that delegates its focus to its
|
|
522
|
+
* text, such as a search entry, takes it there without selecting the text, as a click does. A widget that passes its
|
|
523
|
+
* focus to a child, such as a menu button to its button, focuses that child.
|
|
524
|
+
*/
|
|
525
|
+
const focusKeyTarget = (widget) => {
|
|
526
|
+
if (focusWithin(widget) !== null) {
|
|
327
527
|
return;
|
|
328
528
|
}
|
|
329
|
-
|
|
529
|
+
const delegate = getEditableDelegate(widget);
|
|
530
|
+
if (delegate instanceof Gtk.Text && canTakeFocus(delegate)) {
|
|
531
|
+
delegate.grabFocusWithoutSelecting();
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
widget.grabFocus();
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
/**
|
|
538
|
+
* Sends the key sequence and returns the keys, as `keyboard` input would name them, whose presses nothing on the
|
|
539
|
+
* widget, its focused descendant or their ancestors handled.
|
|
540
|
+
*/
|
|
541
|
+
const keyboard = async (state, widget, input) => {
|
|
542
|
+
let unhandled = [];
|
|
543
|
+
await wrapEvent(widget, async () => {
|
|
544
|
+
focusKeyTarget(widget);
|
|
545
|
+
unhandled = await applyKeyActions(widget, state, parseKeyboardInput(input));
|
|
546
|
+
});
|
|
547
|
+
return [...new Set(unhandled.map((keyval) => keyLabel(keyval)))];
|
|
330
548
|
};
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
549
|
+
const focusedKeyWidget = () => {
|
|
550
|
+
const window = activeToplevel() ?? mappedToplevels()[0];
|
|
551
|
+
if (window === undefined) {
|
|
552
|
+
throw usageError(new Error("No window is open to receive the keys"));
|
|
334
553
|
}
|
|
335
|
-
|
|
336
|
-
|
|
554
|
+
const focus = window.getFocus();
|
|
555
|
+
return focus?.getMapped() ? focus : window;
|
|
556
|
+
};
|
|
557
|
+
export { applyKeyActions, characterActions, focusedKeyWidget, followKeyFocus, heldModifiers, keyboard, parseTypedInput, tab, };
|
|
337
558
|
//# sourceMappingURL=keyboard.js.map
|