Skip to content

Commit b72717f

Browse files
committed
pye_core: Cut or copy the current line if no text is highlighted.
Signed-off-by: robert-hh <[email protected]>
1 parent ed544c7 commit b72717f

File tree

8 files changed

+82
-30
lines changed

8 files changed

+82
-30
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ shows most of the commands.:
6868
|Alt-PgUp & Alt-PgDn|Cycle trough bookmarked locations|
6969
|Alt-Home & Alt-End|Cycle trough locations with changes, based on the Undo list|
7070
|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|
71-
|Ctrl-X|Cut the highlighted text|
72-
|Ctrl-C or Ctrl-D|Copy the highlighted text|
71+
|Ctrl-X|Cut the highlighted text. If the mark is not set, cut the current line.|
72+
|Ctrl-C|Copy the highlighted text. If the mark is not set, copy the current line.|
7373
|Ctrl-V|Insert the copied/cut text.|
74+
|Ctrl-D|Copy text from the Undo buffer to the paste buffer.|
7475
|Ctrl-Z|Undo the last change(s)|
7576
|Ctrl-Y|Redo the last undo(s), repeating what had been undone by undo|
7677
|Ctrl-P|Comment/Uncomment a line or highlighted area|
@@ -568,8 +569,11 @@ the list of files in the current dir
568569

569570
**2.75** Fix an error with character swap.
570571

571-
**2.76** Cycle through places with changes.
572+
**2.76** Cycle through places with changes.
572573

573-
**2.77** Change key binding for bookmark location to Alt-Ins, using Alt-Home and Alt-End to cycle through
574-
locations with changes.
574+
**2.77** Change key binding for bookmark location to Alt-Ins, using Alt-Home and Alt-End
575+
to cycle through locations with changes.
575576

577+
**2.78** Use Ctrl-D to copy text from the UNDO buffer to the Paste buffer.
578+
579+
**2.79** Cut or copy the current line if no text is highlighted.
512 Bytes
Binary file not shown.
-15.3 KB
Binary file not shown.

pye

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
## - Added multi-file support
2222
##
2323

24-
PYE_VERSION = " V2.78 "
24+
PYE_VERSION = " V2.79 "
2525
try:
2626
import usys as sys
2727
except:
@@ -1118,12 +1118,24 @@ class Editor:
11181118
self.cur_line, self.col = cur_line, cur_col ## restore pos
11191119
self.message = "'{}' replaced {} times".format(pat, count)
11201120
elif key == KEY_CUT: # delete line or line(s) into buffer
1121-
if self.mark is not None:
1122-
self.delete_mark(True)
1121+
if self.mark is None:
1122+
if self.cur_line < self.total_lines - 1:
1123+
self.mark = (self.cur_line + 1, 0)
1124+
else:
1125+
self.mark = (self.cur_line, len(l))
1126+
self.col = 0
1127+
self.delete_mark(True)
11231128
elif key == KEY_COPY: # copy line(s) into buffer
1124-
if self.mark is not None:
1125-
self.yank_mark()
1126-
self.clear_mark()
1129+
col = self.col
1130+
if self.mark is None:
1131+
if self.cur_line < self.total_lines - 1:
1132+
self.mark = (self.cur_line + 1, 0)
1133+
else:
1134+
self.mark = (self.cur_line, len(l))
1135+
self.col = 0
1136+
self.yank_mark()
1137+
self.clear_mark()
1138+
self.col = col
11271139
elif key == KEY_PASTE: ## insert buffer
11281140
if Editor.yank_buffer:
11291141
self.col = self.vcol

pye.mpy

108 Bytes
Binary file not shown.

pye.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PYE_VERSION = " V2.78 "
1+
PYE_VERSION = " V2.79 "
22
try:
33
import usys as sys
44
except:
@@ -1022,12 +1022,24 @@ def handle_edit_keys(self, key, char):
10221022
self.cur_line, self.col = cur_line, cur_col
10231023
self.message = "'{}' replaced {} times".format(pat, count)
10241024
elif key == KEY_CUT:
1025-
if self.mark is not None:
1026-
self.delete_mark(True)
1025+
if self.mark is None:
1026+
if self.cur_line < self.total_lines - 1:
1027+
self.mark = (self.cur_line + 1, 0)
1028+
else:
1029+
self.mark = (self.cur_line, len(l))
1030+
self.col = 0
1031+
self.delete_mark(True)
10271032
elif key == KEY_COPY:
1028-
if self.mark is not None:
1029-
self.yank_mark()
1030-
self.clear_mark()
1033+
col = self.col
1034+
if self.mark is None:
1035+
if self.cur_line < self.total_lines - 1:
1036+
self.mark = (self.cur_line + 1, 0)
1037+
else:
1038+
self.mark = (self.cur_line, len(l))
1039+
self.col = 0
1040+
self.yank_mark()
1041+
self.clear_mark()
1042+
self.col = col
10311043
elif key == KEY_PASTE:
10321044
if Editor.yank_buffer:
10331045
self.col = self.vcol

