Forráskód Böngészése

Bracketed paste and OSC 52 in FV

Margers 9 hónapja
szülő
commit
fb872569da

+ 18 - 2
packages/fv/src/app.inc

@@ -402,9 +402,21 @@ CONST
 {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
 
 {$IFDEF FPC_DOTTEDUNITS}
-uses    System.Console.Mouse{,System.Resources.Resource};
+uses    System.Console.Mouse
+{$ifdef FV_UNICODE}
+  {$ifdef unix},FreeVision.Ufvclip{$endif}
+{$else FV_UNICODE}
+  {$ifdef unix},FreeVision.Fvclip{$endif}
+{$endif FV_UNICODE}
+  ;
 {$ELSE FPC_DOTTEDUNITS}
-uses    Mouse{,Resource};
+uses    Mouse
+{$ifdef FV_UNICODE}
+  {$ifdef unix},ufvclip{$endif}
+{$else FV_UNICODE}
+  {$ifdef unix},fvclip{$endif}
+{$endif FV_UNICODE}
+  ;
 {$ENDIF FPC_DOTTEDUNITS}
 
 resourcestring  sVideoFailed='Video initialization failed.';
@@ -1117,6 +1129,7 @@ BEGIN
 {$endif FV_UNICODE}
    InitHistory;                                               { Start history up }
    Inherited Init;                                            { Call ancestor }
+   {$ifdef unix}InitClip(@Self);{$endif}
    InitMsgBox;
    { init mouse and cursor }
    {$IFDEF FPC_DOTTEDUNITS}System.Console.{$ENDIF}Video.SetCursorType(crHidden);
@@ -1140,6 +1153,7 @@ BEGIN
    {$IFDEF FPC_DOTTEDUNITS}FreeVision.{$ENDIF}drivers.donevideo;
 {$endif FV_UNICODE}
 {   DoneMemory;}                                       { Close memory }
+   {$ifdef unix}DoneClip;{$endif}
    donekeyboard;
 {   DoneResource;}
 END;
@@ -1174,6 +1188,7 @@ var s:string;
 {$endif}
 
 BEGIN                                                 { Compatability only }
+  {$ifdef unix}DoneClip;{$endif}
   DoneSysError;
   DoneEvents;
 {$ifdef FV_UNICODE}
@@ -1207,6 +1222,7 @@ BEGIN                                                 { Compatability only }
   InitScreen;
   InitEvents;
   InitSysError;
+  {$ifdef unix}InitClip(@Self);{$endif}
   Redraw;
 END;
 

+ 44 - 0
packages/fv/src/dialogs.inc

@@ -1811,11 +1811,55 @@ Delta, Anchor, OldCurPos, OldFirstPos, OldSelStart, OldSelEnd: Sw_Integer;
      End Else CheckValid := True;                     { No validator }
    END;
 
+   Procedure PasteText(P :PAnsiChar;ASize:sw_integer);
+   var s : sw_string;
+    i : sw_integer;
+    st: sw_string;
+    wlen : sw_integer;
+   begin
+     {$ifdef FV_UNICODE}
+     wlen:=ASize;
+     Setlength(S,wlen);
+     wlen:=Utf8ToUnicode(@S[1],wlen,P,ASize);
+     Setlength(S,wlen);
+     {$else}
+     Setlength(S,Min(ASize,255));
+     Move(P^,s[1],Min(ASize,255));
+     {$endif}
+     for i:=1 to Min(length(s),255) do
+     begin
+       {$ifdef FV_UNICODE}
+       st:=Data+S[i];
+       {$else}
+       st:=Data^+s[i];
+       {$endif}
+       If not assigned(validator) or
+          Validator^.IsValidInput(st,False)  then
+         Begin
+           Event.What:=evKeyDown;
+           {$ifdef FV_UNICODE}
+           Event.UnicodeChar:=s[i];
+           {$else}
+           Event.CharCode:=s[i];
+           {$endif}
+           Event.Scancode:=0;
+           TInputLine.HandleEvent(Event);             { add pasted chars}
+         End;
+       if length(st)=255 then break;
+     end;
+   end;
+
 BEGIN
    Inherited HandleEvent(Event);                      { Call ancestor }
    If (State AND sfSelected <> 0) Then Begin          { View is selected }
      Case Event.What Of
        evNothing: Exit;                               { Speed up exit }
+       evCommand: Begin                               { Command event }
+         If (Event.Command=cmPasteText) then begin    { Bracketed paste or osc52 }
+           PasteText(Event.InfoPtr,Event.Id);
+           ClearEvent(Event);
+         end;
+       end;
        evMouseDown: Begin                             { Mouse down event }
          Delta := MouseDelta;                         { Calc scroll value }
          If CanScroll(Delta) Then Begin               { Can scroll }

+ 1 - 0
packages/fv/src/editors.pas

@@ -2117,6 +2117,7 @@ begin
             cmCut         : ClipCut;
             cmCopy        : ClipCopy;
             cmPaste       : ClipPaste;
+            cmPasteText   : InsertText(Event.InfoPtr,Event.Id,false);
             cmUndo        : Undo;
             cmClear       : DeleteSelect;
             cmCharLeft    : SetCurPtr (PrevChar  (CurPtr), SelectMode);

+ 3 - 0
packages/fv/src/fvconsts.pas

@@ -258,6 +258,9 @@ const
   cmNewColorIndex          = 75;
   cmSaveColorIndex         = 76;
 
+  { fvclip Unit }
+  cmPasteText   = 77;    {bracketed paste, osc52 paste}
+
   { StdDlg Unit   800 - ? }
   cmFileOpen    = 800;   { Returned from TFileDialog when Open pressed }
   cmFileReplace = 801;   { Returned from TFileDialog when Replace pressed }