@@ -104,12 +104,16 @@ class Editor:
104104 b"\x1b [5~" : KEY_PGUP ,
105105 b"\x1b [6~" : KEY_PGDN ,
106106 b"\x11 " : KEY_QUIT , ## Ctrl-Q
107- b"\x03 " : KEY_QUIT , ## Ctrl-C
108107 b"\r " : KEY_ENTER ,
109- b"\n " : KEY_ENTER ,
110108 b"\x7f " : KEY_BACKSPACE , ## Ctrl-? (127)
111- b"\x08 " : KEY_BACKSPACE ,
112109 b"\x1b [3~" : KEY_DELETE ,
110+ b"\x1b [Z" : KEY_BACKTAB , ## Shift Tab
111+ b"\x1b [3;5~" : KEY_YANK , ## Ctrl-Del
112+ #ifndef BASIC
113+ ## keys mapped onto themselves
114+ b"\x03 " : KEY_QUIT , ## Ctrl-C
115+ b"\n " : KEY_ENTER ,
116+ b"\x08 " : KEY_BACKSPACE ,
113117 b"\x13 " : KEY_WRITE , ## Ctrl-S
114118 b"\x06 " : KEY_FIND , ## Ctrl-F
115119 b"\x0e " : KEY_FIND_AGAIN , ## Ctrl-N
@@ -118,19 +122,19 @@ class Editor:
118122 b"\x1a " : KEY_UNDO , ## Ctrl-Z
119123 b"\x09 " : KEY_TAB ,
120124 b"\x15 " : KEY_BACKTAB , ## Ctrl-U
121- b"\x1b [Z" : KEY_BACKTAB , ## Shift Tab
125+ b"\x12 " : KEY_REPLC , ## Ctrl-R
122126 b"\x18 " : KEY_YANK , ## Ctrl-X
123- b"\x1b [3;5~" : KEY_YANK , ## Ctrl-Del
124127 b"\x16 " : KEY_ZAP , ## Ctrl-V
125128 b"\x04 " : KEY_DUP , ## Ctrl-D
126- b" \x12 " : KEY_REPLC , ## Ctrl-R
129+ ##
127130 b"\x1b [M" : KEY_MOUSE ,
128131 b"\x01 " : KEY_TOGGLE , ## Ctrl-A
129132 b"\x14 " : KEY_FIRST , ## Ctrl-T
130133 b"\x02 " : KEY_LAST , ## Ctrl-B
131134 b"\x1b [1;5H" : KEY_FIRST ,
132135 b"\x1b [1;5F" : KEY_LAST ,
133136 b"\x0f " : KEY_GET , ## Ctrl-O
137+ #endif
134138 }
135139
136140 def __init__ (self , tab_size , undo_limit ):
@@ -148,10 +152,10 @@ def __init__(self, tab_size, undo_limit):
148152 self .content = ["" ]
149153 self .undo = []
150154 self .undo_limit = max (undo_limit , 0 )
151- self .yank_buffer = []
152- self .lastkey = 0
153155 self .case = "n"
154156 self .autoindent = "y"
157+ self .yank_buffer = []
158+ self .lastkey = 0
155159#ifndef BASIC
156160 self .replc_pattern = ""
157161 self .write_tabs = "n"
@@ -348,7 +352,7 @@ def get_input(self): ## read from interface/keyboard one byte each and match ag
348352 else :
349353 return KEY_MOUSE ## do nothing but set the cursor
350354#endif
351- elif input [ 0 ] >= 0x20 : ## but only if no Ctrl-Char
355+ elif len ( input ) == 1 : ## but only if a single char
352356 return input [0 ]
353357
354358 def display_window (self ): ## Update window and status line
@@ -478,8 +482,7 @@ def handle_cursor_keys(self, key): ## keys which move, sanity checks later
478482 self .cursor_down ()
479483 self .col = 0
480484 elif key == KEY_HOME :
481- ns = self .spaces (self .content [self .cur_line ])
482- self .col = ns if self .col != ns else 0
485+ self .col = self .spaces (self .content [self .cur_line ]) if self .col == 0 else 0
483486 elif key == KEY_END :
484487 self .col = len (self .content [self .cur_line ])
485488 elif key == KEY_PGUP :
@@ -558,7 +561,7 @@ def handle_edit_key(self, key): ## keys which change content
558561 ni = 0
559562 if self .autoindent == "y" : ## Autoindent
560563 ni = min (self .spaces (l ), self .col ) ## query indentation
561- r = self . content [ self . cur_line ] .partition ("\x23 " )[0 ].rstrip () ## \x23 == #
564+ r = l .partition ("\x23 " )[0 ].rstrip () ## \x23 == #
562565 if r and r [- 1 ] == ':' and self .col >= len (r ): ## look for : as the last non-space before comment
563566 ni += self .tab_size
564567 self .cur_line += 1
@@ -594,15 +597,33 @@ def handle_edit_key(self, key): ## keys which change content
594597 self .changed = '*'
595598 elif key == KEY_TAB :
596599 self .undo_add (self .cur_line , [l ], key )
597- ni = self .tab_size - self .col % self .tab_size ## determine spaces to add
598- self .content [self .cur_line ] = l [:self .col ] + ' ' * ni + l [self .col :]
599- self .col += ni
600+ if False : pass
601+ #ifndef BASIC
602+ else :
603+ ns = self .spaces (l )
604+ if self .col == 0 and self .col != ns :
605+ self .content [self .cur_line ] = ' ' * (self .tab_size - ns % self .tab_size ) + l
606+ self .cursor_down ()
607+ #endif
608+ else :
609+ ni = self .tab_size - self .col % self .tab_size ## determine spaces to add
610+ self .content [self .cur_line ] = l [:self .col ] + ' ' * ni + l [self .col :]
611+ self .col += ni
600612 self .changed = '*'
601613 elif key == KEY_BACKTAB :
602614 self .undo_add (self .cur_line , [l ], key )
603- ni = min ((self .col - 1 ) % self .tab_size + 1 , self .spaces (l , self .col )) ## determine spaces to drop
604- self .content [self .cur_line ] = l [:self .col - ni ] + l [self .col :]
605- self .col -= ni
615+ if False : pass
616+ #ifndef BASIC
617+ else :
618+ ns = self .spaces (l )
619+ if self .col == 0 and ns > 0 :
620+ self .content [self .cur_line ] = l [(ns - 1 ) % self .tab_size + 1 :]
621+ self .cursor_down ()
622+ #endif
623+ else :
624+ ni = min ((self .col - 1 ) % self .tab_size + 1 , self .spaces (l , self .col )) ## determine spaces to drop
625+ self .content [self .cur_line ] = l [:self .col - ni ] + l [self .col :]
626+ self .col -= ni
606627 self .changed = '*'
607628#ifndef BASIC
608629 elif key == KEY_REPLC :
@@ -706,10 +727,6 @@ def handle_edit_key(self, key): ## keys which change content
706727 self .total_lines = len (self .content ) ## brute force
707728 if len (self .undo ) == 0 : ## test changed flag
708729 self .changed = self .sticky_c
709- #ifdef BASIC
710- elif key < 0x20 :
711- self .message = "Sorry, command not supported"
712- #endif
713730 elif key >= 0x20 : ## character to be added
714731 self .undo_add (self .cur_line , [l ], 0x20 if key == 0x20 else 0x41 )
715732 self .content [self .cur_line ] = l [:self .col ] + chr (key ) + l [self .col :]
0 commit comments