Skip to content

Commit

Permalink
dont ask twice
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-jpq committed Oct 30, 2024
1 parent bacd90a commit d7953de
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions chadtree/transitions/cut_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ async def _operation(
s: d for s, d in pre_operations.items() if await exists(d, follow=False)
}

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

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

question = LANG("confirm op", operation=op_name, paths=msg)
ans = await Nvim.confirm(
question=question,
answers=LANG("ask_yesno"),
answer_key={1: True, 2: False},
)
if not asked:
question = LANG("confirm op", operation=op_name, paths=msg)
ans = await Nvim.confirm(
question=question,
answers=LANG("ask_yesno"),
answer_key={1: True, 2: False},
)

if not ans:
return None

if not ans:
return None
try:
await action(operations)
except Exception as e:
await Nvim.write(e, error=True)
return await refresh(state)
else:
try:
await action(operations)
except Exception as e:
await Nvim.write(e, error=True)
return await refresh(state)
else:
parents = {
p.parent for p in chain(operations.keys(), operations.values())
}
invalidate_dirs = parents
index = state.index | parents
new_selection = {*operations.values()}
new_state = await forward(
state,
index=index,
selection=new_selection if is_move else selection,
invalidate_dirs=invalidate_dirs,
)
focus = next(
iter(sorted(new_selection, key=pathsort_key)),
None,
)
parents = {
p.parent for p in chain(operations.keys(), operations.values())
}
invalidate_dirs = parents
index = state.index | parents
new_selection = {*operations.values()}
new_state = await forward(
state,
index=index,
selection=new_selection if is_move else selection,
invalidate_dirs=invalidate_dirs,
)
focus = next(
iter(sorted(new_selection, key=pathsort_key)),
None,
)

if is_move:
await kill_buffers(
last_used=new_state.window_order,
paths=selection,
reopen={},
)
await lsp_moved(operations)
else:
await lsp_created(new_selection)
return Stage(new_state, focus=focus)
if is_move:
await kill_buffers(
last_used=new_state.window_order,
paths=selection,
reopen={},
)
await lsp_moved(operations)
else:
await lsp_created(new_selection)
return Stage(new_state, focus=focus)


@rpc(blocking=False)
Expand Down

0 comments on commit d7953de

Please sign in to comment.