Visitar URL original
Redo by allgo27 · Pull Request #812 · bpython/bpython · GitHub
Skip to content
Merged

Redo #812

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
Prev Previous commit
Next Next commit
Fixed redo; added redone lines to history
  • Loading branch information
allgo27 committed Jun 24, 2020
commit 6a929a63e00f0333dfe3b27780c6b4f8004a2401
8 changes: 4 additions & 4 deletions bpython/curtsiesfrontend/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,9 @@ def process_key_event(self, e):
self.prompt_undo()
elif e in ["<Ctrl-g>"]: # for redo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this seems like a safe choice, bpython doesn't seem to use Ctrl-g for anything and don't know if you checked something like https://en.wikipedia.org/wiki/GNU_Readline but it doesn't sound like something people are clamoring for. It would be nice to make it configurable like self.config.undo_key.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it'd be nice to

  • follow the pattern of other keys of calling a method to keep this switch-like if/elif/elif/... structure shorter
  • also for symmetry, use a tuple here instead of a list

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to follow the pattern of the other keys here, calling a method in the body of the if.

if (self.could_be_redone):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we chose this together but I don't like it anymore, it sounds to me like a boolean. How about redo_stack?

self.push(self.could_be_redone.pop())
open("testFile.txt", "a").write(str(self.history) + "\n")
temp = self.could_be_redone.pop()
self.push(temp)
self.history.append(temp)
else:
self.status_bar.message("Nothing to redo.")
elif e in key_dispatch[self.config.save_key]: # ctrl-s for save
Expand Down Expand Up @@ -1160,7 +1161,6 @@ def push(self, line, insert_into_history=True):

if insert_into_history:
self.insert_into_history(line)
#self.history.append(line)
self.buffer.append(line)

code_to_run = "\n".join(self.buffer)
Expand Down Expand Up @@ -1822,7 +1822,7 @@ def prompt_for_undo():
greenlet.greenlet(prompt_for_undo).switch()

def reevaluate(self, insert_into_history=False):
"""bpython.Repl.undo calls this"""
"""bpython.Repl.undo calls this"""
if self.watcher:
self.watcher.reset()
old_logical_lines = self.history
Expand Down