Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into sage.all-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanDunfield committed Oct 31, 2024
2 parents 2462dfb + 5ed6b0f commit 402e292
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/sage_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
fail-fast: false
version: [9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 10.1, 10.2, 10.3, latest]

container:
Expand Down
39 changes: 21 additions & 18 deletions python/tkterminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,32 +351,35 @@ def handle_keyrelease(self, event):
self.text.tag_add('history', 'output_end', Tk_.INSERT)

def handle_return(self, event=None):
# If the input consists of one complete line of code we run it,
# regardless of where the insert cursor is located. Otherwise we only
# run the code if the cursor is at the end of the input
self.clear_completions()
if self.running_code:
return 'break'
cursor = int(self.text.index(Tk_.INSERT).split('.')[0])
last = int(self.text.index(Tk_.END).split('.')[0])
first = int(self.text.index('output_end').split('.')[0])
if cursor == first == last - 1: # single line input
self.text.mark_set(Tk_.INSERT, Tk_.END)
self.text.insert(Tk_.INSERT, '\n')
if not self.running_code:
cell = self.text.get('output_end', Tk_.INSERT)
self.process_return(cell)
return 'break'

def handle_shift_return(self, event):
self.text.mark_set(Tk_.INSERT, Tk_.END)
return self.handle_return()

def process_return(self, cell):
line, pos = map(int, self.text.index(Tk_.INSERT).split('.'))
last_line = int(self.text.index(Tk_.END).split('.')[0])
if line == last_line - 1:
try:
self.interact_handle_input(cell)
except KeyboardInterrupt:
self.write('(IP) Keyboard Interrupt: ')
self.reset()
cell = self.text.get('output_end', Tk_.INSERT)
try:
self.interact_handle_input(cell)
except KeyboardInterrupt:
self.write('(IP) Keyboard Interrupt: ')
self.reset()
self.hist_pointer = 0
self.hist_stem = ''
self.interact_prompt()
self.text.see(Tk_.INSERT)
if self.IP.more:
self.text.insert(Tk_.INSERT, ' '*self._current_indent, ())
return 'break'

def handle_shift_return(self, event):
self.text.mark_set(Tk_.INSERT, Tk_.END)
return self.handle_return()

def jump_up(self, event):
return self.handle_up(event, jump=True)
Expand Down

0 comments on commit 402e292

Please sign in to comment.