codemirror-interact icon indicating copy to clipboard operation
codemirror-interact copied to clipboard

Proposal: Flag to Disable Alt Key

Open curran opened this issue 3 years ago • 3 comments

I'm interested in having this behave in such a way that the Alt key is not required to press in order to interact.

Ideally the ew-resize cursor would appear over numbers without any mod key pressed, and dragging them would change them.

This line https://github.com/replit/codemirror-interact/blob/06021e3fed0f61bf2a8fc6c3e8b8a664afd92977/src/interact.ts#L269 looks like a good place to start. Perhaps null could be passed into the config? In order to support that, it looks like all we need to do is add another case here that checks for null in the config and always returns true.

https://github.com/replit/codemirror-interact/blob/06021e3fed0f61bf2a8fc6c3e8b8a664afd92977/src/interact.ts#L152-L157

Maybe something like:

switch (modkey) { 
   case "alt": return e.altKey; 
   case "shift": return e.shiftKey; 
   case "ctrl": return e.ctrlKey; 
   case "meta": return e.metaKey;
   case null: return true;
 } 

Any other suggestions for how to approach it? Thanks!

curran avatar Sep 02 '22 19:09 curran

Thanks! That's an interesting idea. I'm not sure if there would be performance issues from having the relevant event handlers run every time you mouse or keydown but in theory it's doable.

@slmjkdbtl wdyt?

sergeichestakov avatar Sep 02 '22 21:09 sergeichestakov

It'll have less performance but should be unnoticeable, it's doable but what I worry about is it disables selection on those text, is that something you want?

slmjkdbtl avatar Sep 06 '22 00:09 slmjkdbtl

Thanks @sergeichestakov and @slmjkdbtl for investigating!

I would like to try it and see how a first version without the Alt key feels.

I wonder if it might be possible to make it so that:

  • Clicking on the number places the cursor there, as usual.
  • Double-clicking on the number selects the number, as usual.
  • Dragging on the number has the interactive behavior, not the usual selection behavior.

If the user can still place the cursor in the number, and can still double-click to select it, I would think it should be OK to remove the drag-to-select interaction on numbers.

curran avatar Sep 06 '22 13:09 curran