MCPcopy Index your code
hub / github.com/bpython/bpython / backspace

Function backspace

bpython/curtsiesfrontend/manual_readline.py:230–253  ·  view source on GitHub ↗
(cursor_offset, line)

Source from the content-addressed store, hash-verified

228@edit_keys.on("<BACKSPACE>")
229@edit_keys.on(config="backspace_key")
230def 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")

Callers 1

test_backspaceMethod · 0.90

Calls 1

Tested by 1

test_backspaceMethod · 0.72