Skip to content

Commit c52af89

Browse files
make hx --hsplit f1 f2 stay focused on the first file split, instead of the last
1 parent 3beb268 commit c52af89

4 files changed

Lines changed: 84 additions & 16 deletions

File tree

LOG

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2026-04-28T21:41:25.032 helix_term::application [WARN] file: "/home/brownbread/forge/forks/helix/a.txt"
2+
2026-04-28T21:41:25.038 helix_view::editor [WARN] action: VerticalSplit
3+
2026-04-28T21:41:25.038 helix_view::tree [WARN] tree: SlotMap {
4+
slots: [
5+
Slot {
6+
version: 0,
7+
next_free: 0,
8+
},
9+
Slot {
10+
version: 1,
11+
value: Node {
12+
parent: ViewId(
13+
1v1,
14+
),
15+
content: Container(
16+
Container {
17+
layout: Vertical,
18+
children: [
19+
ViewId(
20+
2v1,
21+
),
22+
],
23+
area: Rect {
24+
x: 0,
25+
y: 0,
26+
width: 0,
27+
height: 0,
28+
},
29+
},
30+
),
31+
},
32+
},
33+
Slot {
34+
version: 1,
35+
value: Node {
36+
parent: ViewId(
37+
1v1,
38+
),
39+
content: View(
40+
View {
41+
id: ViewId(
42+
2v1,
43+
),
44+
area: Rect {
45+
x: 0,
46+
y: 0,
47+
width: 0,
48+
height: 0,
49+
},
50+
doc: DocumentId(
51+
1,
52+
),
53+
},
54+
),
55+
},
56+
},
57+
],
58+
free_head: 3,
59+
num_elems: 2,
60+
_k: PhantomData<fn(helix_view::ViewId) -> helix_view::ViewId>,
61+
}
62+
2026-04-28T21:41:25.038 helix_term::application [WARN] ------------------------
63+
64+
2026-04-28T21:41:25.038 helix_term::application [WARN] file: "/home/brownbread/forge/forks/helix/b.txt"
65+
2026-04-28T21:41:25.041 helix_view::editor [WARN] action: Load
66+
2026-04-28T21:41:25.041 helix_term::application [WARN] ------------------------
67+

helix-term/src/application.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ impl Application {
184184
None => Action::Load,
185185
};
186186
let old_id = editor.document_id_by_path(&file);
187+
log::warn!("file: {:?}", file);
187188
let doc_id = match editor.open(&file, action) {
188189
// Ignore irregular files during application init.
189190
Err(DocumentOpenError::IrregularFile) => {
@@ -211,6 +212,7 @@ impl Application {
211212
})
212213
.collect();
213214
doc.set_selection(view_id, selection);
215+
log::warn!("------------------------\n");
214216
}
215217
}
216218

helix-view/src/editor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,7 @@ impl Editor {
17691769
return;
17701770
}
17711771

1772+
log::warn!("action: {:?}", action);
17721773
if !matches!(action, Action::Load) {
17731774
self.enter_normal_mode();
17741775
}

helix-view/src/tree.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,24 +175,16 @@ impl Tree {
175175
split.parent = parent;
176176
let split = self.nodes.insert(split);
177177

178-
let container = match &mut self.nodes[split] {
179-
Node {
180-
content: Content::Container(container),
181-
..
182-
} => container,
183-
_ => unreachable!(),
184-
};
178+
let Node { content: Content::Container(container), .. } = &mut self.nodes[split]
179+
else { unreachable!(); };
180+
185181
container.children.push(focus);
186182
container.children.push(node);
187183
self.nodes[focus].parent = split;
188184
self.nodes[node].parent = split;
189185

190-
let container = match &mut self.nodes[parent] {
191-
Node {
192-
content: Content::Container(container),
193-
..
194-
} => container,
195-
_ => unreachable!(),
186+
let Node { content: Content::Container(container), .. } = &mut self.nodes[parent] else {
187+
unreachable!();
196188
};
197189

198190
let pos = container
@@ -204,9 +196,15 @@ impl Tree {
204196
// replace focus on parent with split
205197
container.children[pos] = split;
206198
}
207-
208-
// focus the new node
209-
self.focus = node;
199+
log::warn!("tree: {:#?}", self.nodes);
200+
201+
if self.nodes.iter().filter(|(_, node)| match node {
202+
Node { content: Content::View(_), .. } => true,
203+
_ => false,
204+
}).count() == 1 {
205+
// focus the new node
206+
self.focus = node;
207+
}
210208

211209
// recalculate all the sizes
212210
self.recalculate();

0 commit comments

Comments
 (0)