From 8bb6c463149de305a0d9b310ff29e00147a466b4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 16 Dec 2017 07:59:10 +0530 Subject: [PATCH] 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 --- src/calibre/gui2/tweak_book/editor/smarts/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/editor/smarts/utils.py b/src/calibre/gui2/tweak_book/editor/smarts/utils.py index 8e1a6fb301..580ca3f4ae 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/utils.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/utils.py @@ -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 -