From 373431291dc514054b34b3b7fba475bc0ca40f62 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Sun, 20 Aug 2023 01:45:16 -0700 Subject: [PATCH] fix broken prev normalization --- pythonFiles/normalizeSelection.py | 4 +++- src/client/terminals/codeExecution/helper.ts | 7 +++++-- src/test/terminals/codeExecution/helper.test.ts | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index 48e94f32514c0..b2cca1609aa34 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -246,13 +246,15 @@ def get_next_block_lineno(): # Send the normalized code back to the extension in a JSON object. data = None + which_line_next = 0 # Depending on whether there was a explicit highlight, send smart selection or regular normalization. if contents['emptyHighlight'] is True: normalized = traverse_file(contents["wholeFileContent"], vscode_start_line, vscode_end_line, not empty_Highlight) + which_line_next = get_next_block_lineno() # Only figure out next block line number for smart shift+enter else: normalized = normalize_lines(contents["code"]) # next_block_lineno - which_line_next = get_next_block_lineno() + # which_line_next = get_next_block_lineno() data = json.dumps({"normalized": normalized, "nextBlockLineno": which_line_next}) # data = json.dumps({"normalized": normalized}) # This is how it used to be # data = json.dumps({"normalized": temp}) # 8/16/23 save diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index c15d9eccf352f..5ea8b6ff78115 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -83,8 +83,11 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { // this.smartMoveCursor(object.nextBlockIndex); // commands.executeCommand('cursorMove', { to: 'down'}); // calculate and return offset - const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line; - commands.executeCommand('cursorMove', { to: 'down', by: 'line', value: Number(lineOffset) }); + // Smart cursor move only for smart shift+enter + if (activeEditor!.selection.isEmpty) { + const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line; + commands.executeCommand('cursorMove', { to: 'down', by: 'line', value: Number(lineOffset) }); + } return parse(object.normalized); } catch (ex) { traceError(ex, 'Python: Failed to normalize code for execution in terminal'); diff --git a/src/test/terminals/codeExecution/helper.test.ts b/src/test/terminals/codeExecution/helper.test.ts index ac47037a2344f..5de4e276f38d1 100644 --- a/src/test/terminals/codeExecution/helper.test.ts +++ b/src/test/terminals/codeExecution/helper.test.ts @@ -112,7 +112,7 @@ suite('Terminal - Code Execution Helper', () => { return ({} as unknown) as ObservableExecutionResult; }); - await helper.normalizeLines('print("hello")'); + await helper.normalizeLines('print("hello")', 'print("hello")'); expect(execArgs).to.contain('normalizeSelection.py'); }); @@ -124,7 +124,7 @@ suite('Terminal - Code Execution Helper', () => { .returns((file, args, options) => actualProcessService.execObservable.apply(actualProcessService, [file, args, options]), ); - const normalizedCode = await helper.normalizeLines(source); + const normalizedCode = await helper.normalizeLines(source, source); const normalizedExpected = expectedSource.replace(/\r\n/g, '\n'); expect(normalizedCode).to.be.equal(normalizedExpected); }