diff --git a/Components/ScintEdit.pas b/Components/ScintEdit.pas index f8166e513..b86930827 100644 --- a/Components/ScintEdit.pas +++ b/Components/ScintEdit.pas @@ -138,7 +138,9 @@ TScintEdit = class(TWinControl) function GetLineEndingString: TScintRawString; function GetLineHeight: Integer; function GetLinesInWindow: Integer; + function GetMainSelText: String; function GetModified: Boolean; + function GetRawMainSelText: TScintRawString; function GetRawSelText: TScintRawString; function GetRawText: TScintRawString; function GetReadOnly: Boolean; @@ -165,6 +167,8 @@ TScintEdit = class(TWinControl) 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); @@ -281,9 +285,10 @@ TScintEdit = class(TWinControl) function IsPositionInViewVertically(const Pos: Integer): Boolean; class function KeyCodeAndShiftToKeyDefinition(const KeyCode: TScintKeyCode; Shift: TShiftState): TScintKeyDefinition; + function MainSelTextEquals(const S: String; const MatchCase: Boolean): Boolean; class function KeyToKeyCode(const Key: AnsiChar): TScintKeyCode; procedure PasteFromClipboard; - function RawSelTextEquals(const S: TScintRawString; const MatchCase: Boolean): Boolean; + function RawMainSelTextEquals(const S: TScintRawString; const MatchCase: Boolean): Boolean; class function RawStringIsBlank(const S: TScintRawString): Boolean; procedure Redo; procedure RemoveAdditionalSelections; @@ -298,7 +303,6 @@ TScintEdit = class(TWinControl) procedure SelectNextOccurrence(const Options: TScintFindOptions); function SelEmpty: Boolean; function SelNotEmpty(out Sel: TScintRange): Boolean; - function SelTextEquals(const S: String; const MatchCase: Boolean): Boolean; procedure SetAutoCompleteFillupChars(const FillupChars: AnsiString); procedure SetAutoCompleteSeparator(const C: AnsiChar); procedure SetAutoCompleteSelectedItem(const S: TScintRawString); @@ -339,7 +343,9 @@ TScintEdit = class(TWinControl) property Lines: TScintEditStrings read FLines; property LinesInWindow: Integer read GetLinesInWindow; property MainSelection: Integer read GetMainSelection write SetMainSelection; + property MainSelText: String read GetMainSelText write SetMainSelText; property Modified: Boolean read GetModified; + 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; @@ -864,6 +870,11 @@ procedure TScintEdit.ForwardMessage(const Message: TMessage); CallWindowProc(DefWndProc, Handle, Message.Msg, Message.WParam, Message.LParam); end; +function TScintEdit.GetMainSelText: String; +begin + Result := ConvertRawStringToString(GetRawMainSelText); +end; + function TScintEdit.GetAutoCompleteActive: Boolean; begin Result := Call(SCI_AUTOCACTIVE, 0, 0) <> 0; @@ -1061,7 +1072,19 @@ function TScintEdit.GetPositionOfMatchingBrace(const Pos: Integer): Integer; Result := Call(SCI_BRACEMATCH, Pos, 0); end; +function TScintEdit.GetRawMainSelText: TScintRawString; +begin + var MainSel := MainSelection; + var CaretPos := SelectionCaretPosition[MainSel]; + var AnchorPos := SelectionAnchorPosition[MainSel]; + if AnchorPos < CaretPos then + Result := GetRawTextRange(AnchorPos, CaretPos) + else + Result := GetRawTextRange(CaretPos, AnchorPos); +end; + function TScintEdit.GetRawSelText: TScintRawString; +{ Gets the combined text of *all* selections } var Len: Integer; S: TScintRawString; @@ -1250,6 +1273,12 @@ class function TScintEdit.KeyToKeyCode(const Key: AnsiChar): TScintKeyCode; Result := Ord(UpCase(Key)); end; +function TScintEdit.MainSelTextEquals(const S: String; + const MatchCase: Boolean): Boolean; +begin + Result := RawMainSelTextEquals(ConvertStringToRawString(S), MatchCase); +end; + procedure TScintEdit.Notification(AComponent: TComponent; Operation: TOperation); begin inherited; @@ -1319,7 +1348,7 @@ procedure TScintEdit.PasteFromClipboard; Call(SCI_PASTE, 0, 0); end; -function TScintEdit.RawSelTextEquals(const S: TScintRawString; +function TScintEdit.RawMainSelTextEquals(const S: TScintRawString; const MatchCase: Boolean): Boolean; begin Call(SCI_TARGETFROMSELECTION, 0, 0); @@ -1438,12 +1467,6 @@ procedure TScintEdit.SelectAll; Call(SCI_SELECTALL, 0, 0); end; -function TScintEdit.SelTextEquals(const S: String; - const MatchCase: Boolean): Boolean; -begin - Result := RawSelTextEquals(ConvertStringToRawString(S), MatchCase); -end; - procedure TScintEdit.SetAcceptDroppedFiles(const Value: Boolean); begin if FAcceptDroppedFiles <> Value then begin @@ -1642,7 +1665,19 @@ procedure TScintEdit.SetMainSelection(const Value: Integer); 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 Call(SCI_REPLACESEL, 0, LPARAM(PAnsiChar(Value))); ChooseCaretX; diff --git a/Projects/Src/CompForm.pas b/Projects/Src/CompForm.pas index 392414e7b..409ea4137 100644 --- a/Projects/Src/CompForm.pas +++ b/Projects/Src/CompForm.pas @@ -3196,7 +3196,7 @@ procedure TCompileForm.InitializeFindText(Dlg: TFindDialog); var S: String; begin - S := FActiveMemo.SelText; + S := FActiveMemo.MainSelText; if (S <> '') and (Pos(#13, S) = 0) and (Pos(#10, S) = 0) then Dlg.FindText := S else @@ -3450,8 +3450,8 @@ procedure TCompileForm.ReplaceDialogReplace(Sender: TObject); mbInformation, MB_OK); end else begin - if FActiveMemo.SelTextEquals(FLastFindText, frMatchCase in FLastFindOptions) then - FActiveMemo.SelText := FLastReplaceText; + if FActiveMemo.MainSelTextEquals(FLastFindText, frMatchCase in FLastFindOptions) then + FActiveMemo.MainSelText := FLastReplaceText; FindNext; end; end; @@ -3533,7 +3533,7 @@ procedure TCompileForm.UpdateOccurrenceIndicators(const AMemo: TCompScintEdit); IndicatorRanges.Clear; if FOptions.HighlightSelTextOccurrences and MainSelNotEmpty and MainSelSingleLine then begin - var TextToIndicate := AMemo.RawSelText; + var TextToIndicate := AMemo.RawMainSelText; if SelectionRanges.Count = 0 then { If 0 then we didn't already call GetSelections above} AMemo.GetSelections(SelectionRanges); FindTextAndAddRanges(AMemo, TextToIndicate, GetSelTextOccurrenceFindOptions,SelectionRanges, IndicatorRanges); @@ -3727,7 +3727,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); @@ -3740,7 +3740,7 @@ procedure TCompileForm.TMsgBoxDesignerClick(Sender: TObject); 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; @@ -3765,7 +3765,7 @@ procedure TCompileForm.TRegistryDesignerClick(Sender: TObject); 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; @@ -3782,7 +3782,7 @@ procedure TCompileForm.TFilesDesignerClick(Sender: TObject); 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;