| 228 | @edit_keys.on("<BACKSPACE>") |
| 229 | @edit_keys.on(config="backspace_key") |
| 230 | def backspace(cursor_offset, line): |
| 231 | if cursor_offset == 0: |
| 232 | return cursor_offset, line |
| 233 | if not line[:cursor_offset].strip(): # if just whitespace left of cursor |
| 234 | # front_white = len(line[:cursor_offset]) - \ |
| 235 | # len(line[:cursor_offset].lstrip()) |
| 236 | to_delete = ((cursor_offset - 1) % INDENT) + 1 |
| 237 | return ( |
| 238 | cursor_offset - to_delete, |
| 239 | line[: cursor_offset - to_delete] + line[cursor_offset:], |
| 240 | ) |
| 241 | # removes opening bracket along with closing bracket |
| 242 | # if there is nothing between them |
| 243 | # TODO: could not get config value here, works even without -B option |
| 244 | on_closing_char, pair_close = cursor_on_closing_char_pair( |
| 245 | cursor_offset, line |
| 246 | ) |
| 247 | if on_closing_char and pair_close: |
| 248 | return ( |
| 249 | cursor_offset - 1, |
| 250 | line[: cursor_offset - 1] + line[cursor_offset + 1 :], |
| 251 | ) |
| 252 | |
| 253 | return (cursor_offset - 1, line[: cursor_offset - 1] + line[cursor_offset:]) |
| 254 | |
| 255 | |
| 256 | @edit_keys.on(config="clear_line_key") |