mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Fix backspace key un-indenting instead of deleting even when text is selected if the cursor is at the start of the line
This commit is contained in:
parent
5c9e8dce11
commit
8bb6c46314
@ -15,6 +15,8 @@ def get_text_around_cursor(editor, before=True):
|
||||
cursor.movePosition((cursor.StartOfBlock if before else cursor.EndOfBlock), cursor.KeepAnchor)
|
||||
text = editor.selected_text_from_cursor(cursor)
|
||||
return cursor, text
|
||||
|
||||
|
||||
get_text_before_cursor = get_text_around_cursor
|
||||
get_text_after_cursor = lambda editor: get_text_around_cursor(editor, before=False)
|
||||
|
||||
@ -87,6 +89,8 @@ def smart_tab(editor, ev):
|
||||
|
||||
|
||||
def smart_backspace(editor, ev):
|
||||
if editor.textCursor().hasSelection():
|
||||
return False
|
||||
cursor, text = get_text_before_cursor(editor)
|
||||
if text and not text.lstrip():
|
||||
# cursor is preceded by only whitespace
|
||||
@ -97,4 +101,3 @@ def smart_backspace(editor, ev):
|
||||
editor.setTextCursor(cursor)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user