Revision: 4206
          http://vexi.svn.sourceforge.net/vexi/?rev=4206&view=rev
Author:   clrg
Date:     2011-08-17 04:41:02 +0000 (Wed, 17 Aug 2011)

Log Message:
-----------
One more anonymous function for the road

Modified Paths:
--------------
    trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/field.t

Modified: trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/field.t
===================================================================
--- trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/field.t      
2011-08-17 02:15:48 UTC (rev 4205)
+++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/field.t      
2011-08-17 04:41:02 UTC (rev 4206)
@@ -1,4 +1,4 @@
-<!-- Copyright 2009 - see COPYING for details [LGPL] -->
+<!-- Copyright 2011 - see COPYING for details [LGPL] -->
 
 <vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" 
xmlns:rdt="vexi.util.redirect">
     <meta:doc>
@@ -29,31 +29,6 @@
         th_view    ++= static.viewWrite;
         KeyPressed ++= static.keypressWrite;
         
-        /** sync the textfield with the cursor pos so it is always visible */
-        thisbox.syncViewWithCursor = function(v) {
-            cascade = v;
-            var viewtoedit   = th_view.distanceto(v_edit).x;
-            var porttocursor = th_viewport.distanceto(v_cursor).x;
-            var vieweditend  = th_view.width - v_edit.width - viewtoedit;
-            
-            if (v_cursor.x == 0 or v_edit.getCWord() == null or 
th_viewport.width >= th_view.width) {
-                // no word - set to 0
-                th_view.x = 0;
-                
-            } else if (viewtoedit > porttocursor) {
-                // cursor too far to the left
-                th_view.x = -v_cursor.x;
-                
-            } else if (porttocursor + v_cursor.width > th_viewport.width) {
-                // cursor too far to the right
-                th_view.x = th_viewport.width - vieweditend - v_cursor.x - 
viewtoedit;
-                
-            } else if (0 > th_view.x and th_viewport.width > th_view.width + 
th_view.x) {
-                // cursor visible but view is too far to the left 
-                th_view.x = th_viewport.width - th_view.width;
-            }
-        }
-        
     </ui:box>
     
     static.keypressWrite = function(v) {
@@ -152,12 +127,42 @@
         var edit = trapee.v_edit;
         var cursor = trapee.v_cursor;
         var f = trapee.focused;
-        var sync = trapee.syncViewWithCursor;
+        
         edit.focused = f;
         if (f) {
             if (trapee.selectonfocus) {
                 edit.selectAll();
             }
+            
+            // sync the textfield with the cursor pos so it is always visible
+            var tbox = trapee;
+            var sync = function(v) {
+                cascade = v;
+                var view = tbox.th_view;
+                var viewport = tbox.th_viewport;
+                var viewtoedit   = view.distanceto(edit).x;
+                var porttocursor = viewport.distanceto(cursor).x;
+                var vieweditend  = view.width - edit.width - viewtoedit;
+                
+                if (cursor.x == 0 or edit.getCWord() == null or viewport.width 
>= view.width) {
+                    // no word - set to 0
+                    view.x = 0;
+                    
+                } else if (viewtoedit > porttocursor) {
+                    // cursor too far to the left
+                    view.x = -cursor.x;
+                    
+                } else if (porttocursor + cursor.width > viewport.width) {
+                    // cursor too far to the right
+                    view.x = viewport.width - vieweditend - cursor.x - 
viewtoedit;
+                    
+                } else if (0 > view.x and viewport.width > view.width + 
view.x) {
+                    // cursor visible but view is too far to the left 
+                    view.x = viewport.width - view.width;
+                }
+            };
+            
+            tbox.v_syncViewWithCursor = v_sync;
             if (cursor and sync) {
                 cursor.x ++= sync;
                 trapee.th_viewport.width ++= sync;
@@ -166,6 +171,8 @@
             if (trapee.selectonfocus) {
                 edit.unselectAll();
             }
+            var sync = trapee.v_syncViewWithCursor;
+            trapee.v_syncViewWithCursor = null;
             if (cursor and sync) {
                 cursor.x --= sync;
                 trapee.th_view.width --= sync;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to