Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: FuzzySuggestModal's onChooseItem does not fire on enter/return with modifier keys #85

Open
cryy22 opened this issue Nov 3, 2022 · 3 comments

Comments

@cryy22
Copy link

cryy22 commented Nov 3, 2022

I want to open a file selected via FuzzySuggestModal in a new tab, new split, or new window according to the modifier keys held down while the selection occurs, mirroring the behavior of Quick Switcher. However, onChooseItem is not currently firing when any modifier keys are held down.

Steps to reproduce:

  • extend FuzzySuggestModal and implement getItems and getItemText with dummy data
  • for onChooseItem, console.log("hello")
  • invoke your FuzzySuggestModal from Obsidian
  • hold down any one or more modifier keys (tried with Shift, Meta, Ctrl and Alt/Option on macOS) while pressing enter/return
  • observe no message in the console, and the modal is not dismissed
@cryy22
Copy link
Author

cryy22 commented Nov 3, 2022

I've reproduced the issue in a sample plugin here: https://github.com/cryy22/obsidian-FuzzySuggestModal-bug-demo

@cryy22 cryy22 changed the title Bug: FuzzySuggestModal's onChooseItem does not fire when modifier keys are held down Bug: FuzzySuggestModal's onChooseItem does not fire on enter/return with modifier keys Nov 4, 2022
@lishid
Copy link
Collaborator

lishid commented Jan 22, 2023

This is currently on purpose but the procedure to allow other keys is not yet well documented:

constructor(app: App) {
  super(app);
  // @ts-ignore
  this.scope.register([], 'Tab', (evt: KeyboardEvent) => {
    // @ts-ignore
    if (!evt.isComposing && this.suggestions.useSelectedItem(evt)) {
      return false;
    }
  });
}

Zachatoo added a commit to Zachatoo/obsidian-css-editor that referenced this issue Sep 3, 2023
@Zachatoo
Copy link

Zachatoo commented Sep 3, 2023

Looks like the internal APIs changed a bit, here's the solution that worked for me. Would love to see better support for this.

constructor(app: App) {
  super(app);
  this.scope.register([], 'Tab', (evt: KeyboardEvent) => {
    // @ts-ignore
    if (!evt.isComposing && this.chooser.useSelectedItem(evt)) {
      return false;
    }
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants