Skip to content

Commit ebe26f4

Browse files
dschomjcheetham
authored andcommitted
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 a9f4d51 + 874cf26 commit ebe26f4

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
@@ -12,6 +12,7 @@
1212
#include "run-command.h"
1313
#include "sigchain.h"
1414
#include "wrapper.h"
15+
#include "compat/terminal.h"
1516

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

6566
if (strcmp(editor, ":")) {
67+
int save_and_restore_term = !strcmp(editor, "vi") || !strcmp(editor, "vim");
6668
struct strbuf realpath = STRBUF_INIT;
6769
struct child_process p = CHILD_PROCESS_INIT;
6870
int ret, sig;
@@ -91,14 +93,20 @@ static int launch_specified_editor(const char *editor, const char *path,
9193
strvec_pushv(&p.env, (const char **)env);
9294
p.use_shell = 1;
9395
p.trace2_child_class = "editor";
96+
if (save_and_restore_term)
97+
save_and_restore_term = !save_term(1);
9498
if (start_command(&p) < 0) {
99+
if (save_and_restore_term)
100+
restore_term();
95101
strbuf_release(&realpath);
96102
return error("unable to start editor '%s'", editor);
97103
}
98104

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

0 commit comments

Comments
 (0)