From de9b5dec15d0c8e1f4891d621533a1c42125f045 Mon Sep 17 00:00:00 2001 From: Cyrille Bougot Date: Wed, 5 Jun 2024 09:45:53 +0200 Subject: [PATCH 1/2] Do not erase a modified line when moving in the Python console history --- source/pythonConsole.py | 10 ++++++++++ user_docs/en/changes.md | 1 + 2 files changed, 11 insertions(+) diff --git a/source/pythonConsole.py b/source/pythonConsole.py index 951e50e78ef..f3742368408 100755 --- a/source/pythonConsole.py +++ b/source/pythonConsole.py @@ -313,6 +313,8 @@ def __init__(self, parent): self.inputCtrl.SetFont(font) self.inputCtrl.Bind(wx.EVT_CHAR, self.onInputChar) self.inputCtrl.Bind(wx.EVT_TEXT_PASTE, self.onInputPaste) + self.inputCtrl.Bind(wx.EVT_TEXT, self.onInputTextChange) + self.inputTextModified = False inputSizer.Add(self.inputCtrl, proportion=1, flag=wx.EXPAND) mainSizer.Add(inputSizer, proportion=1, flag=wx.EXPAND) self.SetSizer(mainSizer) @@ -374,6 +376,9 @@ def execute(self): self.outputPositions.append(self.outputCtrl.GetInsertionPoint()) def historyMove(self, movement): + if self.inputTextModified: + self.inputHistoryPos = len(self.inputHistory) - 1 + self.inputHistory[self.inputHistoryPos] = self.inputCtrl.GetValue() newIndex = self.inputHistoryPos + movement if not (0 <= newIndex < len(self.inputHistory)): # No more lines in this direction. @@ -381,6 +386,7 @@ def historyMove(self, movement): self.inputHistoryPos = newIndex self.inputCtrl.ChangeValue(self.inputHistory[newIndex]) self.inputCtrl.SetInsertionPointEnd() + self.inputTextModified = False return True RE_COMPLETE_UNIT = re.compile(r"[\w.]*$") @@ -516,6 +522,10 @@ def onInputPaste(self, evt): self.inputCtrl.ChangeValue(suffix) break + def onInputTextChange(self, evt): + self.inputTextModified = True + evt.Skip() + def onOutputKeyDown(self, evt): key = evt.GetKeyCode() # #3763: WX 3 no longer passes escape to evt_char for richEdit fields, therefore evt_key_down is used. diff --git a/user_docs/en/changes.md b/user_docs/en/changes.md index d13c77ea4c7..4e825cd9725 100644 --- a/user_docs/en/changes.md +++ b/user_docs/en/changes.md @@ -28,6 +28,7 @@ Unicode CLDR has been updated. * The fallback braille input table is now equal to the fallback output table, which is Unified English Braille Code grade 1. (#9863, @JulienCochuyt, @LeonarddeR) * NVDA will now report figures with no accessible children, but with a label or description. (#14514) * When reading by line in browse mode, "caption" is no longer reported on each line of a long figure or table caption. (#14874) +* In the Python console, the last unexecuted command will no longer be lost when moving in the input history. (#16653, @CyrilleB79) ### Bug Fixes * Windows 11 fixes: From f7ac65a7676ed2e5c09ed07b77f56e31fc9087d6 Mon Sep 17 00:00:00 2001 From: Sean Budd Date: Thu, 6 Jun 2024 11:09:15 +1000 Subject: [PATCH 2/2] Update source/pythonConsole.py --- source/pythonConsole.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/pythonConsole.py b/source/pythonConsole.py index f3742368408..7cb76ae1ddc 100755 --- a/source/pythonConsole.py +++ b/source/pythonConsole.py @@ -522,7 +522,7 @@ def onInputPaste(self, evt): self.inputCtrl.ChangeValue(suffix) break - def onInputTextChange(self, evt): + def onInputTextChange(self, evt: wx.CommandEvent): self.inputTextModified = True evt.Skip()