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
Option to drag by fixed amounts/intervals #116
Comments
Yes, I'd accept a PR for this idea. |
OK, sounds good. I have already implemented here, although I did it outside the splitjs codebase using |
Look at the code that uses |
Not a proper PR yet, but since it's my first contribution here I wanted to make sure you are happy with how I have implemented this. Here are the changes I have made: adrianbj@34ea3ee Obviously I need to do this in the file under src instead, but for quick testing this was easiest for now. If you're happy with this, I'll redo as a proper PR. Do you want me to add to the docs as well? I assume you'll handle building/minifying? Thanks! |
Actually, I am using |
I named the option snapInterval. Do you prefer this or dragInterval? Keep in mind my other recent suggestion for keyboard shortcuts for resizing in which case "drag" may be less appropriate. |
Great! This looks good. You don't need to account for the gutter in the dragging math, that's handled later. I would say subtract half of the dragInterval, so that the gutter is more centered under the cursor. Change that line to this: (Math.ceil(offset / snapInterval) * snapInterval) - (snapInterval / 2) You can also get rid of this if statement and the if(offset!== snappedInterval) { And just set offset directly instead: offset = (Math.ceil(offset / snapInterval) * snapInterval) - (snapInterval / 2) Please add the new option to the README, both in the markdown table and further down with the default value and description. I'll handle building and minifying, so the only changes in the PR should be in |
Also I think |
One more thing for your PR, add yourself to the AUTHORS.md file. |
I see, your version matches the line heights. I was optimizing for keeping the cursor over the gutter. You can see the difference in the two (very nice) gifs you posted. |
Right - I do now see why you wanted the mouse cursor over the gutter, but I think that the position of the gutter relative to the line height is more important - otherwise the end result is quite ineffective. This seems to accommodate both needs relatively well:
It still jumps obviously, but at least now each time it snaps it snaps into place under the cursor. What do you think - would you be happy accepting this version? |
Oh, here's the better option: offset = Math.round(offset / dragInterval) * dragInterval
|
Sorry, I'm not trying to be difficult, just want to make sure this new option works all around and not just for this specific use case. In your example, the "correct" sizing will only apply to the first (top) element of the split. If you tried your example in the second (bottom) element, the sizing would be off because I'm trying to come up with a solution that doesn't use |
I don't think you're being difficult at all :) I guess I need to setup a working example with ACE editor instances in both elements so I can test properly. |
I thought about this a bit more, and I think we'll need a second option besides Here's the 3 behaviors against a 20px background, with |
In |
Added this changes in PR #155. Please give it a try and see if that works for your use case. |
That looks good and seems like a great solution - thanks for picking up on this and making it some much better / more versatile. I tested the PR you just posted and the 'end' option works beautifully! |
Merged and published as 1.5.3. Thanks! |
Thank you very much! |
Just a thought, but I wonder if it might be more semantically correct for the default value to be I don't feel strongly about it one way or the other, but thought I should bring it up given that my first code example used |
Yeah, good observation. Want to submit that as a PR? I think we just have to change the default and the |
Sure, happy to. Just one question - what should happen if Maybe this could actually be a useful option in some scenarios, especially when there are more than two elements, or as a way to lock dragging after some user interaction, etc. What do you think? |
I'd probably ignore |
Published in v1.5.4. |
Thanks for a great script.
Just wondering if you would consider an option to snap dragging to a defined interval of pixels.
I am using this in conjunction with Ace editor and it would be great to be able to set the
dragInterval
to the same height as the Ace editorlineHeight
setting.I am sure there could be other use cases as well for this functionality.
Thanks!
The text was updated successfully, but these errors were encountered: