wip II
[sdk] / ecere / src / gui / controls / EditBox.ec
index 16b567d..f8d2825 100644 (file)
@@ -776,6 +776,7 @@ public:
       {
          if(this)
          {
+            undoBuffer.dontRecord++;
             Deselect();
             DelCh(this.lines.first, 0, 0, this.lines.last, this.lineCount-1, ((EditLine)(this.lines.last)).count, true);
             if(value)
@@ -783,6 +784,7 @@ public:
             //SetViewToCursor(true);
             UpdateDirty();
             Home();
+            undoBuffer.dontRecord--;
          }
       }
 
@@ -943,7 +945,7 @@ private:
    int caretX, caretY;
    UndoBuffer undoBuffer { data = this };
    int savedAction;
-   Color selectionColor, selectionText;
+   ColorAlpha selectionColor, selectionText;
    SyntaxColorScheme colorScheme { };
 
    menu = Menu { };
@@ -1718,10 +1720,26 @@ private:
                            if(!wasEscaped)
                               escaped = true;
                         }
-                        else if(!inQuotes && !inString && !inMultiLineComment && !inSingleLineComment && 
-                           ( ( isdigit(word[0]) /*&& (!c || word[-1] == ' ' || word[-1] == '\t')*/ ) || (word[0] == '.' && isdigit(word[1]))))
+                        else if(!inQuotes && !inString && !inMultiLineComment && !inSingleLineComment && (isdigit(word[0]) || (word[0] == '.' && isdigit(word[1]))))
                         {
-                           newTextColor = colorScheme.numberColor;
+                           char * dot = strchr(word, '.');
+                           char * s = null;
+                           if(dot)
+                              strtod((dot == word + wordLen) ? (dot+1) : word, &s);
+                           else
+                              strtol(word, &s, 0);
+                           if(s && s != word)
+                           {
+                              if((dot && *s == 'f' && !isalnum(s[1]) && s[1] != '_') || (!isalpha(*s) && *s != '_'))
+                              {
+                                 int newWordLen = s + ((*s == 'f') ? 1 : 0) - word;
+                                 newTextColor = colorScheme.numberColor;
+                                 c += newWordLen - wordLen;
+                                 wordLen = newWordLen;
+                              }
+                              else if(dot && dot > word && (isalpha(dot[1]) || dot[1] == '_'))
+                                 newTextColor = colorScheme.numberColor;
+                           }
                         }
                         else
                         {
@@ -1921,12 +1939,12 @@ private:
             if(x > selX)
             {
                if(x > line.count)
-                  width = Max(line.length + (x - line.count) * space.w, maxLength);
+                  width = Max(line.length + (x - line.count) * space.w, maxLength + XOFFSET);
             }
             else
             {
                if(selX > selLine.count)
-                  width = Max(selLine.length + (selX - selLine.count) * space.w, maxLength);
+                  width = Max(selLine.length + (selX - selLine.count) * space.w, maxLength + XOFFSET);
             }
          }
 
@@ -3451,6 +3469,8 @@ private:
       {
          key.code = (SmartKey)key.code;
       }
