Skip to content
Merged

Redo #812

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
Prev Previous commit
Next Next commit
Updated redo with Tom's suggestions: made redo configurable and impro…
…ved formatting
  • Loading branch information
allgo27 committed Jun 25, 2020
commit a8f5789323ef34b26db39d330ecca11a9b306fd2
2 changes: 2 additions & 0 deletions bpython/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def loadini(struct, configfile):
"last_output": "F9",
"left": "C-b",
"pastebin": "F8",
"redo": "C-g",
"reimport": "F6",
"reverse_incremental_search": "M-r",
"right": "C-f",
Expand Down Expand Up @@ -193,6 +194,7 @@ def get_key_no_doublebind(command):
struct.suspend_key = get_key_no_doublebind("suspend")
struct.toggle_file_watch_key = get_key_no_doublebind("toggle_file_watch")
struct.undo_key = get_key_no_doublebind("undo")
struct.redo_key = get_key_no_doublebind("redo")
struct.reimport_key = get_key_no_doublebind("reimport")
struct.reverse_incremental_search_key = get_key_no_doublebind(
"reverse_incremental_search"
Expand Down
29 changes: 16 additions & 13 deletions bpython/curtsiesfrontend/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,8 @@ def process_key_event(self, e):
self.on_tab(back=True)
elif e in key_dispatch[self.config.undo_key]: # ctrl-r for undo
self.prompt_undo()
elif e in ["<Ctrl-g>"]: # for redo
if (self.could_be_redone):
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.redo_key]: # ctrl-g for redo
self.prompt_redo()
elif e in key_dispatch[self.config.save_key]: # ctrl-s for save
greenlet.greenlet(self.write2file).switch()
elif e in key_dispatch[self.config.pastebin_key]: # F8 for pastebin
Expand Down Expand Up @@ -865,17 +860,17 @@ def readline_kill(self, e):
else:
self.cut_buffer = cut

def on_enter(self, insert_into_history=True, reset_rl_history=True):
def on_enter(self, new_code=True, reset_rl_history=True):
# so the cursor isn't touching a paren TODO: necessary?
if insert_into_history:
self.could_be_redone = []
if new_code:
self.redo_stack = []

self._set_cursor_offset(-1, update_completion=False)
if reset_rl_history:
self.rl_history.reset()

self.history.append(self.current_line)
self.push(self.current_line, insert_into_history=insert_into_history)
self.push(self.current_line, insert_into_history=new_code)

def on_tab(self, back=False):
"""Do something on tab key
Expand Down Expand Up @@ -1821,7 +1816,15 @@ def prompt_for_undo():

greenlet.greenlet(prompt_for_undo).switch()

def reevaluate(self, insert_into_history=False):
def prompt_redo(self):
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 think just redo, "prompt_undo" is because it may prompt you for how many lines you want to undo.

if (self.redo_stack):
temp = self.redo_stack.pop()
self.push(temp)
self.history.append(temp)
else:
self.status_bar.message("Nothing to redo.")

def reevaluate(self, new_code=False):
"""bpython.Repl.undo calls this"""
if self.watcher:
self.watcher.reset()
Expand All @@ -1845,7 +1848,7 @@ def reevaluate(self, insert_into_history=False):
sys.stdin = ReevaluateFakeStdin(self.stdin, self)
for line in old_logical_lines:
self._current_line = line
self.on_enter(insert_into_history=insert_into_history)
self.on_enter(new_code=new_code)
while self.fake_refresh_requested:
self.fake_refresh_requested = False
self.process_event(bpythonevents.RefreshRequestEvent())
Expand Down
10 changes: 5 additions & 5 deletions bpython/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ def __init__(self, interp, config):
duplicates=config.hist_duplicates, hist_size=config.hist_length
)
self.s_hist = []
self.history = [] # History of commands
self.could_be_redone = []
self.history = [] # commands executed since beginning of session
self.redo_stack = []
self.evaluating = False
self.matches_iter = MatchesIterator()
self.funcprops = None
Expand Down Expand Up @@ -1011,9 +1011,9 @@ def undo(self, n=1):
entries = list(self.rl_history.entries)

#Most recently undone command
lastEntry = self.history[-n:]
lastEntry.reverse()
self.could_be_redone += lastEntry
last_entries = self.history[-n:]
last_entries.reverse()
self.redo_stack += last_entries
self.history = self.history[:-n]
self.reevaluate()

Expand Down