Skip to content

Commit f5df5b6

Browse files
authored
Merge pull request #207 from mochouaaaaa/master
fix(mux): Unable to use its own operations in neovim
2 parents 54cbdb8 + 589005b commit f5df5b6

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

kitty/neighboring_window.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
1+
from kitty.key_encoding import KeyEvent, parse_shortcut
2+
from kittens.tui.handler import result_handler
3+
4+
15
def main():
26
pass
37

48

9+
def encode_key_mapping(window, key_mapping):
10+
mods, key = parse_shortcut(key_mapping)
11+
event = KeyEvent(
12+
mods=mods,
13+
key=key,
14+
shift=bool(mods & 1),
15+
alt=bool(mods & 2),
16+
ctrl=bool(mods & 4),
17+
super=bool(mods & 8),
18+
hyper=bool(mods & 16),
19+
meta=bool(mods & 32),
20+
).as_window_system_event()
21+
22+
return window.encoded_key(event)
23+
24+
25+
@result_handler(no_ui=True)
526
def handle_result(args, result, target_window_id, boss):
6-
boss.active_tab.neighboring_window(args[1])
27+
window = boss.window_id_map.get(target_window_id)
728

29+
keymap = args[2]
830

9-
handle_result.no_ui = True
31+
cmd = window.child.foreground_cmdline[0]
32+
if cmd == 'nvim':
33+
encoded = encode_key_mapping(window, keymap)
34+
window.write_to_child(encoded)
35+
elif cmd == 'tmux':
36+
pass
37+
else:
38+
boss.active_tab.neighboring_window(args[1])

kitty/relative_resize.py

+35-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
11
# Based on MIT licensed code at https://github.com/chancez/dotfiles/blob/badc69d3895a6a942285amount26b8c372a55d77533eamount/kitty/.config/kitty/relative_resize.py
22
from kittens.tui.handler import result_handler
3+
from kitty.key_encoding import KeyEvent, parse_shortcut
4+
5+
6+
def encode_key_mapping(window, key_mapping):
7+
mods, key = parse_shortcut(key_mapping)
8+
event = KeyEvent(
9+
mods=mods,
10+
key=key,
11+
shift=bool(mods & 1),
12+
alt=bool(mods & 2),
13+
ctrl=bool(mods & 4),
14+
super=bool(mods & 8),
15+
hyper=bool(mods & 16),
16+
meta=bool(mods & 32),
17+
).as_window_system_event()
18+
19+
return window.encoded_key(event)
20+
321

422
def main(args):
523
pass
624

25+
726
def relative_resize_window(direction, amount, target_window_id, boss):
827
window = boss.window_id_map.get(target_window_id)
928
if window is None:
1029
return
1130

12-
neighbors = boss.active_tab.current_layout.neighbors_for_window(window, boss.active_tab.windows)
31+
neighbors = boss.active_tab.current_layout.neighbors_for_window(
32+
window, boss.active_tab.windows
33+
)
1334
current_window_id = boss.active_tab.active_window
1435

1536
left_neighbors = neighbors.get('left')
@@ -57,8 +78,20 @@ def relative_resize_window(direction, amount, target_window_id, boss):
5778
elif direction == 'down' and bottom_neighbors:
5879
boss.active_tab.resize_window('taller', amount)
5980

81+
6082
@result_handler(no_ui=True)
6183
def handle_result(args, result, target_window_id, boss):
6284
direction = args[1]
6385
amount = int(args[2])
64-
relative_resize_window(direction, amount, target_window_id, boss)
86+
window = boss.window_id_map.get(target_window_id)
87+
88+
keymap = args[3]
89+
90+
cmd = window.child.foreground_cmdline[0]
91+
if cmd == 'nvim':
92+
encoded = encode_key_mapping(window, keymap)
93+
window.write_to_child(encoded)
94+
elif cmd == 'tmux':
95+
pass
96+
else:
97+
relative_resize_window(direction, amount, target_window_id, boss)

0 commit comments

Comments
 (0)