pye_core.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Small python text editor based on the
33
## Very simple VT100 terminal text editor widget
44
## Copyright (c) 2015 Paul Sokolovsky (initial code)
5-
## Copyright (c) 2015-2021 Robert Hammelrath (additional code)
5+
## Copyright (c) 2015-2025 Robert Hammelrath (additional code)
66
## Distributed under MIT License
77
## Changes:
88
## - Ported the code to boards from micropython.org, Pycom Boards,
@@ -19,7 +19,7 @@
1919
## - Added multi-file support
2020
##
2121

22-
PYE_VERSION = " V2.78 "
22+
PYE_VERSION = " V2.79 "
2323
try:
2424
import usys as sys
2525
except:
@@ -1116,12 +1116,24 @@ def handle_edit_keys(self, key, char): ## keys which change content
11161116
self.cur_line, self.col = cur_line, cur_col ## restore pos
11171117
self.message = "'{}' replaced {} times".format(pat, count)
11181118
elif key == KEY_CUT: # delete line or line(s) into buffer
1119-
if self.mark is not None:
1120-
self.delete_mark(True)
1119+
if self.mark is None:
1120+
if self.cur_line < self.total_lines - 1:
1121+
self.mark = (self.cur_line + 1, 0)
1122+
else:
1123+
self.mark = (self.cur_line, len(l))
1124+
self.col = 0
1125+
self.delete_mark(True)
11211126
elif key == KEY_COPY: # copy line(s) into buffer
1122-
if self.mark is not None:
1123-
self.yank_mark()
1124-
self.clear_mark()
1127+
col = self.col
1128+
if self.mark is None:
1129+
if self.cur_line < self.total_lines - 1:
1130+
self.mark = (self.cur_line + 1, 0)
1131+
else:
1132+
self.mark = (self.cur_line, len(l))
1133+
self.col = 0
1134+
self.yank_mark()
1135+
self.clear_mark()
1136+
self.col = col
11251137
elif key == KEY_PASTE: ## insert buffer
11261138
if Editor.yank_buffer:
11271139
self.col = self.vcol

pye_win

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
## - Added multi-file support
2020
##
2121

22-
PYE_VERSION = " V2.78 "
22+
PYE_VERSION = " V2.79 "
2323
try:
2424
import usys as sys
2525
except:
@@ -1116,12 +1116,24 @@ class Editor:
11161116
self.cur_line, self.col = cur_line, cur_col ## restore pos
11171117
self.message = "'{}' replaced {} times".format(pat, count)
11181118
elif key == KEY_CUT: # delete line or line(s) into buffer
1119-
if self.mark is not None:
1120-
self.delete_mark(True)
1119+
if self.mark is None:
1120+
if self.cur_line < self.total_lines - 1:
1121+
self.mark = (self.cur_line + 1, 0)
1122+
else:
1123+
self.mark = (self.cur_line, len(l))
1124+
self.col = 0
1125+
self.delete_mark(True)
11211126
elif key == KEY_COPY: # copy line(s) into buffer
1122-
if self.mark is not None:
1123-
self.yank_mark()
1124-
self.clear_mark()
1127+
col = self.col
1128+
if self.mark is None:
1129+
if self.cur_line < self.total_lines - 1:
1130+
self.mark = (self.cur_line + 1, 0)
1131+
else:
1132+
self.mark = (self.cur_line, len(l))
1133+
self.col = 0
1134+
self.yank_mark()
1135+
self.clear_mark()
1136+
self.col = col
11251137
elif key == KEY_PASTE: ## insert buffer
11261138
if Editor.yank_buffer:
11271139
self.col = self.vcol

0 commit comments

Comments
 (0)