Browse Source

+ DelStart and SelectWord implemented
* AddChar(tab) now reacts correctly if efAutoIndent is set

pierre 26 years ago
parent
commit
b8da895212
1 changed files with 56 additions and 8 deletions
  1. 56 8
      ide/text/weditor.pas

+ 56 - 8
ide/text/weditor.pas

@@ -2273,7 +2273,7 @@ begin
    end
    end
   else
   else
    begin
    begin
-     Delete(S,CurPos.X+1,1);
+     Delete(S,LinePosToCharIdx(CurPos.Y,CurPos.X)+1,1);
      SetLineText(CurPos.Y,S);
      SetLineText(CurPos.Y,S);
      SDX:=-1; SDY:=0;
      SDX:=-1; SDY:=0;
    end;
    end;
@@ -2294,12 +2294,19 @@ begin
 end;
 end;
 
 
 procedure TCodeEditor.DelStart;
 procedure TCodeEditor.DelStart;
+var S: string;
 begin
 begin
   if IsReadOnly then Exit;
   if IsReadOnly then Exit;
+  S:=GetLineText(CurPos.Y);
 
 
-  NotImplemented; Exit;
-
-  SetModified(true);
+  if (S<>'') and (CurPos.X<>0) then
+  begin
+    SetLineText(CurPos.Y,copy(S,LinePosToCharIdx(CurPos.Y,CurPos.X)+1,255));
+    SetCurPtr(0,CurPos.Y);
+    UpdateAttrs(CurPos.Y,attrAll);
+    DrawLines(CurPos.Y);
+    SetModified(true);
+  end;
 end;
 end;
 
 
 procedure TCodeEditor.DelEnd;
 procedure TCodeEditor.DelEnd;
@@ -2309,7 +2316,7 @@ begin
   S:=GetLineText(CurPos.Y);
   S:=GetLineText(CurPos.Y);
   if (S<>'') and (CurPos.X<>length(S)) then
   if (S<>'') and (CurPos.X<>length(S)) then
   begin
   begin
-    SetLineText(CurPos.Y,copy(S,1,CurPos.X));
+    SetLineText(CurPos.Y,copy(S,1,LinePosToCharIdx(CurPos.Y,CurPos.X)));
     SetCurPtr(CurPos.X,CurPos.Y);
     SetCurPtr(CurPos.X,CurPos.Y);
     UpdateAttrs(CurPos.Y,attrAll);
     UpdateAttrs(CurPos.Y,attrAll);
     DrawLines(CurPos.Y);
     DrawLines(CurPos.Y);
@@ -2526,8 +2533,28 @@ begin
 end;
 end;
 
 
 procedure TCodeEditor.SelectWord;
 procedure TCodeEditor.SelectWord;
+const WordChars = ['A'..'Z','a'..'z','0'..'9','_'];
+var S : String;
+    StartPos,EndPos : byte;
+    A,B: TPoint;
 begin
 begin
-  NotImplemented; Exit;
+  A:=CurPos;
+  B:=CurPos;
+  S:=GetLineText(A.Y);
+  StartPos:=A.X+1;
+  EndPos:=StartPos;
+  if not (S[StartPos] in WordChars) then
+    exit
+  else
+    begin
+       While (StartPos>0) and (S[StartPos-1] in WordChars) do
+         Dec(StartPos);
+       While (EndPos<Length(S)) and (S[EndPos+1] in WordChars) do
+         Inc(EndPos);
+       A.X:=StartPos-1;
+       B.X:=EndPos;
+       SetSelection(A,B);
+    end;
 end;
 end;
 
 
 procedure TCodeEditor.SelectLine;
 procedure TCodeEditor.SelectLine;
@@ -2608,12 +2635,29 @@ var S,SC,TabS: string;
     SP: TPoint;
     SP: TPoint;
 begin
 begin
   if IsReadOnly then Exit;
   if IsReadOnly then Exit;
+
   Lock;
   Lock;
   SP:=CurPos;
   SP:=CurPos;
   if (C<>TAB) or ((Flags and efUseTabCharacters)<>0) then
   if (C<>TAB) or ((Flags and efUseTabCharacters)<>0) then
     SC:=C
     SC:=C
+  else if ((Flags and efAutoIndent)=0) then
+    SC:=CharStr(' ',TabSize)
   else
   else
-    SC:=CharStr(' ',TabSize);
+    begin
+      if CurPos.Y>1 then
+        begin
+          S:=GetLineText(CurPos.Y-1);
+          BI:=CurPos.X+1;
+          while S[BI]=' ' do
+            inc(BI);
+          if BI=CurPos.X+1 then
+            SC:=CharStr(' ',TabSize)
+          else
+            SC:=CharStr(' ',BI-CurPos.X-1);
+        end
+      else
+        SC:=CharStr(' ',TabSize);
+    end;
   S:=GetLineText(CurPos.Y);
   S:=GetLineText(CurPos.Y);
   if CharIdxToLinePos(CurPos.Y,length(S))<CurPos.X then
   if CharIdxToLinePos(CurPos.Y,length(S))<CurPos.X then
     begin
     begin
@@ -4475,7 +4519,11 @@ end;
 END.
 END.
 {
 {
   $Log$
   $Log$
-  Revision 1.51  1999-10-08 15:24:50  pierre
+  Revision 1.52  1999-10-12 23:35:18  pierre
+    + DelStart and SelectWord implemented
+    * AddChar(tab) now reacts correctly if efAutoIndent is set
+
+  Revision 1.51  1999/10/08 15:24:50  pierre
    * InsertFrom bug (end of line wasdiscarded)
    * InsertFrom bug (end of line wasdiscarded)
 
 
   Revision 1.50  1999/09/28 23:44:13  pierre
   Revision 1.50  1999/09/28 23:44:13  pierre