@hexdspace/react 0.1.49 → 0.1.51

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/index.d.ts CHANGED
@@ -894,6 +894,7 @@ declare class VimHandleKeyUseCase {
894
894
  reset(scopeId?: ScopeId): void;
895
895
  handleChar(char: string, e: KeyboardEvent): void;
896
896
  handleEscape(e: KeyboardEvent): void;
897
+ consumeCount(scopeId: ScopeId, def: number): number;
897
898
  private applyDirectional;
898
899
  private goToLast;
899
900
  private goToIndex;
@@ -912,6 +913,7 @@ type VimModifierMovementActionArgs = {
912
913
  key: RegionKey;
913
914
  itemId: ItemId | null;
914
915
  direction: VimDirection;
916
+ count: number;
915
917
  event: KeyboardEvent;
916
918
  };
917
919
  type VimModifierMovementAction = (args: VimModifierMovementActionArgs) => void;
@@ -924,13 +926,13 @@ declare class VimController {
924
926
  private readonly regions;
925
927
  private readonly handleKey;
926
928
  private readonly selection;
927
- private readonly modifierMovementActionsByScope;
929
+ private readonly modifierMovementActionsByRegion;
928
930
  constructor(selection: SelectionController, regions?: VimRegionRegistry, handleKey?: VimHandleKeyUseCase);
929
931
  handleRegisterRegionMeta(meta: VimRegionMeta): void;
930
932
  handleUnregisterRegionMeta(key: RegionKey): void;
931
933
  handleCharKey(char: string, e: KeyboardEvent): void;
932
934
  handleEscape(e: KeyboardEvent): void;
933
- setModifierMovementActions(scopeId: ScopeId, actions: VimModifierMovementActions | null): void;
935
+ setModifierMovementActions(key: RegionKey, actions: VimModifierMovementActions | null): void;
934
936
  handleModifiedMovement(dir: VimDirection, modifier: VimMovementModifier, e: KeyboardEvent): void;
935
937
  resetActiveScope(): void;
936
938
  getSelection(): SelectionController;
@@ -954,7 +956,7 @@ type VimBindingOptions = {
954
956
  allowArrowKeys?: boolean;
955
957
  modifierMovementActions?: VimModifierMovementActions;
956
958
  };
957
- declare function useVimBindings(keyboardScopeId: string, options?: VimBindingOptions): void;
959
+ declare function useVimBindings(regionKey: RegionKey, keyboardScopeId: string, options?: VimBindingOptions): void;
958
960
 
959
961
  type UseVimRegionArgs = {
960
962
  key: RegionKey;
package/dist/index.js CHANGED
@@ -3383,6 +3383,13 @@ var VimHandleKeyUseCase = class {
3383
3383
  st.pending = null;
3384
3384
  }
3385
3385
  }
3386
+ consumeCount(scopeId, def) {
3387
+ const st = this.stateByScope.get(scopeId);
3388
+ if (!st) return def;
3389
+ const count = consumeCount(st, def);
3390
+ st.pending = null;
3391
+ return count;
3392
+ }
3386
3393
  applyDirectional(scopeId, activeKey, dir, count) {
3387
3394
  const meta = this.regions.get(activeKey);
3388
3395
  if (meta?.intra.has(dir)) {
@@ -3569,7 +3576,7 @@ var VimController = class {
3569
3576
  regions;
3570
3577
  handleKey;
3571
3578
  selection;
3572
- modifierMovementActionsByScope = /* @__PURE__ */ new Map();
3579
+ modifierMovementActionsByRegion = /* @__PURE__ */ new Map();
3573
3580
  constructor(selection, regions = new VimRegionRegistry(), handleKey = new VimHandleKeyUseCase(
3574
3581
  selection.getHandle(),
3575
3582
  selection.getQuery(),
@@ -3592,23 +3599,25 @@ var VimController = class {
3592
3599
  handleEscape(e) {
3593
3600
  this.handleKey.handleEscape(e);
3594
3601
  }
3595
- setModifierMovementActions(scopeId, actions) {
3602
+ setModifierMovementActions(key, actions) {
3603
+ const regionKey = toRegionKeyString(key);
3596
3604
  if (!actions) {
3597
- this.modifierMovementActionsByScope.delete(scopeId);
3605
+ this.modifierMovementActionsByRegion.delete(regionKey);
3598
3606
  return;
3599
3607
  }
3600
- this.modifierMovementActionsByScope.set(scopeId, actions);
3608
+ this.modifierMovementActionsByRegion.set(regionKey, actions);
3601
3609
  }
3602
3610
  handleModifiedMovement(dir, modifier, e) {
3603
3611
  const scopeId = this.selection.getActiveScope();
3604
3612
  if (!scopeId) return;
3605
3613
  const activeKey = this.selection.getActiveRegion(scopeId);
3606
3614
  if (!activeKey) return;
3607
- const actions = this.modifierMovementActionsByScope.get(scopeId);
3615
+ const actions = this.modifierMovementActionsByRegion.get(toRegionKeyString(activeKey));
3608
3616
  const action = actions?.[modifier]?.[dir];
3609
3617
  if (!action) return;
3610
3618
  const itemId = this.selection.getActiveItem(activeKey);
3611
- action({ scopeId, key: activeKey, itemId, direction: dir, event: e });
3619
+ const count = this.handleKey.consumeCount(scopeId, 1);
3620
+ action({ scopeId, key: activeKey, itemId, direction: dir, count, event: e });
3612
3621
  }
3613
3622
  resetActiveScope() {
3614
3623
  const scopeId = this.selection.getActiveScope();
@@ -3640,6 +3649,9 @@ var createVimController = controllerFactory(
3640
3649
  };
3641
3650
  }
3642
3651
  );
3652
+ function toRegionKeyString(key) {
3653
+ return `${key.scopeId}.${key.regionId}`;
3654
+ }
3643
3655
 
3644
3656
  // src/feature/vim-navigation/infra/web/react/VimControllerProvider.tsx
3645
3657
  import { createContext as createContext5, useContext as useContext6 } from "react";
@@ -3662,7 +3674,7 @@ function notify(entry) {
3662
3674
  notifySub(entry.ownerId);
3663
3675
  }
3664
3676
  }
3665
- function useVimBindings(keyboardScopeId, options = {}) {
3677
+ function useVimBindings(regionKey, keyboardScopeId, options = {}) {
3666
3678
  const vim = useVimController();
3667
3679
  const enabled = options.enabled ?? true;
3668
3680
  const allowArrowKeys = options.allowArrowKeys ?? true;
@@ -3705,12 +3717,13 @@ function useVimBindings(keyboardScopeId, options = {}) {
3705
3717
  };
3706
3718
  }, [enabled, handleOwnerChange, keyboardScopeId]);
3707
3719
  useEffect7(() => {
3708
- if (!enabled || !isOwner) {
3720
+ if (!enabled) {
3721
+ vim.setModifierMovementActions(regionKey, null);
3709
3722
  return;
3710
3723
  }
3711
- vim.setModifierMovementActions(keyboardScopeId, modifierMovementActions ?? null);
3712
- return () => vim.setModifierMovementActions(keyboardScopeId, null);
3713
- }, [enabled, isOwner, keyboardScopeId, modifierMovementActions, vim]);
3724
+ vim.setModifierMovementActions(regionKey, modifierMovementActions ?? null);
3725
+ return () => vim.setModifierMovementActions(regionKey, null);
3726
+ }, [enabled, modifierMovementActions, regionKey, vim]);
3714
3727
  const bindings = useMemo6(() => {
3715
3728
  if (!enabled || !isOwner) {
3716
3729
  return [];
@@ -3891,7 +3904,7 @@ function useVimRegion(containerRef, args) {
3891
3904
  keyboard.handleEnableScope(keyboardScopeId);
3892
3905
  return () => keyboard.handleDisableScope(keyboardScopeId);
3893
3906
  }, [bindKeys, keyboard, keyboardScopeId]);
3894
- useVimBindings(keyboardScopeId, {
3907
+ useVimBindings(args.key, keyboardScopeId, {
3895
3908
  enabled: bindKeys,
3896
3909
  allowArrowKeys: args.allowArrowKeys,
3897
3910
  modifierMovementActions: args.modifierMovementActions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexdspace/react",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",