Skip to content

Commit ec78ccf

Browse files
committed
Fixed stupid bug in Ctrl-K Command; added catch for internal errors
1 parent e208623 commit ec78ccf

File tree

7 files changed

+834
-166
lines changed

7 files changed

+834
-166
lines changed

pe.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ def scroll_region(self, stop):
104104
def scroll_up(self, scrolling):
105105
self.scrbuf[scrolling:] = self.scrbuf[:-scrolling]
106106
self.scrbuf[:scrolling] = [''] * scrolling
107+
self.cursor(False)
107108
self.goto(0, 0)
108109
self.wr("\x1bM" * scrolling)
109110
def scroll_down(self, scrolling):
110111
self.scrbuf[:-scrolling] = self.scrbuf[scrolling:]
111112
self.scrbuf[-scrolling:] = [''] * scrolling
113+
self.cursor(False)
112114
self.goto(self.height - 1, 0)
113115
self.wr("\x1bD " * scrolling)
114116
def set_screen_parms(self):
@@ -291,8 +293,8 @@ def handle_cursor_keys(self, key):
291293
except:
292294
pass
293295
elif key == 0x01:
294-
self.autoindent = 'y' if self.autoindent != 'y' else 'n'
295-
self.autoindent = 'y' if self.autoindent != 'y' else 'n'
296+
297+
296298
pat = self.line_edit("Case Sensitive Search {}, Autoindent {}, Tab Size {}, Write Tabs {}: ".format(self.case, self.autoindent, self.tab_size, self.write_tabs), "")
297299
try:
298300
res = [i.strip().lower() for i in pat.split(",")]
@@ -320,7 +322,14 @@ def handle_cursor_keys(self, key):
320322
self.top_line = min(self.top_line + 3, self.total_lines - 1)
321323
self.cur_line = max(self.cur_line, self.top_line)
322324
self.scroll_down(3)
325+
elif key == 0x14:
326+
self.cur_line = 0
327+
elif key == 0x02:
328+
self.cur_line = self.total_lines - 1
329+
self.row = self.height - 1
323330
elif key == 0xfffe:
331+
if self.col >= len(self.content[self.cur_line]):
332+
return True
324333
opening = "([{<"
325334
closing = ")]}>"
326335
level = 0
@@ -360,11 +369,6 @@ def handle_cursor_keys(self, key):
360369
level += 1
361370
if i > 0:
362371
pos = len(self.content[i - 1]) - 1
363-
elif key == 0x14:
364-
self.cur_line = 0
365-
elif key == 0x02:
366-
self.cur_line = self.total_lines - 1
367-
self.row = self.height - 1
368372
elif key == 0x0c:
369373
self.mark = self.cur_line if self.mark == None else None
370374
else:
@@ -573,25 +577,28 @@ def edit_loop(self):
573577
self.display_window()
574578
key = self.get_input()
575579
self.message = ''
576-
if key == 0x11:
577-
if self.changed != ' ':
578-
res = self.line_edit("Content changed! Quit without saving (y/N)? ", "N")
579-
if not res or res[0].upper() != 'Y':
580-
continue
581-
self.mouse_reporting(False)
582-
self.scroll_region(0)
583-
self.goto(self.height, 0)
584-
self.clear_to_eol()
585-
return None
586-
elif key == 0x05:
587-
self.set_screen_parms()
588-
self.row = min(self.height - 1, self.row)
589-
if sys.implementation.name == "micropython":
590-
gc.collect()
591-
self.message = "{} Bytes Memory available".format(gc.mem_free())
592-
elif self.handle_cursor_keys(key):
593-
pass
594-
else: self.handle_edit_key(key)
580+
try:
581+
if key == 0x11:
582+
if self.changed != ' ':
583+
res = self.line_edit("Content changed! Quit without saving (y/N)? ", "N")
584+
if not res or res[0].upper() != 'Y':
585+
continue
586+
self.mouse_reporting(False)
587+
self.scroll_region(0)
588+
self.goto(self.height, 0)
589+
self.clear_to_eol()
590+
return None
591+
elif key == 0x05:
592+
self.set_screen_parms()
593+
self.row = min(self.height - 1, self.row)
594+
if sys.implementation.name == "micropython":
595+
gc.collect()
596+
self.message = "{} Bytes Memory available".format(gc.mem_free())
597+
elif self.handle_cursor_keys(key):
598+
pass
599+
else: self.handle_edit_key(key)
600+
except Exception as err:
601+
self.message = "Internal error: {}".format(err)
595602
def packtabs(self, s):
596603
from _io import StringIO
597604
sb = StringIO()

0 commit comments

Comments
 (0)