Skip to content

Commit

Permalink
Various cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnlaan committed Jun 17, 2024
1 parent c4a0ec2 commit 60ccc49
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
49 changes: 26 additions & 23 deletions Components/ScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface
StyleNumberUnusedBits = 8-StyleNumberBits; { 3 bits of a byte are unused }

type
TScintChangeHistory = (schDisabled, schMarkers, schIndicators);
TScintEditAutoCompleteSelectionEvent = TNotifyEvent;
TScintEditChangeInfo = record
Inserting: Boolean;
Expand Down Expand Up @@ -87,7 +88,7 @@ TScintEdit = class(TWinControl)
FAcceptDroppedFiles: Boolean;
FAutoCompleteFontName: String;
FAutoCompleteFontSize: Integer;
FChangeHistory: Boolean;
FChangeHistory: TScintChangeHistory;
FCodePage: Integer;
FDirectPtr: Pointer;
FDirectStatusFunction: SciFnDirectStatus;
Expand Down Expand Up @@ -151,7 +152,7 @@ TScintEdit = class(TWinControl)
procedure SetCaretLine(const Value: Integer);
procedure SetCaretPosition(const Value: Integer);
procedure SetCaretVirtualSpace(const Value: Integer);
procedure SetChangeHistory(const Value: Boolean);
procedure SetChangeHistory(const Value: TScintChangeHistory);
procedure SetFillSelectionToEdge(const Value: Boolean);
procedure SetIndentationGuides(const Value: TScintIndentationGuides);
procedure SetLineNumbers(const Value: Boolean);
Expand Down Expand Up @@ -264,6 +265,7 @@ TScintEdit = class(TWinControl)
function IsPositionInViewVertically(const Pos: Integer): Boolean;
procedure PasteFromClipboard;
function RawSelTextEquals(const S: TScintRawString; const MatchCase: Boolean): Boolean;
class function RawStringIsBlank(const S: TScintRawString): Boolean;
procedure Redo;
procedure RemoveAdditionalSelections;
function ReplaceRawTextRange(const StartPos, EndPos: Integer;
Expand Down Expand Up @@ -337,7 +339,7 @@ TScintEdit = class(TWinControl)
write SetAutoCompleteFontName;
property AutoCompleteFontSize: Integer read FAutoCompleteFontSize
write SetAutoCompleteFontSize default 0;
property ChangeHistory: Boolean read FChangeHistory write SetChangeHistory default False;
property ChangeHistory: TScintChangeHistory read FChangeHistory write SetChangeHistory default schDisabled;
property CodePage: Integer read FCodePage write SetCodePage default CP_UTF8;
property Color;
property FillSelectionToEdge: Boolean read FFillSelectionToEdge write SetFillSelectionToEdge
Expand Down Expand Up @@ -475,21 +477,11 @@ TScintPixmap = class
property Pixmap: Pointer read GetPixmap;
end;

function ScintRawStringIsBlank(const S: TScintRawString): Boolean;

implementation

uses
ShellAPI, RTLConsts, UITypes, GraphUtil;

function ScintRawStringIsBlank(const S: TScintRawString): Boolean;
begin
for var I := 1 to Length(S) do
if not(S[I] in [#9, ' ']) then
Exit(False);
Result := True;
end;

{ TScintEdit }

const
Expand Down Expand Up @@ -546,9 +538,9 @@ procedure TScintEdit.ApplyOptions;
Call(SCI_SETVIRTUALSPACEOPTIONS, Flags, 0);
Call(SCI_SETWRAPMODE, Ord(FWordWrap), 0);
Call(SCI_SETINDENTATIONGUIDES, IndentationGuides[FIndentationGuides], 0);
{ If FChangeHistory is True then next call to ClearUndo will enable change
history and else we should disable it now }
if not FChangeHistory then
{ If FChangeHistory is not schDisabled then next call to ClearUndo will enable
change history and else we should disable it now }
if FChangeHistory = schDisabled then
Call(SCI_SETCHANGEHISTORY, SC_CHANGE_HISTORY_DISABLED, 0);
end;

Expand All @@ -558,7 +550,6 @@ procedure TScintEdit.BeginUndoAction;
end;

function TScintEdit.Call(Msg: Cardinal; WParam: Longint; LParam: Longint): Longint;

begin
HandleNeeded;
if FDirectPtr = nil then
Expand Down Expand Up @@ -649,9 +640,14 @@ procedure TScintEdit.ClearUndo(const ClearChangeHistory: Boolean);
SetSavePoint;
Call(SCI_EMPTYUNDOBUFFER, 0, 0);

if ClearChangeHistory and FChangeHistory then begin
if ClearChangeHistory and (FChangeHistory <> schDisabled) then begin
Call(SCI_SETCHANGEHISTORY, SC_CHANGE_HISTORY_DISABLED, 0);
Call(SCI_SETCHANGEHISTORY, SC_CHANGE_HISTORY_ENABLED or SC_CHANGE_HISTORY_MARKERS, 0);
var Flags := SC_CHANGE_HISTORY_ENABLED;
if FChangeHistory = schMarkers then
Flags := Flags or SC_CHANGE_HISTORY_MARKERS
else
Flags := Flags or SC_CHANGE_HISTORY_INDICATORS;
Call(SCI_SETCHANGEHISTORY, Flags, 0);
end;
end;

Expand Down Expand Up @@ -726,7 +722,7 @@ procedure TScintEdit.CreateWnd;
Call(SCI_SETMODEVENTMASK, SC_MOD_INSERTTEXT or SC_MOD_DELETETEXT, 0);
Call(SCI_SETCARETPERIOD, GetCaretBlinkTime, 0);
Call(SCI_SETSCROLLWIDTHTRACKING, 1, 0);
{ The default popup menu conflicts with the VCL's PopupMenu on Delphi 3 }
{ The default popup menu conflicts with the VCL's PopupMenu }
Call(SCI_USEPOPUP, 0, 0);
SetDefaultWordChars;
ApplyOptions;
Expand Down Expand Up @@ -815,7 +811,7 @@ function TScintEdit.FormatRange(const Draw: Boolean;
procedure TScintEdit.ForwardMessage(const Message: TMessage);
begin
if HandleAllocated then
SendMessage(Handle, Message.Msg, Message.WParam, Message.LParam);
CallWindowProc(DefWndProc, Handle, Message.Msg, Message.WParam, Message.LParam);
end;

function TScintEdit.GetAutoCompleteActive: Boolean;
Expand Down Expand Up @@ -1270,6 +1266,14 @@ function TScintEdit.RawSelTextEquals(const S: TScintRawString;
end;
end;

class function TScintEdit.RawStringIsBlank(const S: TScintRawString): Boolean;
begin
for var I := 1 to Length(S) do
if not(S[I] in [#9, ' ']) then
Exit(False);
Result := True;
end;

procedure TScintEdit.Redo;
begin
Call(SCI_REDO, 0, 0);
Expand Down Expand Up @@ -1315,7 +1319,6 @@ procedure TScintEdit.ScrollCaretIntoView;
Call(SCI_SCROLLCARET, 0, 0);
end;


procedure TScintEdit.SelectAllOccurrences(const Options: TScintFindOptions);
{ At the moment this does not automatically expand folds, unlike VSCode. Also
see SelectNextOccurrence. }
Expand Down Expand Up @@ -1456,7 +1459,7 @@ procedure TScintEdit.SetCaretVirtualSpace(const Value: Integer);
end;
end;

procedure TScintEdit.SetChangeHistory(const Value: Boolean);
procedure TScintEdit.SetChangeHistory(const Value: TScintChangeHistory);
begin
if FChangeHistory <> Value then begin
FChangeHistory := Value;
Expand Down
6 changes: 3 additions & 3 deletions Projects/Src/CompForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ function TCompileForm.InitializeMemoBase(const Memo: TCompScintEdit; const Popup
function TCompileForm.InitializeFileMemo(const Memo: TCompScintFileEdit; const PopupMenu: TPopupMenu): TCompScintFileEdit;
begin
InitializeMemoBase(Memo, PopupMenu);
Memo.ChangeHistory := True;
Memo.ChangeHistory := schMarkers;
Memo.CompilerFileIndex := UnknownCompilerFileIndex;
Memo.ErrorLine := -1;
Memo.StepLine := -1;
Expand Down Expand Up @@ -3332,7 +3332,7 @@ procedure TCompileForm.UpdateOccurrenceIndicators(const AMemo: TCompScintEdit);
const TextToFind: TScintRawString; const Options: TScintFindOptions;
const SelectionRanges, IndicatorRanges: TScintRangeList);
begin
if ScintRawStringIsBlank(TextToFind) then
if TScintEdit.RawStringIsBlank(TextToFind) then
Exit;

var StartPos := 0;
Expand Down Expand Up @@ -4568,7 +4568,7 @@ procedure TCompileForm.MemoCharAdded(Sender: TObject; Ch: AnsiChar);
function LineIsBlank(const Line: Integer): Boolean;
begin
var S := FActiveMemo.Lines.RawLines[Line];
Result := ScintRawStringIsBlank(S);
Result := TScintEdit.RawStringIsBlank(S);
end;

var
Expand Down
2 changes: 1 addition & 1 deletion Projects/Src/CompScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ procedure TCompScintEdit.UpdateMarginsAndSquigglyWidths(const IconMarkersWidth,
Call(SCI_SETMARGINWIDTHN, mmIcons, IconMarkersWidth);

var ChangeHistoryWidth: Integer;
if ChangeHistory then
if ChangeHistory <> schDisabled then
ChangeHistoryWidth := BaseChangeHistoryWidth
else
ChangeHistoryWidth := 0; { Current this is just the preprocessor output memo }
Expand Down
5 changes: 4 additions & 1 deletion whatsnew.htm
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@
<li>Left, Right, etc. navigation with rectangular selection is now allowed.</li>
<li>When autocompleting with multiple selections present, the autocompleted text now goes into each selection.</li>
</ul>
<p>Other changes:</p>
<p>Other editor changes:</p>
<ul>
<li>The editor's gutter now shows change history to keep track of saved and unsaved modifications.</li>
<li>The editor's gutter now shows fold icons to temporarily hide and show sections.</li>
<li>The editor's font now defaults to Consolas if available, consistent with most other editors.</li>
<li>The editor can now be scrolled horizontally instead of vertically by holding the Shift key while rotating the mouse wheel. Horizontal scroll wheels are now also supported.</li>
<li>Added shortcuts to move selected lines up or down (Alt+Up and Alt+Down).</li>
<li>Added a right-click popup menu to the editor's gutter column for breakpoints.</li>
</ul>
<p>Other changes:</p>
<ul>
<li>Moved the list of recently opened files into a new <i>Open Recent</i> submenu of the <i>Files</i> menu.</li>
<li>Minor tweaks and documentation improvements.</li>
</ul>
Expand Down

0 comments on commit 60ccc49

Please sign in to comment.