# HG changeset patch
# User Andrey Skvortsov <andrej.skvortzov@gmail.com>
# Date 1482507631 -10800
# Node ID 41ca586da9dc28780177228916d95dde004fe86e
# Parent  bd03e1217fa56fcfec36b8f6735bf45a6b0d2534
fix strange behavior on Backspace press in ST

Before:
 if text was selected and cursor was at indention, one indention (two
 spaces) was removed.

 if cursor was at start position of the line, then nothing happened.

 if cursor was in the middle of indention then on backspace more
 indention were added


Now:
 if text is selected, it will be removed.
 if cursor is at start position, then new line will be removed.
 if cursor was in the middle of indention one indention is removed.

diff -r bd03e1217fa5 -r 41ca586da9dc editors/TextViewer.py
--- a/editors/TextViewer.py	Thu Dec 22 17:39:58 2016 +0300
+++ b/editors/TextViewer.py	Fri Dec 23 18:40:31 2016 +0300
@@ -894,11 +894,12 @@
                     key_handled = True
             elif key == wx.WXK_BACK:
                 if self.TextSyntax in ["ST", "ALL"]:
-                    indent = self.Editor.GetLineIndentation(line)
-                    if lineText.strip() == "" and indent > 0:
-                        self.Editor.DelLineLeft()
-                        self.Editor.AddText(" " * ((max(0, indent - 1) / 2) * 2))
-                        key_handled = True
+                    if not self.Editor.GetSelectedText():
+                        indent = self.Editor.GetColumn(self.Editor.GetCurrentPos())
+                        if lineText.strip() == "" and len(lineText) > 0 and indent > 0:
+                            self.Editor.DelLineLeft()
+                            self.Editor.AddText(" " * ((max(0, indent - 1) / 2) * 2))
+                            key_handled = True
             if not key_handled:
                 event.Skip()
         else: