Przeglądaj źródła

use shared key conversion function, copy/paste text

Unknown 6 lat temu
rodzic
commit
74a2d0174e
2 zmienionych plików z 31 dodań i 33 usunięć
  1. 29 22
      lazpaintcontrols/lcvectortextshapes.pas
  2. 2 11
      vectoredit/umain.pas

+ 29 - 22
lazpaintcontrols/lcvectortextshapes.pas

@@ -88,7 +88,7 @@ function StrToFontBidiMode(AText: string): TFontBidiMode;
 
 implementation
 
-uses BGRATransform, BGRAText, LCVectorialFill, math, BGRAUTF8, BGRAUnicode, Graphics;
+uses BGRATransform, BGRAText, LCVectorialFill, math, BGRAUTF8, BGRAUnicode, Graphics, Clipbrd, LCLType, LCLIntf;
 
 function FontStyleToStr(AStyle: TFontStyles): string;
 begin
@@ -666,6 +666,7 @@ procedure TTextShape.KeyDown(Shift: TShiftState; Key: TSpecialKey;
   var AHandled: boolean);
 var
   idxPara, newPos: Integer;
+  stream: TStringStream;
 begin
   if FTextLayout = nil then exit;
 
@@ -749,44 +750,50 @@ begin
   begin
     InsertText(#9);
     AHandled := true;
-  end{ else
-  If (Key = VK_C) and (ssCtrl in Shift) then
-  begin
-    if SelLength> 0 then
-      SetClipboardAsText(GetTextLayoutIgnoreMatrix.CopyText(SelStart, SelLength));
-    Key := 0;
   end else
-  If (Key = VK_X) and (ssCtrl in Shift) then
+  if (Key in[skC,skX]) and (ssCtrl in Shift) then
   begin
-    if SelLength > 0 then
+    if FSelEnd <> FSelStart then
     begin
-      SetClipboardAsText(GetTextLayoutIgnoreMatrix.CopyText(SelStart, SelLength));
-      DeleteSelection;
+      stream := nil;
+      try
+        Clipboard.Clear;
+        stream := TStringStream.Create(GetTextLayoutIgnoreMatrix.CopyText(min(FSelStart,FSelEnd),abs(FSelEnd-FSelStart)));
+        Clipboard.SetFormat(PredefinedClipboardFormat(pcfText), stream);
+      finally
+        stream.Free;
+      end;
+      if Key = skX then DeleteSelectedText;
+      AHandled:= true;
     end;
-    Key := 0;
   end else
-  If (Key = VK_V) and (ssCtrl in Shift) then
+  if (Key = skV) and (ssCtrl in Shift) then
   begin
-    InsertText(Clipboard.AsText);
-    Key := 0;
+    if Clipboard.HasFormat(PredefinedClipboardFormat(pcfText)) then
+    begin
+      InsertText(Clipboard.AsText);
+      AHandled:= true;
+    end;
   end else
-  If (Key = VK_A) and (ssCtrl in Shift) then
+  if (Key = skA) and (ssCtrl in Shift) then
   begin
-    SelStart:= 0;
-    SelLength:= GetTextLayoutIgnoreMatrix.CharCount;
-    Key := 0;
-  end};
+    BeginUpdate;
+    FSelStart:= 0;
+    FSelEnd:= GetTextLayoutIgnoreMatrix.CharCount;
+    EndUpdate;
+  end;
 end;
 
 procedure TTextShape.KeyPress(UTF8Key: string; var AHandled: boolean);
+var
+  stream: TStringStream;
 begin
   if UTF8Key = #8 then
   begin
     if FSelEnd <> FSelStart then DeleteSelectedText
     else DeleteTextBefore(1);
     AHandled := true;
-  end
-  else
+  end else
   if UTF8Key >= ' ' then
   begin
     InsertText(UTF8Key);

+ 2 - 11
vectoredit/umain.pas

@@ -255,15 +255,6 @@ uses math, BGRAPen, BGRAThumbnail, BGRAGradientOriginal, uvectorclipboard, LReso
 
 {$R *.lfm}
 
-function LCLKeyToSpecialKey(Key: Word): TSpecialKey;
-var
-  sk: TSpecialKey;
-begin
-  for sk := low(TSpecialKey) to high(TSpecialKey) do
-    if Key = SpecialKeyToLCL[sk] then exit(sk);
-  exit(skUnknown);
-end;
-
 function IsCreateShapeTool(ATool: TPaintTool): boolean;
 begin
   result := PaintToolClass[ATool] <> nil;
@@ -745,7 +736,7 @@ var
 begin
   if Assigned(img) then
   begin
-    img.KeyDown(Shift, LCLKeyToSpecialKey(Key), AHandled);
+    img.KeyDown(Shift, LCLKeyToSpecialKey(Key, Shift), AHandled);
     if AHandled then Key := 0;
   end;
 
@@ -777,7 +768,7 @@ var
 begin
   if Assigned(img) then
   begin
-    img.KeyUp(Shift, LCLKeyToSpecialKey(Key), AHandled);
+    img.KeyUp(Shift, LCLKeyToSpecialKey(Key, Shift), AHandled);
     if AHandled then Key:= 0;
   end;
 end;