Revision: 4509
          http://sourceforge.net/p/vexi/code/4509
Author:   clrg
Date:     2013-04-11 23:25:53 +0000 (Thu, 11 Apr 2013)
Log Message:
-----------
WIP

Modified Paths:
--------------
    
branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/edit.t
    
branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/scrollpane.t

Modified: 
branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/edit.t
===================================================================
--- 
branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/edit.t   
    2013-04-07 01:27:23 UTC (rev 4508)
+++ 
branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/edit.t   
    2013-04-11 23:25:53 UTC (rev 4509)
@@ -11,13 +11,17 @@
         // INTERNAL
         
         var v_text = "";
+        var insert = true;
         
         var line_count = 0;
         const line_markers = [];
         
         const line_height = vexi.ui.font.height(font, fontsize, "dy");
         
+        var cursor = 0;
+        var selectFrom = null;
         
+        
             
         const addLine = function(str, line_num) {
             const line_y = line_height * line_num;
@@ -33,19 +37,41 @@
         const floor = vexi.math.floor;
         const layoutText = function() {
             clear();
-            var cur = max(0, floor((from_y - line_height) / line_height));
+            var line = max(0, floor((from_y - line_height) / line_height));
             const to = from_y + height;
-            while ((to > cur * line_height) and (line_count > cur)) {
-                const n1 = line_markers[2 * cur];
-                const n2 = line_markers[2 * cur + 1];
-                addLine(v_text.substring(n1, n2)+" ", cur);
-                cur++;
+            while ((to > line * line_height) and (line_count > line)) {
+                const n1 = line_markers[2 * line];
+                const n2 = line_markers[2 * line + 1];
+                addLine(v_text.substring(n1, n2)+" ", line);
+                line++;
             }
         }
         
         
         
         
+        const locateCursor = function(dx, dy) {
+            const line = floor((dy + from_y) / line_height);
+            const n1 = line_markers[2 * line];
+            const n2 = line_markers[2 * line + 1];
+            var curi = n1;
+            var curx = 0;
+            while (n2 > curi) {
+                const w = vexi.ui.font.width(font, fontsize, c);
+                if (curx > dx + (w/2))
+                    break;
+                curi ++;
+                curx += w;
+            }
+            cursor = curi;
+            cursor_x = curx;
+            cursor_y = line * line_height - from_y;
+            cursor_height = line_height;
+        }
+        
+        
+        
+        
         const NEWLINE = 0;
         const WHITESPACE = 1;
         const ALPHA_NUMERIC = 2;
@@ -185,5 +211,241 @@
             layoutText();
         }
         
+        
+        
+        const deleteSelected = function() {
+            if (selectFrom == null) return;
+            if (cursor > selectFrom) {
+                v_text = v_text.substring(0, selectFrom) + 
v_text.substring(cursor);
+                cursor = selectFrom;
+            } else {
+                v_text = v_text.substring(0, cursor) + 
v_text.substring(selectFrom);
+            }
+            selectFrom = null;
+        }
+        
+        const getSelectedText = function() {
+            if (selectFrom == null) return;
+            return (cursor > selectFrom)
+                ? v_text.substring(0, selectFrom) + v_text.substring(cursor)
+                : v_text.substring(0, cursor) + v_text.substring(selectFrom);
+        }
+        
+        const unselectLeft = function() {
+            if (selectFrom == null) return false;
+            if (cursor > selectFrom)
+                cursor = selectFrom;
+            selectFrom = null;
+            return true;
+        }
+        
+        const unselectRight = function() {
+            if (selectFrom == null) return false;
+            if (selectFrom > cursor)
+                cursor = selectFrom;
+            selectFrom = null;
+            return true;
+        }
+        
+        thisbox.selectAll = function() {
+            selectFrom = 0;
+            cursor = v_text.length;
+        }
+        
+        thisbox.copy = function() {
+            if (selectFrom != null) {
+                var t = getSelectedText();
+                vexi.ui.clipboard = t;
+            }
+        }
+        
+        thisbox.copyAll = function() {
+            selectAll();
+            copy();
+            unselectAll();
+        }
+        
+        thisbox.cut = function() {
+            if (selectFrom != null) {
+                var t = getSelectedText();
+                vexi.ui.clipboard = t;
+                deleteSelected();
+            }
+        }
+        
+        thisbox.cutAll = function() {
+            selectAll();
+            copy();
+            deleteSelected();
+        }
+        
+        thisbox.paste = function() {
+            deleteSelected();
+            var t = vexi.ui.clipboard;
+            insertText(t);
+        }
+        
+        /** applies a caret to the letter preceeding the cursor if it is valid 
*/
+        const checkAndApplyCaret = function() {
+            if (cursor == 0) return;
+            const oldc = v_text.charCodeAt(cursor-1);
+            const newc = static.charCaretLookup[oldc+""];
+            if (newc!=null) {
+                v_text = v_text.substring(0, cursor-1) + 
vexi.string.fromCharCode(newc) + v_text.substring(cursor);
+                // there is a miniscule possibility of the careted and 
un-careted
+                // characters being a slightly different width and needing 
reflow
+                reflowText();
+            }
+        }
+        
+        
+        
+        thisbox.KeyPressed ++= function(v) {
+            
+            if (v.length == 1) {
+                if (!insert) {
+                    KeyPressed = "delete";
+                }
+                
+                deleteSelected();
+                
+                v_text = v_text.substring(0, cursor) + v + 
v_text.substring(cursor);
+                cursor++;
+            } else
+            switch(v) {
+            // select all
+            case "C-a":
+            case "C-A":
+                selectAll();
+                break;
+            
+            // unselect all
+            case "escape":
+                unselectAll();
+                break;
+            
+            // copy
+            case "C-c":
+            case "C-C":
+                copy();
+                break;
+                
+            // cut
+            case "C-x":
+            case "C-X":
+                cut();
+                break;
+                
+            // paste
+            case "C-v":
+            case "C-V":
+                paste();
+                break;
+            
+            // add circumflex (caret) accent
+            case "C-^":
+                checkAndApplyCaret(cbInd, cwInd, cPos);
+                break;
+            
+            case "insert":
+            case "INSERT":
+                insert = false;
+                break;
+            
+            case "delete":
+            case "DELETE":
+            case "C-delete":
+            case "C-DELETE":
+                if (selectFrom != null)
+                    deleteSelected();
+                else if (v_text.length > cursor)
+                    v_text = v_text.substring(0, cursor) + 
v_text.substring(cursor+1);
+                break;
+            
+            case "back_space":
+            case "BACK_SPACE":
+            case "C-back_space":
+            case "C-BACK_SPACE":
+                if (selectFrom != null)
+                    deleteSelected();
+                else if (cursor > 0)
+                    v_text = v_text.substring(0, cursor-1) + 
v_text.substring(cursor);
+                break;
+                
+            // insert a new line
+            case "enter":
+            case "ENTER":
+                v_text = v_text.substring(0, cursor) + '\n' + 
v_text.substring(cursor);
+                break;
+                
+            // move cursor left
+            case "left":
+            case "C-left":
+                if (unselectLeft()) {
+                    return;
+                }
+            case "LEFT":
+            case "C-LEFT":
+                break;
+                
+            // move cursor right
+            case "right":
+            case "C-right":
+                if (unselectRight()) return;
+            case "RIGHT":
+            case "C-RIGHT":
+                break;
+                
+            // move cursor up
+            case "up":
+            case "C-up":
+                if (unselectLeft()) {
+                    return;
+                }
+            case "UP":
+            case "C-UP":
+                break;
+            
+            // move cursor down
+            case "down":
+            case "C-down":
+                if (unselectRight()) {
+                    return;
+                }
+            case "DOWN":
+            case "C-DOWN":
+                break;
+                
+            // move cursor to start of line
+            case "home":
+            case "HOME":
+                break;
+                
+            // move cursor to end of line
+            case "end":
+            case "END":
+            }
+            
+            reflowText();
+        }
+        
     </ui:box>
+    
+    static.charCaretLookup = {
+        "65":194,  "194":65,  // A->\xC2
+        "97":226,  "226":97,  // a->\xE2
+        "69":202,  "202":69,  // E->\xCA
+        "101":234, "234":101, // e->\xEA
+        "73":206,  "206":73,  // I->\xCE
+        "105":238, "238":105, // i->\xEE
+        "79":212,  "212":79,  // O->\xD4
+        "111":244, "244":111, // o->\xF4
+        "85":219,  "219":85,  // U->\xDB
+        "117":251, "251":117, // u->\xFB
+        "87":372,  "372":87,  // W->
+        "119":373, "373":119, // w->
+        "89":374,  "374":89,  // Y->
+        "121":375, "375":121  // y->
+    };
+    
 </vexi>

Modified: 
branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/scrollpane.t
===================================================================
--- 
branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/scrollpane.t
       2013-04-07 01:27:23 UTC (rev 4508)
+++ 
branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/scrollpane.t
       2013-04-11 23:25:53 UTC (rev 4509)
@@ -112,7 +112,6 @@
         vbody.x = vbody.y = 0;
         vbody.width = vbody.height = 0;
         vport[0] = vbody;
-        vbody.height ++= function(v) { cascade = v; trace(new 
vexi.js.Exception(v)); }
         return vport;
     }
     

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


------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to