Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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.
Binary file modified additional_documentation/Pyboard Editor.doc
Binary file not shown.
35 changes: 24 additions & 11 deletions pye
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,7 +21,7 @@
## - Added multi-file support
##

PYE_VERSION = " V2.78 "
PYE_VERSION = " V2.79 "
try:
import usys as sys
except:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Binary file modified pye.mpy
Binary file not shown.
33 changes: 23 additions & 10 deletions pye.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PYE_VERSION = " V2.78 "
PYE_VERSION = " V2.79 "
try:
import usys as sys
except:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
35 changes: 24 additions & 11 deletions pye_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,7 +19,7 @@
## - Added multi-file support
##

PYE_VERSION = " V2.78 "
PYE_VERSION = " V2.79 "
try:
import usys as sys
except:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
35 changes: 24 additions & 11 deletions pye_win
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,7 +19,7 @@
## - Added multi-file support
##

PYE_VERSION = " V2.78 "
PYE_VERSION = " V2.79 "
try:
import usys as sys
except:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down