Skip to content

Commit

Permalink
fix broken prev normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Aug 20, 2023
1 parent d4c2504 commit 3734312
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pythonFiles/normalizeSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/client/terminals/codeExecution/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions src/test/terminals/codeExecution/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ suite('Terminal - Code Execution Helper', () => {
return ({} as unknown) as ObservableExecutionResult<string>;
});

await helper.normalizeLines('print("hello")');
await helper.normalizeLines('print("hello")', 'print("hello")');

expect(execArgs).to.contain('normalizeSelection.py');
});
Expand All @@ -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);
}
Expand Down

0 comments on commit 3734312

Please sign in to comment.