<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -510,15 +510,15 @@ def cursor_in_zone(context, selector):
 
 def get_item_for_range(context, range):
     '''Returns the smallest item containing the given range'''
-    return context.itemizer().smallestItemContainingCharacterRange_()
+    return context.itemizer().smallestItemContainingCharacterRange_(range)
 
 def get_item_parent_for_range(context, range):
     '''Returns the parent of the item containing the given range'''
-    item = tea.get_item_from_range(context, range)
+    item = get_item_for_range(context, range)
     new_range = item.range()
     # Select the parent if the range is the same
     while(item.parent() and (new_range.location == range.location and \
-          new_range.length == range.length):
+          new_range.length == range.length)):
         item = item.parent()
         new_range = item.range()
     return item</diff>
      <filename>src/Contents/Resources/tea_actions.py</filename>
    </modified>
    <modified>
      <diff>@@ -5,14 +5,18 @@ their contents.
 If direction == 'in', balance will attempt to move inward (select first
 balanced delimiters contained within the current delimiter) rather than
 outward.
+
+Setting force_itemizers to True will use itemizers even in HTML documents.
 '''
 
+from Foundation import NSValue
+
 import tea_actions as tea
 
 from zencoding import html_matcher as html_matcher
 
-def act(context, direction='out'):
-    if tea.cursor_in_zone(context, &quot;html, html *, xml, xml *&quot;):
+def act(context, direction='out', force_itemizers=False):
+    if tea.cursor_in_zone(context, &quot;html, html *, xml, xml *&quot;) and not force_itemizers:
         # HTML or XML, so use Zen-coding's excellent balancing commands
         
         # Using this method rather than tea.get_single_range() is better
@@ -62,9 +66,19 @@ def act(context, direction='out'):
         targets = []
         for range in ranges:
             if direction.lower() == 'in':
-                targets[] = tea.get_item_for_range(context, range).range()
+                item = tea.get_item_for_range(context, range)
+                if item is None:
+                    # No item, so jump to next iteration
+                    continue
+                new_range = item.range()
+                if new_range.location == range.location and \
+                   new_range.length == range.length:
+                    items = item.childItems()
+                    if len(items) &gt; 0:
+                        new_range = items[0].range()
+                targets.append(new_range)
             else:
-                targets[] = tea.get_item_parent_for_range(context, range).range()
+                targets.append(tea.get_item_parent_for_range(context, range).range())
         
         # Set the selections, and return
         context.setSelectedRanges_([NSValue.valueWithRange_(range) for range in targets])</diff>
      <filename>src/Support/Scripts/balance.py</filename>
    </modified>
    <modified>
      <diff>@@ -2,30 +2,6 @@
 &lt;action-recipes&gt;
 	&lt;!-- Commands are in menu order, because that's how I roll --&gt;
 	
-	&lt;action id=&quot;com.onecrayon.TextActions.Balance&quot; category=&quot;actions.text.generic&quot;&gt;
-		&lt;class&gt;TEAforEspresso&lt;/class&gt;
-		&lt;title&gt;Balance&lt;/title&gt;
-		&lt;key-equivalent&gt;cmd d&lt;/key-equivalent&gt;
-		&lt;setup&gt;
-			&lt;action&gt;balance&lt;/action&gt;
-		&lt;/setup&gt;
-	&lt;/action&gt;
-	
-	&lt;action id=&quot;com.onecrayon.TextActions.BalanceIn&quot; category=&quot;actions.text.generic&quot;&gt;
-		&lt;class&gt;TEAforEspresso&lt;/class&gt;
-		&lt;title&gt;Balance Inward&lt;/title&gt;
-		&lt;key-equivalent&gt;cmd D&lt;/key-equivalent&gt;
-		&lt;setup&gt;
-			&lt;action&gt;balance&lt;/action&gt;
-			&lt;options&gt;
-				&lt;dict&gt;
-					&lt;key&gt;direction&lt;/key&gt;
-					&lt;string&gt;in&lt;/string&gt;
-				&lt;/dict&gt;
-			&lt;/options&gt;
-		&lt;/setup&gt;
-	&lt;/action&gt;
-	
 	&lt;action id=&quot;com.onecrayon.TextActions.TrimLines&quot; category=&quot;actions.text.generic/actions.text.whitespace&quot;&gt;
 		&lt;class&gt;TEAforEspresso&lt;/class&gt;
 		&lt;title&gt;Trim Line(s)&lt;/title&gt;
@@ -52,6 +28,30 @@
 		&lt;/setup&gt;
 	&lt;/action&gt;
 	
+	&lt;action id=&quot;com.onecrayon.TextActions.Balance&quot; category=&quot;actions.text.generic/actions.text.selection/tea.balance&quot;&gt;
+		&lt;class&gt;TEAforEspresso&lt;/class&gt;
+		&lt;title&gt;Balance&lt;/title&gt;
+		&lt;key-equivalent&gt;control b&lt;/key-equivalent&gt;
+		&lt;setup&gt;
+			&lt;action&gt;balance&lt;/action&gt;
+		&lt;/setup&gt;
+	&lt;/action&gt;
+	
+	&lt;action id=&quot;com.onecrayon.TextActions.BalanceIn&quot; category=&quot;actions.text.generic/actions.text.selection/tea.balance&quot;&gt;
+		&lt;class&gt;TEAforEspresso&lt;/class&gt;
+		&lt;title&gt;Balance Inward&lt;/title&gt;
+		&lt;key-equivalent&gt;control B&lt;/key-equivalent&gt;
+		&lt;setup&gt;
+			&lt;action&gt;balance&lt;/action&gt;
+			&lt;options&gt;
+				&lt;dict&gt;
+					&lt;key&gt;direction&lt;/key&gt;
+					&lt;string&gt;in&lt;/string&gt;
+				&lt;/dict&gt;
+			&lt;/options&gt;
+		&lt;/setup&gt;
+	&lt;/action&gt;
+	
 	&lt;action id=&quot;com.onecrayon.TextActions.SelectWord&quot; category=&quot;actions.text.generic/actions.text.selection/1&quot;&gt;
 		&lt;class&gt;TEAforEspresso&lt;/class&gt;
 		&lt;title&gt;Word&lt;/title&gt;</diff>
      <filename>src/TextActions/Actions.xml</filename>
    </modified>
    <modified>
      <diff>@@ -26,6 +26,7 @@
 	&lt;/category&gt;
 	
 	&lt;!-- TEA-specific categories --&gt;
+	&lt;category id=&quot;tea.balance&quot; show=&quot;inline separated&quot;&gt;&lt;/category&gt;
 	&lt;category id=&quot;tea.conversion&quot; show=&quot;inline separated&quot;&gt;&lt;/category&gt;
 	&lt;category id=&quot;tea.insertion&quot; show=&quot;inline separated&quot;&gt;&lt;/category&gt;
 	&lt;category id=&quot;tea.wrapping&quot; show=&quot;inline separated&quot;&gt;&lt;/category&gt;</diff>
      <filename>src/TextActions/Categories.xml</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8a24b1c32ff74647da8b1a8b963dc8f1964ec6cb</id>
    </parent>
  </parents>
  <author>
    <name>Ian Beck</name>
    <email>ian@onecrayon.com</email>
  </author>
  <url>http://github.com/onecrayon/tea-for-espresso/commit/24a2c8910758b260cbf994ea2a98c9f3be7fb04c</url>
  <id>24a2c8910758b260cbf994ea2a98c9f3be7fb04c</id>
  <committed-date>2009-10-24T22:45:01-07:00</committed-date>
  <authored-date>2009-10-24T22:45:01-07:00</authored-date>
  <message>Debugged problems with balancing and itemizer utilities; changed layout of balance actions in menu</message>
  <tree>548a8829391132d940dab066b61b55706569e3a6</tree>
  <committer>
    <name>Ian Beck</name>
    <email>ian@onecrayon.com</email>
  </committer>
</commit>
