浏览代码

Add Set(Raw)MainSelText because SCI_REPLACESEL is also weird.

Martijn Laan 1 年之前
父节点
当前提交
768c9d14f5
共有 2 个文件被更改,包括 20 次插入7 次删除
  1. 15 2
      Components/ScintEdit.pas
  2. 5 5
      Projects/Src/CompForm.pas

+ 15 - 2
Components/ScintEdit.pas

@@ -167,6 +167,8 @@ type
     procedure SetIndentationGuides(const Value: TScintIndentationGuides);
     procedure SetLineNumbers(const Value: Boolean);
     procedure SetMainSelection(const Value: Integer);
+    procedure SetMainSelText(const Value: String);
+    procedure SetRawMainSelText(const Value: TScintRawString);
     procedure SetRawSelText(const Value: TScintRawString);
     procedure SetRawText(const Value: TScintRawString);
     procedure SetReadOnly(const Value: Boolean);
@@ -340,9 +342,9 @@ type
     property Lines: TScintEditStrings read FLines;
     property LinesInWindow: Integer read GetLinesInWindow;
     property MainSelection: Integer read GetMainSelection write SetMainSelection;
-    property MainSelText: String read GetMainSelText;
+    property MainSelText: String read GetMainSelText write SetMainSelText;
     property Modified: Boolean read GetModified;
-    property RawMainSelText: TScintRawString read GetRawMainSelText;
+    property RawMainSelText: TScintRawString read GetRawMainSelText write SetRawMainSelText;
     property RawSelText: TScintRawString read GetRawSelText write SetRawSelText;
     property RawText: TScintRawString read GetRawText write SetRawText;
     property RawTextLength: Integer read GetRawTextLength;
@@ -1654,6 +1656,17 @@ begin
   Call(SCI_SETMAINSELECTION, Value, 0);
 end;
 
+procedure TScintEdit.SetMainSelText(const Value: String);
+begin
+  SetRawMainSelText(ConvertStringToRawString(Value));
+end;
+
+procedure TScintEdit.SetRawMainSelText(const Value: TScintRawString);
+begin
+  Call(SCI_TARGETFROMSELECTION, 0, 0);
+  Call(SCI_REPLACETARGETMINIMAL, Length(Value), LPARAM(PAnsiChar(Value)));
+end;
+
 procedure TScintEdit.SetRawSelText(const Value: TScintRawString);
 { Replaces the main selection's text and *clears* additional selections }
 begin

+ 5 - 5
Projects/Src/CompForm.pas

@@ -3352,7 +3352,7 @@ begin
   end
   else begin
     if FActiveMemo.MainSelTextEquals(FLastFindText, frMatchCase in FLastFindOptions) then
-      FActiveMemo.SelText := FLastReplaceText;
+      FActiveMemo.MainSelText := FLastReplaceText;
     FindNext;
   end;
 end;
@@ -3628,7 +3628,7 @@ procedure TCompileForm.TGenerateGUIDClick(Sender: TObject);
 begin
   if MsgBox('The generated GUID will be inserted into the editor at the cursor position. Continue?',
      SCompilerFormCaption, mbConfirmation, MB_YESNO) = IDYES then
-    FActiveMemo.SelText := GenerateGuid;
+    FActiveMemo.MainSelText := GenerateGuid;
 end;
 
 procedure TCompileForm.TMsgBoxDesignerClick(Sender: TObject);
@@ -3641,7 +3641,7 @@ begin
   var MsgBoxForm := TMsgBoxDesignerForm.Create(Application);
   try
     if MsgBoxForm.ShowModal = mrOk then
-      FActiveMemo.SelText := MsgBoxForm.GetText(FOptions.TabWidth, FOptions.UseTabCharacter);
+      FActiveMemo.MainSelText := MsgBoxForm.GetText(FOptions.TabWidth, FOptions.UseTabCharacter);
   finally
     MsgBoxForm.Free;
   end;
@@ -3666,7 +3666,7 @@ begin
       var Text := RegistryDesignerForm.Text;
       if FMemosStyler.GetSectionFromLineState(FActiveMemo.Lines.State[FActiveMemo.CaretLine]) <> scRegistry then
         Text := '[Registry]' + SNewLine + Text;
-      FActiveMemo.SelText := Text;
+      FActiveMemo.MainSelText := Text;
     end;
   finally
     RegistryDesignerForm.Free;
@@ -3683,7 +3683,7 @@ begin
       var Text := FilesDesignerForm.Text;
       if FMemosStyler.GetSectionFromLineState(FActiveMemo.Lines.State[FActiveMemo.CaretLine]) <> scFiles then
         Text := '[Files]' + SNewLine + Text;
-      FActiveMemo.SelText := Text;
+      FActiveMemo.MainSelText := Text;
     end;
   finally
     FilesDesignerForm.Free;