Skip to content

Commit d7953de

Browse files
committed
dont ask twice
1 parent bacd90a commit d7953de

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed

chadtree/transitions/cut_copy.py

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ async def _operation(
5858
s: d for s, d in pre_operations.items() if await exists(d, follow=False)
5959
}
6060

61+
asked = False
6162
new_operations: MutableMapping[PurePath, PurePath] = {}
6263
while pre_existing:
6364
source, dest = pre_existing.popitem()
6465
resp = await Nvim.input(question=LANG("path_exists_err"), default=dest.name)
6566
new_dest = dest.parent / resp if resp else None
67+
asked = True
6668

6769
if not new_dest:
6870
pre_existing[source] = dest
@@ -92,49 +94,50 @@ async def _operation(
9294
for s, d in sorted(operations.items(), key=lambda t: pathsort_key(t[0]))
9395
)
9496

95-
question = LANG("confirm op", operation=op_name, paths=msg)
96-
ans = await Nvim.confirm(
97-
question=question,
98-
answers=LANG("ask_yesno"),
99-
answer_key={1: True, 2: False},
100-
)
97+
if not asked:
98+
question = LANG("confirm op", operation=op_name, paths=msg)
99+
ans = await Nvim.confirm(
100+
question=question,
101+
answers=LANG("ask_yesno"),
102+
answer_key={1: True, 2: False},
103+
)
104+
105+
if not ans:
106+
return None
101107

102-
if not ans:
103-
return None
108+
try:
109+
await action(operations)
110+
except Exception as e:
111+
await Nvim.write(e, error=True)
112+
return await refresh(state)
104113
else:
105-
try:
106-
await action(operations)
107-
except Exception as e:
108-
await Nvim.write(e, error=True)
109-
return await refresh(state)
110-
else:
111-
parents = {
112-
p.parent for p in chain(operations.keys(), operations.values())
113-
}
114-
invalidate_dirs = parents
115-
index = state.index | parents
116-
new_selection = {*operations.values()}
117-
new_state = await forward(
118-
state,
119-
index=index,
120-
selection=new_selection if is_move else selection,
121-
invalidate_dirs=invalidate_dirs,
122-
)
123-
focus = next(
124-
iter(sorted(new_selection, key=pathsort_key)),
125-
None,
126-
)
114+
parents = {
115+
p.parent for p in chain(operations.keys(), operations.values())
116+
}
117+
invalidate_dirs = parents
118+
index = state.index | parents
119+
new_selection = {*operations.values()}
120+
new_state = await forward(
121+
state,
122+
index=index,
123+
selection=new_selection if is_move else selection,
124+
invalidate_dirs=invalidate_dirs,
125+
)
126+
focus = next(
127+
iter(sorted(new_selection, key=pathsort_key)),
128+
None,
129+
)
127130

128-
if is_move:
129-
await kill_buffers(
130-
last_used=new_state.window_order,
131-
paths=selection,
132-
reopen={},
133-
)
134-
await lsp_moved(operations)
135-
else:
136-
await lsp_created(new_selection)
137-
return Stage(new_state, focus=focus)
131+
if is_move:
132+
await kill_buffers(
133+
last_used=new_state.window_order,
134+
paths=selection,
135+
reopen={},
136+
)
137+
await lsp_moved(operations)
138+
else:
139+
await lsp_created(new_selection)
140+
return Stage(new_state, focus=focus)
138141

139142

140143
@rpc(blocking=False)

0 commit comments

Comments
 (0)