Skip to content

Commit 167f926

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 8aeeeae + 8d73b05 commit 167f926

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

editor.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "strvec.h"
1212
#include "run-command.h"
1313
#include "sigchain.h"
14+
#include "compat/terminal.h"
1415

1516
#ifndef DEFAULT_EDITOR
1617
#define DEFAULT_EDITOR "vi"
@@ -62,6 +63,7 @@ static int launch_specified_editor(const char *editor, const char *path,
6263
return error("Terminal is dumb, but EDITOR unset");
6364

6465
if (strcmp(editor, ":")) {
66+
int save_and_restore_term = !strcmp(editor, "vi") || !strcmp(editor, "vim");
6567
struct strbuf realpath = STRBUF_INIT;
6668
struct child_process p = CHILD_PROCESS_INIT;
6769
int ret, sig;
@@ -90,14 +92,20 @@ static int launch_specified_editor(const char *editor, const char *path,
9092
strvec_pushv(&p.env, (const char **)env);
9193
p.use_shell = 1;
9294
p.trace2_child_class = "editor";
95+
if (save_and_restore_term)
96+
save_and_restore_term = !save_term(1);
9397
if (start_command(&p) < 0) {
98+
if (save_and_restore_term)
99+
restore_term();
94100
strbuf_release(&realpath);
95101
return error("unable to start editor '%s'", editor);
96102
}
97103

98104
sigchain_push(SIGINT, SIG_IGN);
99105
sigchain_push(SIGQUIT, SIG_IGN);
100106
ret = finish_command(&p);
107+
if (save_and_restore_term)
108+
restore_term();
101109
strbuf_release(&realpath);
102110
sig = ret - 128;
103111
sigchain_pop(SIGINT);

0 commit comments

Comments
 (0)