+      else if(!ch && key.alt)
+         key.code = 0;
 
       switch(key.code) //(ch || key.alt || key.ctrl) ? key.code : (Key)(SmartKey)key.code)
       {
@@ -4271,6 +4291,7 @@ private:
          case home:
          {
             if(style.stuckCaret) break;
+            if(!style.multiLine && key.ctrl) break;
             if(!(style.freeCaret))
                this.selX = Min(this.selX, this.selLine.count);
 
@@ -4293,7 +4314,7 @@ private:
                   for(c=0; line.buffer[c]; c++)
                      if(line.buffer[c] != ' ' && line.buffer[c] != '\t')
                         break;
-                  if(c != 0 || this.x)
+                  if(shift && (c != 0 || this.x))
                      DirtyLine(this.y);
                   if(this.x != c) 
                      this.x = c;
@@ -4302,8 +4323,8 @@ private:
                }
                else
                {
-                  /*if(this.x != 0)
-                     DirtyLine(this.y);*/
+                  if(shift && this.x != 0)
+                     DirtyLine(this.y);
                   this.x = 0;
                }
                ComputeColumn();
@@ -4316,7 +4337,8 @@ private:
          case end:
          {
             if(style.stuckCaret) break;
-            if(!(style.freeCaret))
+            if(!style.multiLine && key.ctrl) break;
+            if(!style.freeCaret)
                this.selX = Min(this.selX, this.selLine.count);
 
             if(!shift) SelDirty();
@@ -4327,7 +4349,8 @@ private:
             else if(this.x != this.line.count)
             {
                this.x = this.line.count;
-               //DirtyLine(this.y);
+               if(shift)
+                  DirtyLine(this.y);
                ComputeColumn();
             }
             if(!shift) Deselect();
@@ -4498,49 +4521,55 @@ private:
             }
             break;
          case pageDown:
-            if(key.ctrl)
+            if(style.multiLine)
             {
-               if(!(style.hScroll) || hasHorzScroll) break;
-               if(this.viewX < this.maxLength)
+               if(key.ctrl)
+               {
+                  if(!(style.hScroll) || hasHorzScroll) break;
+                  if(this.viewX < this.maxLength)
+                  {
+                     //this.viewX+=this.space.w*this.tabSize;
+                     //DirtyAll();
+                     SetScrollPosition((this.viewX + this.space.w*this.tabSize), this.viewY * this.space.h);
+                  }
+               }
+               else
                {
-                  //this.viewX+=this.space.w*this.tabSize;
-                  //DirtyAll();
-                  SetScrollPosition((this.viewX + this.space.w*this.tabSize), this.viewY * this.space.h);
+                  PageDown();
+                  DirtyAll();
+                  if(!shift) Deselect();
+                  SetCursorToViewX();
+                  SetCursorToViewY();
                }
+               return false;
             }
-            else
-            {
-               PageDown();
-               DirtyAll();
-               if(!shift) Deselect();
-               SetCursorToViewX();
-               SetCursorToViewY();
-            }
-            return false;
-            // break;
+            break;
          case pageUp:
-            if(key.ctrl)
+            if(style.multiLine)
             {
-               if(!(style.hScroll) || hasHorzScroll) break;
-               if(this.viewX > 0)
+               if(key.ctrl)
                {
-                  //this.viewX-=this.space.w*this.tabSize;
-                  //this.viewX = Max(this.viewX,0);
-                  //DirtyAll();
-                  SetScrollPosition((this.viewX-this.space.w*this.tabSize), this.viewY * this.space.h);
-                  // SetCursorToView();
+                  if(!(style.hScroll) || hasHorzScroll) break;
+                  if(this.viewX > 0)
+                  {
+                     //this.viewX-=this.space.w*this.tabSize;
+                     //this.viewX = Max(this.viewX,0);
+                     //DirtyAll();
+                     SetScrollPosition((this.viewX-this.space.w*this.tabSize), this.viewY * this.space.h);
+                     // SetCursorToView();
+                  }
                }
+               else
+               {
+                  PageUp();
+                  DirtyAll();
+                  if(!shift) Deselect();
+                  SetCursorToViewX();
+                  SetCursorToViewY();
+               }
+               return false;
             }
-            else
-            {
-               PageUp();
-               DirtyAll();
-               if(!shift) Deselect();
-               SetCursorToViewX();
-               SetCursorToViewY();
-            }
-            // break;
-            return false;
+            break;
          case insert:
             if(key.ctrl)
             {
@@ -4704,7 +4733,8 @@ private:
                         delete newline;
                      }
                      return false;
-                  } else if(!key.ctrl && !key.alt && ch != 128 && ch >= 32)
+                  }
+                  else if(!key.ctrl && !key.alt && ch != 128 && ch >= 32)
                   {
                      PutCh(ch);
                      return false;
@@ -4909,14 +4939,14 @@ private:
             this.line = line;
             this.x = 0;
             this.col = 0;
-
-            ComputeLength(this.line);
+            line.count = length;
 
 #ifdef _DEBUG
       if(length > 4000 || length < 0)
          printf("Warning");
 #endif
-            line.count = length;
+            ComputeLength(this.line);
+
             DirtyEnd(this.y);
             this.y++;
             this.lineCount++;
@@ -5230,7 +5260,7 @@ public:
          if(style.allCaps)
             ch = (ch < 128) ? toupper(ch) : ch;     // TODO: UNICODE TO UPPER
 
-         if(this.x < this.line.count && this.overwrite)
+         if(this.overwrite && selX == x && selY == y && this.x < this.line.count)
          {
             char buffer[5];
             char * newString;
@@ -5337,6 +5367,7 @@ public:
    {
       if(this)
       {
+         undoBuffer.dontRecord++;
          Deselect();
          DelCh(this.lines.first, 0, 0, this.lines.last, this.lineCount-1, ((EditLine)(this.lines.last)).count, true);
          if(format)
@@ -5352,6 +5383,7 @@ public:
          }
          UpdateDirty();
          Home();
+         undoBuffer.dontRecord--;
       }
    }