Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add bracketed paste mode for Python3.13 and above
  • Loading branch information
anthonykim1 committed Nov 6, 2024
commit eb51c96e523d7d2a8ff9f9d63cd999db86b68829
7 changes: 4 additions & 3 deletions python_files/normalizeSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import textwrap
from typing import Iterable

attach_bracket_paste = sys.version_info >= (3, 13)

def split_lines(source):
"""
Expand Down Expand Up @@ -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"))
Expand Down
10 changes: 10 additions & 0 deletions src/client/terminals/codeExecution/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down