Skip to content

Commit

Permalink
Merge branch 'main' into scintkeymap-vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnlaan committed Jun 22, 2024
2 parents 0d6210d + 768c9d1 commit cc812b8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
53 changes: 44 additions & 9 deletions Components/ScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions Projects/Src/CompForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit cc812b8

Please sign in to comment.