diff --git a/README.md b/README.md index 2616268..87d05c0 100644 --- a/README.md +++ b/README.md @@ -68,9 +68,10 @@ shows most of the commands.: |Alt-PgUp & Alt-PgDn|Cycle trough bookmarked locations| |Alt-Home & Alt-End|Cycle trough locations with changes, based on the Undo list| |Ctrl-L or Ctrl-Space|Start highlighting at the current position, or clear the highlight. The highlight can then be extended by moving the cursor| -|Ctrl-X|Cut the highlighted text| -|Ctrl-C or Ctrl-D|Copy the highlighted text| +|Ctrl-X|Cut the highlighted text. If the mark is not set, cut the current line.| +|Ctrl-C|Copy the highlighted text. If the mark is not set, copy the current line.| |Ctrl-V|Insert the copied/cut text.| +|Ctrl-D|Copy text from the Undo buffer to the paste buffer.| |Ctrl-Z|Undo the last change(s)| |Ctrl-Y|Redo the last undo(s), repeating what had been undone by undo| |Ctrl-P|Comment/Uncomment a line or highlighted area| @@ -568,8 +569,11 @@ the list of files in the current dir **2.75** Fix an error with character swap. -**2.76** Cycle through places with changes. +**2.76** Cycle through places with changes. -**2.77** Change key binding for bookmark location to Alt-Ins, using Alt-Home and Alt-End to cycle through -locations with changes. +**2.77** Change key binding for bookmark location to Alt-Ins, using Alt-Home and Alt-End +to cycle through locations with changes. +**2.78** Use Ctrl-D to copy text from the UNDO buffer to the Paste buffer. + +**2.79** Cut or copy the current line if no text is highlighted. diff --git a/additional_documentation/Pyboard Editor.doc b/additional_documentation/Pyboard Editor.doc index 4e2ebf5..248dc69 100644 Binary files a/additional_documentation/Pyboard Editor.doc and b/additional_documentation/Pyboard Editor.doc differ diff --git a/pye b/pye index f6e75b7..b606f37 100755 --- a/pye +++ b/pye @@ -4,7 +4,7 @@ ## Small python text editor based on the ## Very simple VT100 terminal text editor widget ## Copyright (c) 2015 Paul Sokolovsky (initial code) -## Copyright (c) 2015-2021 Robert Hammelrath (additional code) +## Copyright (c) 2015-2025 Robert Hammelrath (additional code) ## Distributed under MIT License ## Changes: ## - Ported the code to boards from micropython.org, Pycom Boards, @@ -21,7 +21,7 @@ ## - Added multi-file support ## -PYE_VERSION = " V2.78 " +PYE_VERSION = " V2.79 " try: import usys as sys except: @@ -1118,12 +1118,24 @@ class Editor: self.cur_line, self.col = cur_line, cur_col ## restore pos self.message = "'{}' replaced {} times".format(pat, count) elif key == KEY_CUT: # delete line or line(s) into buffer - if self.mark is not None: - self.delete_mark(True) + if self.mark is None: + if self.cur_line < self.total_lines - 1: + self.mark = (self.cur_line + 1, 0) + else: + self.mark = (self.cur_line, len(l)) + self.col = 0 + self.delete_mark(True) elif key == KEY_COPY: # copy line(s) into buffer - if self.mark is not None: - self.yank_mark() - self.clear_mark() + col = self.col + if self.mark is None: + if self.cur_line < self.total_lines - 1: + self.mark = (self.cur_line + 1, 0) + else: + self.mark = (self.cur_line, len(l)) + self.col = 0 + self.yank_mark() + self.clear_mark() + self.col = col elif key == KEY_PASTE: ## insert buffer if Editor.yank_buffer: self.col = self.vcol @@ -1235,7 +1247,7 @@ class Editor: key = self.handle_edit_keys(key, char) if key == KEY_QUIT: - if self.hash != self.hash_buffer(): + if self.hash != self.hash_buffer() and not self.is_dir: res = self.line_edit("File changed! Quit (y/N/f)? ", "N") if not res or res[0].upper() == "N": continue @@ -1282,8 +1294,8 @@ class Editor: if fname: try: self.fname = fname - if fname in (".", "..") or (os.stat(fname)[0] & 0x4000): ## Dir - os.chdir(fname) + if fname in (".", "..", "") or (os.stat(fname)[0] & 0x4000): ## Dir + os.chdir(fname or ".") self.work_dir = os.getcwd() # let the os module do the normalization self.fname = "/" if self.work_dir == "/" else self.work_dir.split("/")[-1] self.content = ["Directory '{}'".format(self.work_dir), ""] + sorted( @@ -1381,7 +1393,8 @@ def pye_edit(content, tab_size=4, undo=50, io_device=None): break del slot[index] elif key == KEY_GET: - f = slot[index].line_edit("Open file: ", "", Editor.file_char) + dfn = slot[index].content[slot[index].cur_line].strip() if slot[index].is_dir else "" + f = slot[index].line_edit("Open file: ", dfn, Editor.file_char) if f is not None: slot.append(Editor(tab_size, undo, io_device)) index = len(slot) - 1 diff --git a/pye.mpy b/pye.mpy index 3d2d556..0a80aa4 100644 Binary files a/pye.mpy and b/pye.mpy differ diff --git a/pye.py b/pye.py index f330c99..35c3333 100644 --- a/pye.py +++ b/pye.py @@ -1,4 +1,4 @@ -PYE_VERSION = " V2.78 " +PYE_VERSION = " V2.79 " try: import usys as sys except: @@ -1022,12 +1022,24 @@ def handle_edit_keys(self, key, char): self.cur_line, self.col = cur_line, cur_col self.message = "'{}' replaced {} times".format(pat, count) elif key == KEY_CUT: - if self.mark is not None: - self.delete_mark(True) + if self.mark is None: + if self.cur_line < self.total_lines - 1: + self.mark = (self.cur_line + 1, 0) + else: + self.mark = (self.cur_line, len(l)) + self.col = 0 + self.delete_mark(True) elif key == KEY_COPY: - if self.mark is not None: - self.yank_mark() - self.clear_mark() + col = self.col + if self.mark is None: + if self.cur_line < self.total_lines - 1: + self.mark = (self.cur_line + 1, 0) + else: + self.mark = (self.cur_line, len(l)) + self.col = 0 + self.yank_mark() + self.clear_mark() + self.col = col elif key == KEY_PASTE: if Editor.yank_buffer: self.col = self.vcol @@ -1133,7 +1145,7 @@ def edit_loop(self): self.message = "" key = self.handle_edit_keys(key, char) if key == KEY_QUIT: - if self.hash != self.hash_buffer(): + if self.hash != self.hash_buffer() and not self.is_dir: res = self.line_edit("File changed! Quit (y/N/f)? ", "N") if not res or res[0].upper() == "N": continue @@ -1173,8 +1185,8 @@ def get_file(self, fname): if fname: try: self.fname = fname - if fname in (".", "..") or (os.stat(fname)[0] & 0x4000): - os.chdir(fname) + if fname in (".", "..", "") or (os.stat(fname)[0] & 0x4000): + os.chdir(fname or ".") self.work_dir = os.getcwd() self.fname = "/" if self.work_dir == "/" else self.work_dir.split("/")[-1] self.content = ["Directory '{}'".format(self.work_dir), ""] + sorted( @@ -1262,7 +1274,8 @@ def pye_edit(content, tab_size=4, undo=50, io_device=None): break del slot[index] elif key == KEY_GET: - f = slot[index].line_edit("Open file: ", "", Editor.file_char) + dfn = slot[index].content[slot[index].cur_line].strip() if slot[index].is_dir else "" + f = slot[index].line_edit("Open file: ", dfn, Editor.file_char) if f is not None: slot.append(Editor(tab_size, undo, io_device)) index = len(slot) - 1 diff --git a/pye_core.py b/pye_core.py index 097eefa..d54fe01 100644 --- a/pye_core.py +++ b/pye_core.py @@ -2,7 +2,7 @@ ## Small python text editor based on the ## Very simple VT100 terminal text editor widget ## Copyright (c) 2015 Paul Sokolovsky (initial code) -## Copyright (c) 2015-2021 Robert Hammelrath (additional code) +## Copyright (c) 2015-2025 Robert Hammelrath (additional code) ## Distributed under MIT License ## Changes: ## - Ported the code to boards from micropython.org, Pycom Boards, @@ -19,7 +19,7 @@ ## - Added multi-file support ## -PYE_VERSION = " V2.78 " +PYE_VERSION = " V2.79 " try: import usys as sys except: @@ -1116,12 +1116,24 @@ def handle_edit_keys(self, key, char): ## keys which change content self.cur_line, self.col = cur_line, cur_col ## restore pos self.message = "'{}' replaced {} times".format(pat, count) elif key == KEY_CUT: # delete line or line(s) into buffer - if self.mark is not None: - self.delete_mark(True) + if self.mark is None: + if self.cur_line < self.total_lines - 1: + self.mark = (self.cur_line + 1, 0) + else: + self.mark = (self.cur_line, len(l)) + self.col = 0 + self.delete_mark(True) elif key == KEY_COPY: # copy line(s) into buffer - if self.mark is not None: - self.yank_mark() - self.clear_mark() + col = self.col + if self.mark is None: + if self.cur_line < self.total_lines - 1: + self.mark = (self.cur_line + 1, 0) + else: + self.mark = (self.cur_line, len(l)) + self.col = 0 + self.yank_mark() + self.clear_mark() + self.col = col elif key == KEY_PASTE: ## insert buffer if Editor.yank_buffer: self.col = self.vcol @@ -1233,7 +1245,7 @@ def edit_loop(self): ## main editing loop key = self.handle_edit_keys(key, char) if key == KEY_QUIT: - if self.hash != self.hash_buffer(): + if self.hash != self.hash_buffer() and not self.is_dir: res = self.line_edit("File changed! Quit (y/N/f)? ", "N") if not res or res[0].upper() == "N": continue @@ -1280,8 +1292,8 @@ def get_file(self, fname): if fname: try: self.fname = fname - if fname in (".", "..") or (os.stat(fname)[0] & 0x4000): ## Dir - os.chdir(fname) + if fname in (".", "..", "") or (os.stat(fname)[0] & 0x4000): ## Dir + os.chdir(fname or ".") self.work_dir = os.getcwd() # let the os module do the normalization self.fname = "/" if self.work_dir == "/" else self.work_dir.split("/")[-1] self.content = ["Directory '{}'".format(self.work_dir), ""] + sorted( @@ -1379,7 +1391,8 @@ def pye_edit(content, tab_size=4, undo=50, io_device=None): break del slot[index] elif key == KEY_GET: - f = slot[index].line_edit("Open file: ", "", Editor.file_char) + dfn = slot[index].content[slot[index].cur_line].strip() if slot[index].is_dir else "" + f = slot[index].line_edit("Open file: ", dfn, Editor.file_char) if f is not None: slot.append(Editor(tab_size, undo, io_device)) index = len(slot) - 1 diff --git a/pye_win b/pye_win index eddc5f1..3e832d8 100644 --- a/pye_win +++ b/pye_win @@ -2,7 +2,7 @@ ## Small python text editor based on the ## Very simple VT100 terminal text editor widget ## Copyright (c) 2015 Paul Sokolovsky (initial code) -## Copyright (c) 2015-2021 Robert Hammelrath (additional code) +## Copyright (c) 2015-2025 Robert Hammelrath (additional code) ## Distributed under MIT License ## Changes: ## - Ported the code to boards from micropython.org, Pycom Boards, @@ -19,7 +19,7 @@ ## - Added multi-file support ## -PYE_VERSION = " V2.78 " +PYE_VERSION = " V2.79 " try: import usys as sys except: @@ -1116,12 +1116,24 @@ class Editor: self.cur_line, self.col = cur_line, cur_col ## restore pos self.message = "'{}' replaced {} times".format(pat, count) elif key == KEY_CUT: # delete line or line(s) into buffer - if self.mark is not None: - self.delete_mark(True) + if self.mark is None: + if self.cur_line < self.total_lines - 1: + self.mark = (self.cur_line + 1, 0) + else: + self.mark = (self.cur_line, len(l)) + self.col = 0 + self.delete_mark(True) elif key == KEY_COPY: # copy line(s) into buffer - if self.mark is not None: - self.yank_mark() - self.clear_mark() + col = self.col + if self.mark is None: + if self.cur_line < self.total_lines - 1: + self.mark = (self.cur_line + 1, 0) + else: + self.mark = (self.cur_line, len(l)) + self.col = 0 + self.yank_mark() + self.clear_mark() + self.col = col elif key == KEY_PASTE: ## insert buffer if Editor.yank_buffer: self.col = self.vcol @@ -1233,7 +1245,7 @@ class Editor: key = self.handle_edit_keys(key, char) if key == KEY_QUIT: - if self.hash != self.hash_buffer(): + if self.hash != self.hash_buffer() and not self.is_dir: res = self.line_edit("File changed! Quit (y/N/f)? ", "N") if not res or res[0].upper() == "N": continue @@ -1280,8 +1292,8 @@ class Editor: if fname: try: self.fname = fname - if fname in (".", "..") or (os.stat(fname)[0] & 0x4000): ## Dir - os.chdir(fname) + if fname in (".", "..", "") or (os.stat(fname)[0] & 0x4000): ## Dir + os.chdir(fname or ".") self.work_dir = os.getcwd() # let the os module do the normalization self.fname = "/" if self.work_dir == "/" else self.work_dir.split("/")[-1] self.content = ["Directory '{}'".format(self.work_dir), ""] + sorted( @@ -1379,7 +1391,8 @@ def pye_edit(content, tab_size=4, undo=50, io_device=None): break del slot[index] elif key == KEY_GET: - f = slot[index].line_edit("Open file: ", "", Editor.file_char) + dfn = slot[index].content[slot[index].cur_line].strip() if slot[index].is_dir else "" + f = slot[index].line_edit("Open file: ", dfn, Editor.file_char) if f is not None: slot.append(Editor(tab_size, undo, io_device)) index = len(slot) - 1