Skip to content

Commit 29dcf7d

Browse files
committed
Merge branch 'un-revert-editor-save-and-reset'
A fix for calling `vim` in Windows Terminal caused a regression and was reverted. We partially un-revert this, to get the fix again. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 6318444 + eb128f7 commit 29dcf7d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

editor.c

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "strvec.h"
55
#include "run-command.h"
66
#include "sigchain.h"
7+
#include "compat/terminal.h"
78

89
#ifndef DEFAULT_EDITOR
910
#define DEFAULT_EDITOR "vi"
@@ -55,6 +56,7 @@ static int launch_specified_editor(const char *editor, const char *path,
5556
return error("Terminal is dumb, but EDITOR unset");
5657

5758
if (strcmp(editor, ":")) {
59+
int save_and_restore_term = !strcmp(editor, "vi") || !strcmp(editor, "vim");
5860
struct strbuf realpath = STRBUF_INIT;
5961
struct child_process p = CHILD_PROCESS_INIT;
6062
int ret, sig;
@@ -83,14 +85,20 @@ static int launch_specified_editor(const char *editor, const char *path,
8385
strvec_pushv(&p.env_array, (const char **)env);
8486
p.use_shell = 1;
8587
p.trace2_child_class = "editor";
88+
if (save_and_restore_term)
89+
save_and_restore_term = !save_term(1);
8690
if (start_command(&p) < 0) {
91+
if (save_and_restore_term)
92+
restore_term();
8793
strbuf_release(&realpath);
8894
return error("unable to start editor '%s'", editor);
8995
}
9096

9197
sigchain_push(SIGINT, SIG_IGN);
9298
sigchain_push(SIGQUIT, SIG_IGN);
9399
ret = finish_command(&p);
100+
if (save_and_restore_term)
101+
restore_term();
94102
strbuf_release(&realpath);
95103
sig = ret - 128;
96104
sigchain_pop(SIGINT);

0 commit comments

Comments
 (0)