Skip to content

Commit

Permalink
Edit Book: Fix backspace key un-indenting instead of deleting even wh…
Browse files Browse the repository at this point in the history
…en text is selected if the cursor is at the start of the line
  • Loading branch information
kovidgoyal committed Dec 16, 2017
1 parent 5c9e8dc commit 8bb6c46
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/calibre/gui2/tweak_book/editor/smarts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -97,4 +101,3 @@ def smart_backspace(editor, ev):
editor.setTextCursor(cursor)
return True
return False

0 comments on commit 8bb6c46

Please sign in to comment.