File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
src/client/terminals/codeExecution Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 88import textwrap
99from typing import Iterable
1010
11+ attach_bracket_paste = sys .version_info >= (3 , 13 )
1112
1213def split_lines (source ):
1314 """
@@ -279,14 +280,14 @@ def get_next_block_lineno(which_line_next):
279280 normalized = result ["normalized_smart_result" ]
280281 which_line_next = result ["which_line_next" ]
281282 if normalized == "deprecated" :
282- data = json .dumps ({"normalized" : normalized })
283+ data = json .dumps ({"normalized" : normalized , "attach_bracket_paste" : attach_bracket_paste })
283284 else :
284285 data = json .dumps (
285- {"normalized" : normalized , "nextBlockLineno" : result ["which_line_next" ]}
286+ {"normalized" : normalized , "nextBlockLineno" : result ["which_line_next" ], "attach_bracket_paste" : attach_bracket_paste }
286287 )
287288 else :
288289 normalized = normalize_lines (contents ["code" ])
289- data = json .dumps ({"normalized" : normalized })
290+ data = json .dumps ({"normalized" : normalized , "attach_bracket_paste" : attach_bracket_paste })
290291
291292 stdout = sys .stdout if sys .version_info < (3 ,) else sys .stdout .buffer
292293 stdout .write (data .encode ("utf-8" ))
Original file line number Diff line number Diff line change @@ -118,6 +118,16 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
118118 const lineOffset = object . nextBlockLineno - activeEditor ! . selection . start . line - 1 ;
119119 await this . moveToNextBlock ( lineOffset , activeEditor ) ;
120120 }
121+ // For new _pyrepl for Python3.13 and above, we need to send code via bracketed paste mode.
122+ if ( object . attach_bracket_paste ) {
123+ // return `\u001b[200~${object.normalized.trim()}\u001b[201~`;
124+ let trimmedNormalized = object . normalized . replace ( / \n $ / , '' ) ;
125+ if ( trimmedNormalized . endsWith ( ':\n' ) ) {
126+ // In case where statement is unfinished via :, truncate so auto-indentation lands nicely.
127+ trimmedNormalized = trimmedNormalized . replace ( / \n $ / , '' ) ;
128+ }
129+ return `\u001b[200~${ trimmedNormalized } \u001b[201~` ;
130+ }
121131
122132 return parse ( object . normalized ) ;
123133 } catch ( ex ) {
You can’t perform that action at this time.
0 commit comments