zed icon indicating copy to clipboard operation
zed copied to clipboard

Fix lag while hovering a tab over the gutter

Open phisch opened this issue 1 year ago • 2 comments

This is extracted from #10643.

It looks like the editor had a small optimization to drop events when hovering the gutter. This also happens while dragging a tab over the gutter, and causes some stuttering. Please correct me if this wasn't just a small optimization, but I could not derive a different reason for this code to exist.

Release Notes:

  • Fixed issue where dragging a tab over the gutter would cause it to stutter

phisch avatar Apr 18 '24 17:04 phisch

@maxdeviant The blame does lead to the commit that renamed editor2 to editor though: https://github.com/zed-industries/zed/commit/588976d27a22bb36a5aac7e762b21e180a66a2f9#diff-2c4beb0f3febb4181a2f3bcf1d1008cd789d2f072b34b57c3de3249d88ffe48fL485-R580

Edit: link doesn't work, here is a screenshot image

phisch avatar Apr 18 '24 17:04 phisch

@maxdeviant The blame does lead to the commit that renamed editor2 to editor though: 588976d#diff-2c4beb0f3febb4181a2f3bcf1d1008cd789d2f072b34b57c3de3249d88ffe48fL485-R580

Edit: link doesn't work, here is a screenshot image

That is merely a symptom of the fact that editor was replaced by editor2, and the files were similar enough that the changes were detected as a merge rather than a rename.

If you look at the commit on main prior to that point, you can see that stanza already existed in editor2: https://github.com/zed-industries/zed/blob/55175982b61bdd780eba6f68f2c973111462e59c/crates/editor2/src/element.rs#L577-L579

And the actual logic for stopping propagation predates that, as shown by this refactor: https://github.com/zed-industries/zed/commit/9b0bea32edd98588a90655a11372842b62a95f8e#diff-19c01d84512097b519a9de4b46c003b310f4dfa006e46e754060a137b6ad1467L569-R571

So it's a bit of a deep rabbithole.

maxdeviant avatar Apr 18 '24 17:04 maxdeviant

Yeah I am not sure why we have that stop_propagation there. I don't think we did it for performance reasons, maybe it was just a way of signaling that the gutter handled the event, but I don't recall why we did it.

In general, it always seems bad that stopping propagation anywhere could cause the dragged item to be perceived as laggy by the user because we're missing a redraw. Thus, I wonder if it'd be better to change this code path instead:

https://github.com/zed-industries/zed/blob/222034cacf96fb20af658e23ef104070bd620409/crates/gpui/src/window.rs#L1302-L1313

Basically we would need to remove the self.app.propagate_event part condition and always refresh / clear the drag respectively when we observe a mouse move or a mouse up and the drag is active.

@phisch what do you think about opening a pull request with this change? I think that would be a more robust fix for this kind of lag long-term.

as-cii avatar Apr 19 '24 08:04 as-cii

Thanks for looking into this @as-cii. That's certainly a better approach, and I didn't look at it from that side. I'll just transform this PR to represent that change instead, since it's a very small one.

phisch avatar Apr 19 '24 11:04 phisch

Updated the PR. This solution works just as well, if not better, since it would cover any potential future issues as well.

phisch avatar Apr 19 '24 11:04 phisch

Great work! 🔥

as-cii avatar Apr 19 '24 11:04 as-cii