[Python-checkins] r62546 - in python/trunk/Lib/idlelib: EditorWindow.py NEWS.txt PyShell.py

kurt.kaiser python-checkins at python.org
Sun Apr 27 23:07:41 CEST 2008


Author: kurt.kaiser
Date: Sun Apr 27 23:07:41 2008
New Revision: 62546

Log:
Home / Control-A toggles between left margin and end of leading white
space.  Patch 1196903 Jeff Shute.

M    idlelib/PyShell.py
M    idlelib/EditorWindow.py
M    idlelib/NEWS.txt


Modified:
   python/trunk/Lib/idlelib/EditorWindow.py
   python/trunk/Lib/idlelib/NEWS.txt
   python/trunk/Lib/idlelib/PyShell.py

Modified: python/trunk/Lib/idlelib/EditorWindow.py
==============================================================================
--- python/trunk/Lib/idlelib/EditorWindow.py	(original)
+++ python/trunk/Lib/idlelib/EditorWindow.py	Sun Apr 27 23:07:41 2008
@@ -153,6 +153,7 @@
         text.bind("<Right>", self.move_at_edge_if_selection(1))
         text.bind("<<del-word-left>>", self.del_word_left)
         text.bind("<<del-word-right>>", self.del_word_right)
+        text.bind("<<beginning-of-line>>", self.home_callback)
 
         if flist:
             flist.inversedict[self] = key
@@ -281,6 +282,50 @@
         self.flist.new(dirname)
         return "break"
 
+    def home_callback(self, event):
+        if (event.state & 12) != 0 and event.keysym == "Home":
+            # state&1==shift, state&4==control, state&8==alt
+            return # <Modifier-Home>; fall back to class binding
+
+        if self.text.index("iomark") and \
+           self.text.compare("iomark", "<=", "insert lineend") and \
+           self.text.compare("insert linestart", "<=", "iomark"):
+            insertpt = int(self.text.index("iomark").split(".")[1])
+        else:
+            line = self.text.get("insert linestart", "insert lineend")
+            for insertpt in xrange(len(line)):
+                if line[insertpt] not in (' ','\t'):
+                    break
+            else:
+                insertpt=len(line)
+
+        lineat = int(self.text.index("insert").split('.')[1])
+
+        if insertpt == lineat:
+            insertpt = 0
+
+        dest = "insert linestart+"+str(insertpt)+"c"
+
+        if (event.state&1) == 0:
+            # shift not pressed
+            self.text.tag_remove("sel", "1.0", "end")
+        else:
+            if not self.text.index("sel.first"):
+                self.text.mark_set("anchor","insert")
+
+            first = self.text.index(dest)
+            last = self.text.index("anchor")
+
+            if self.text.compare(first,">",last):
+                first,last = last,first
+
+            self.text.tag_remove("sel", "1.0", "end")
+            self.text.tag_add("sel", first, last)
+
+        self.text.mark_set("insert", dest)
+        self.text.see("insert")
+        return "break"
+
     def set_status_bar(self):
         self.status_bar = self.MultiStatusBar(self.top)
         if macosxSupport.runningAsOSXApp():

Modified: python/trunk/Lib/idlelib/NEWS.txt
==============================================================================
--- python/trunk/Lib/idlelib/NEWS.txt	(original)
+++ python/trunk/Lib/idlelib/NEWS.txt	Sun Apr 27 23:07:41 2008
@@ -6,6 +6,9 @@
 - Issue #2665: On Windows, an IDLE installation upgraded from an old version
   would not start if a custom theme was defined.
 
+- Home / Control-A toggles between left margin and end of leading white
+  space.  Patch 1196903 Jeff Shute.
+
 What's New in IDLE 2.6a1?
 =========================
 

Modified: python/trunk/Lib/idlelib/PyShell.py
==============================================================================
--- python/trunk/Lib/idlelib/PyShell.py	(original)
+++ python/trunk/Lib/idlelib/PyShell.py	Sun Apr 27 23:07:41 2008
@@ -826,7 +826,6 @@
         text.bind("<<newline-and-indent>>", self.enter_callback)
         text.bind("<<plain-newline-and-indent>>", self.linefeed_callback)
         text.bind("<<interrupt-execution>>", self.cancel_callback)
-        text.bind("<<beginning-of-line>>", self.home_callback)
         text.bind("<<end-of-file>>", self.eof_callback)
         text.bind("<<open-stack-viewer>>", self.open_stack_viewer)
         text.bind("<<toggle-debugger>>", self.toggle_debugger)
@@ -1063,16 +1062,6 @@
             self.top.quit()
         return "break"
 
-    def home_callback(self, event):
-        if event.state != 0 and event.keysym == "Home":
-            return # <Modifier-Home>; fall back to class binding
-        if self.text.compare("iomark", "<=", "insert") and \
-           self.text.compare("insert linestart", "<=", "iomark"):
-            self.text.mark_set("insert", "iomark")
-            self.text.tag_remove("sel", "1.0", "end")
-            self.text.see("insert")
-            return "break"
-
     def linefeed_callback(self, event):
         # Insert a linefeed without entering anything (still autoindented)
         if self.reading:


More information about the Python-checkins mailing list