-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Workspace move editor actions #21760
Workspace move editor actions #21760
Conversation
Marked as ready for review based on this comment: #20205 (comment) |
|
One counterpoint I can think of, is if you start by creating all the splits the way you like and then proceed to move items around, you may close a pane when you didn't meant to. But otherwise there is no merit to keep it, it looks wrong and there is no way to close it through UI at the moment.
I tried moving an editor to the terminal pane with the mouse and it didn't work (I mean it pasted the file path as, I assume, intended). Now after your comment I realize that moving terminals within the terminal pane should be possible in the same fashion, right... I'll look into it and add it tomorrow. Have you thought about a more unified model to pane splitting and navigation for editors and termianls? |
That reason is good, but seems rather small compared to the inactionable panels?
I have thought about it, and decided that's hard to do given the fact that terminal panel restricts other kinds of items, and differently reacts to files being dropped inside it. zed/crates/terminal_view/src/terminal_panel.rs Lines 1122 to 1135 in 26ba48e
This PR does pretty much the same, but not in a unified way, so I can return the question back. |
Fair enough. Foolish consistency, yada yada... I'll add similar calls to the terminal crate, and adjust the original if needed. Found a bug in 2024-12-10_14-56-11.mp4Error log from the linux machine
Also, question from the issue thread about keybinding: "ctrl-shift-1": ["workspace::MoveItemToPane", 0],
"ctrl-shift-2": ["workspace::MoveItemToPane", 1],
"ctrl-shift-3": ["workspace::MoveItemToPane", 2],
"ctrl-shift-4": ["workspace::MoveItemToPane", 3],
"ctrl-shift-5": ["workspace::MoveItemToPane", 4],
"ctrl-shift-6": ["workspace::MoveItemToPane", 5],
"ctrl-shift-7": ["workspace::MoveItemToPane", 6],
"ctrl-shift-8": ["workspace::MoveItemToPane", 7],
"ctrl-shift-9": ["workspace::MoveItemToPane", 8]
|
For that, it's better to do incremental, potentially smaller updates instead of changing the entire mechanism at once. Later, after allowing to split/move things however we like, one can go and land an approach on top, dealing with all actions that may leave the pane empty — deciding what to do in this case seems like a good task on its own. So the only foolish thing I see here is the appearance of this word in the discussion and, overall, hastiness to slap labels on things.
|
a58bf75
to
0c2340f
Compare
f8d3f2c
to
a9252ae
Compare
Implemented the actions for the terminal panel and cleaned things up a bit. I think, in it's current state, it can pass as an "incremental, potentially smaller update". Intentionally missing:
And, question about hotkeys, @ConradIrwin, please, give us your judgement about #20205 (comment) and, maybe look at the #14817 as well? I'd like to see that implemented, maybe after this PR, I'll try making that happen next. Thanks! |
a9252ae
to
6ed4888
Compare
@Igonato for vim we should use In the current state of things, closing the empty pane is consistent with how Zed does things (and with vim :D), so for getting this shipped, we should close them. If we come back to #14187, I think the two questions to answer are:
|
That's how it's implemeneted right now.
This had me confused for a minute :D
If one to get an inspiration from zellij layouts, then something similar to |
Can any mac user install Sublime and post contents of the |
Sublime keymap
|
6ed4888
to
63a60f9
Compare
Noticed something, when switching ( 2024-12-11_19-42-07.mp4 |
Question: I'd like to add an option to keep the focus in the source pane (as suggested in #14817). What is the best way to add it? Is there an action that has default params I can look at? Would it be better to add as set of separate cations On a related note: what do you think about a set of unparameterized actions that will appear in the command palette for discoverability ( |
Not sure about the lag, one idea might be that a moved element is not redrawing timely (
I think that adding another parameter makes more sense than a setting or separate actions, as people can bind it however they like this way. zed/crates/editor/src/actions.rs Lines 18 to 23 in 937186d
zed/assets/keymaps/default-macos.json Lines 116 to 117 in 937186d
is one example of such definitions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've found a focus solution for you, and might have found a lag fix either.
Let's try that.
crates/workspace/src/pane_group.rs
Outdated
@@ -121,6 +121,35 @@ impl PaneGroup { | |||
}; | |||
} | |||
|
|||
pub fn move_active_item( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code better, it looks like we have
zed/crates/workspace/src/workspace.rs
Lines 6150 to 6180 in 7b7d5dc
pub fn move_item( | |
source: &View<Pane>, | |
destination: &View<Pane>, | |
item_id_to_move: EntityId, | |
destination_index: usize, | |
cx: &mut WindowContext<'_>, | |
) { | |
let Some((item_ix, item_handle)) = source | |
.read(cx) | |
.items() | |
.enumerate() | |
.find(|(_, item_handle)| item_handle.item_id() == item_id_to_move) | |
.map(|(ix, item)| (ix, item.clone())) | |
else { | |
// Tab was closed during drag | |
return; | |
}; | |
if source != destination { | |
// Close item from previous pane | |
source.update(cx, |source, cx| { | |
source.remove_item_and_focus_on_pane(item_ix, false, destination.clone(), cx); | |
}); | |
} | |
// This automatically removes duplicate items in the pane | |
destination.update(cx, |destination, cx| { | |
destination.add_item(item_handle, true, true, Some(destination_index), cx); | |
destination.focus(cx) | |
}); | |
} |
which does almost the same thing but also focuses the right pane?
Let's unity them (by removing this method and moving the existing one here; optionally we can also replace remove_item_and_focus_on_pane
noop wrapper with remove_item
).
I think, that focusing the last pane is important, and might solve the observed lag issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I missed it when I was reading the code. I'll see where and how it is used and merge them into one if it makes sense.
The lag isn't related to the move. It happens on ctrl-tab
too. Something to do with chagning the active tab when the tab has a certain LSP enabled, maybe? I'll try to narrow it down
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have used the workspace one instead of the new one, just moved it into the PaneGroup
(and removed that useless remove_item_and_focus_on_pane
wrapper).
For the lag, I wonder if it already exists on main
before the changes?
If focus-related changes do not improve things and it is on main
already, we can move on and fix that lag separately.
Thank you for the review @SomeoneToIgnore. I'll go over everything later tonight. |
20acc2c
to
0cc4d13
Compare
Added support for optional focus. Example bindings: "ctrl-shift-1": ["workspace::MoveItemToPane", { "destination": 0 }],
"ctrl-shift-2": [
"workspace::MoveItemToPane",
{ "destination": 1, "focus_destination": false }
],
"alt-shift-h": [
"workspace::MoveItemToPaneInDirection",
{ "direction": "Left" }
],
"alt-shift-l": [
"workspace::MoveItemToPaneInDirection",
{ "direction": "Right" }
],
"alt-shift-k": [
"workspace::MoveItemToPaneInDirection",
{ "direction": "Up" }
],
"alt-shift-j": [
"workspace::MoveItemToPaneInDirection",
{ "direction": "Down" }
],
"ctrl-alt-shift-h": [
"workspace::MoveItemToPaneInDirection",
{ "direction": "Left", "focus_destination": false }
],
"ctrl-alt-shift-l": [
"workspace::MoveItemToPaneInDirection",
{ "direction": "Right", "focus_destination": false }
],
"ctrl-alt-shift-k": [
"workspace::MoveItemToPaneInDirection",
{ "direction": "Up", "focus_destination": false }
],
"ctrl-alt-shift-j": [
"workspace::MoveItemToPaneInDirection",
{ "direction": "Down", "focus_destination": false }
], Reviewed The lag is in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a few style nits, but looks good overall, thank you!
Analogous to the Sublime's ctrl+shif+*number* shortcut
Closes zed-industries#20205 An action to move the active editor to a pane in a specified direction
Also add an example of a new settings field usage into the default keymaps.
# Conflicts: # crates/terminal_view/src/terminal_panel.rs
7fad903
to
2bcd893
Compare
Closes zed-industries#20205 Release Notes: - Added `MoveItemToPane` and `MoveItemToPaneInDirection` actions --------- Co-authored-by: Kirill Bulatov <[email protected]>
Closes #20205
Release Notes:
MoveItemToPane
andMoveItemToPaneInDirection
actions