diff --git a/python_files/normalizeSelection.py b/python_files/normalizeSelection.py index 981251289e57..598ebc654183 100644 --- a/python_files/normalizeSelection.py +++ b/python_files/normalizeSelection.py @@ -8,6 +8,7 @@ import textwrap from typing import Iterable +attach_bracket_paste = sys.version_info >= (3, 13) def split_lines(source): """ @@ -279,14 +280,14 @@ def get_next_block_lineno(which_line_next): normalized = result["normalized_smart_result"] which_line_next = result["which_line_next"] if normalized == "deprecated": - data = json.dumps({"normalized": normalized}) + data = json.dumps({"normalized": normalized, "attach_bracket_paste": attach_bracket_paste}) else: data = json.dumps( - {"normalized": normalized, "nextBlockLineno": result["which_line_next"]} + {"normalized": normalized, "nextBlockLineno": result["which_line_next"], "attach_bracket_paste": attach_bracket_paste} ) else: normalized = normalize_lines(contents["code"]) - data = json.dumps({"normalized": normalized}) + data = json.dumps({"normalized": normalized, "attach_bracket_paste": attach_bracket_paste }) stdout = sys.stdout if sys.version_info < (3,) else sys.stdout.buffer stdout.write(data.encode("utf-8")) diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index ff1c4f218f8d..9c1ca3ab1598 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -118,6 +118,16 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line - 1; await this.moveToNextBlock(lineOffset, activeEditor); } + // For new _pyrepl for Python3.13 and above, we need to send code via bracketed paste mode. + if (object.attach_bracket_paste) { + // return `\u001b[200~${object.normalized.trim()}\u001b[201~`; + let trimmedNormalized = object.normalized.replace(/\n$/, ''); + if (trimmedNormalized.endsWith(':\n')) { + // In case where statement is unfinished via :, truncate so auto-indentation lands nicely. + trimmedNormalized = trimmedNormalized.replace(/\n$/, ''); + } + return `\u001b[200~${trimmedNormalized}\u001b[201~`; + } return parse(object.normalized); } catch (ex) {