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

Enable Native Double Tap as Keybinding (keymap.cson) #301

Open
1 task done
rajmondx opened this issue Jan 5, 2023 · 3 comments
Open
1 task done

Enable Native Double Tap as Keybinding (keymap.cson) #301

rajmondx opened this issue Jan 5, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@rajmondx
Copy link

rajmondx commented Jan 5, 2023

Have you checked for existing feature requests?

  • Completed

Summary

Allow users to double tap any button (eg. as IDEA allows it with their "double shift")
something like this

'.platform-win32':
  'shift-shift': 'fuzzy-finder:toggle-file-finder'

# or plus
'.platform-win32':
  'shift+shift': 'fuzzy-finder:toggle-file-finder'

What benefits does this feature provide?

No big deal. I would just love to see this feature because of the muscle memory gained in IDEA, hard to not double press shift and somehow I believe some idea users might not like any ide if its not possible to configure double tap.

Any alternatives?

Edit File > Init Script (init.js):

const keystrokeCache = {};
const maxDoubleTime = 500;
const allowKeystrokeResolverOnlyFor = ['shift'/*, 'enter'*/];

atom.keymaps.addKeystrokeResolver((keypress)=>{
  try{
    const keystroke = keypress.keystroke;
    if(allowKeystrokeResolverOnlyFor.indexOf(keystroke) >= 0){
      // keypress.event.repeat == is holding, doesnt count
      if(!keypress.event.repeat && keypress.event.type == 'keydown'){
        const lastPressedTimestamp = keystrokeCache[keystroke] || keypress.event.timeStamp;
        const currentPressedTimestamp = keypress.event.timeStamp;
        const diff = currentPressedTimestamp-lastPressedTimestamp;
        if(diff > 0 && diff < maxDoubleTime){
          return `${keystroke}+${keystroke}`;
        }
        keystrokeCache[keystroke] = keypress.event.timeStamp;
      }
    }
  }catch(e){
    console.error('DoubleKeystrokeResolver: ', e);
  }
});

Use in File > Keymap (keymap.cson) for example:

# Use + instead of -
'.platform-win32':
  'shift+shift': 'fuzzy-finder:toggle-file-finder'

hint. Check allowKeystrokeResolverOnlyFor to allow any other buttons than shift for double tap (be caution with buttons like backspace)

hint. You need to use + instead of - in keymap.cson because - doesn't work for double tap (it seems that pulsar-edit is interpreting shift-shift like a single button press).

Other examples:

No response

@rajmondx rajmondx added the enhancement New feature or request label Jan 5, 2023
@confused-Techie
Copy link
Member

Thanks for the contribution, this would be a pretty cool feature to see integrated

@rajmondx
Copy link
Author

rajmondx commented Jan 5, 2023

Thanks for the contribution, this would be a pretty cool feature to see integrated

Check "Alternatives": I wrote a script which you could add to your own init.js, its a bit hacky and it could be done better (eg. if your init.js gets bigger such "little scripts" end up messy or you could increase the performance by using keyid instead of strings etc.) but it does what its supposed to do.

@mauricioszabo
Copy link
Contributor

I don't think this is supported by Electron or browsers in general (trigger an event when a modifier key is pressed). If they don't send us the keystroke, there's nothing we can actually do...

One thing they you CAN do already is double tap any key that's not a modifier. For example, the keystroke 'esc esc' works today (double tap escape key).

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

No branches or pull requests

3 participants