Skip to content

Commit

Permalink
Add new Show whitespace option.
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnlaan committed Nov 20, 2024
1 parent badba1f commit 51d663f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
12 changes: 8 additions & 4 deletions Projects/Src/IDE.IDEScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ TIDEScintEdit = class(TScintEdit)
function GetRectExtendShiftState(const Desired: Boolean): TShiftState;
procedure UpdateIndicators(const Ranges: TScintRangeList;
const IndicatorNumber: TIDEScintIndicatorNumber);
procedure UpdateMarginsAndSquigglyAndCaretWidths(const IconMarkersWidth,
procedure UpdateWidthsAndSizes(const IconMarkersWidth,
BaseChangeHistoryWidth, BaseFolderMarkersWidth, LeftBlankMarginWidth,
RightBlankMarginWidth, SquigglyWidth, CaretWidth: Integer);
RightBlankMarginWidth, SquigglyWidth, CaretWidth, WhiteSpaceSize: Integer);
procedure UpdateThemeColorsAndStyleAttributes;
published
property KeyMappingType: TIDEScintKeyMappingType read FKeyMappingType write SetKeyMappingType default kmtDefault;
Expand Down Expand Up @@ -436,9 +436,9 @@ procedure TIDEScintEdit.UpdateIndicators(const Ranges: TScintRangeList;
end;
end;

procedure TIDEScintEdit.UpdateMarginsAndSquigglyAndCaretWidths(const IconMarkersWidth,
procedure TIDEScintEdit.UpdateWidthsAndSizes(const IconMarkersWidth,
BaseChangeHistoryWidth, BaseFolderMarkersWidth, LeftBlankMarginWidth,
RightBlankMarginWidth, SquigglyWidth, CaretWidth: Integer);
RightBlankMarginWidth, SquigglyWidth, CaretWidth, WhiteSpaceSize: Integer);
begin
Call(SCI_SETMARGINWIDTHN, mmIcons, IconMarkersWidth);

Expand All @@ -463,6 +463,8 @@ procedure TIDEScintEdit.UpdateMarginsAndSquigglyAndCaretWidths(const IconMarkers
Call(SCI_INDICSETSTROKEWIDTH, minSquiggly, SquigglyWidth);

Call(SCI_SETCARETWIDTH, CaretWidth, 0);

Call(SCI_SETWHITESPACESIZE, WhiteSpaceSize, 0);
end;

procedure TIDEScintEdit.UpdateThemeColorsAndStyleAttributes;
Expand Down Expand Up @@ -491,6 +493,8 @@ procedure TIDEScintEdit.UpdateThemeColorsAndStyleAttributes;
Call(SCI_SETELEMENTCOLOUR, SC_ELEMENT_SELECTION_INACTIVE_BACK, SelBackColor);
Call(SCI_SETELEMENTCOLOUR, SC_ELEMENT_SELECTION_INACTIVE_ADDITIONAL_BACK, SelBackColor);

Call(SCI_SETELEMENTCOLOUR, SC_ELEMENT_WHITE_SPACE, FTheme.Colors[tcIndentGuideFore] or (SC_ALPHA_OPAQUE shl 24));

Call(SCI_SETELEMENTCOLOUR, SC_ELEMENT_FOLD_LINE, FTheme.Colors[tcIndentGuideFore] or (70 shl 24));
Call(SCI_SETFOLDMARGINCOLOUR, Ord(True), FTheme.Colors[tcBack]);
Call(SCI_SETFOLDMARGINHICOLOUR, Ord(True), FTheme.Colors[tcBack]);
Expand Down
12 changes: 10 additions & 2 deletions Projects/Src/IDE.MainForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ TMainForm = class(TUIStateForm)
CursorPastEOL: Boolean;
TabWidth: Integer;
UseTabCharacter: Boolean;
ShowWhiteSpace: Boolean;
UseFolding: Boolean;
FindRegEx: Boolean;
WordWrap: Boolean;
Expand Down Expand Up @@ -850,6 +851,7 @@ constructor TMainForm.Create(AOwner: TComponent);
FOptions.CursorPastEOL := Ini.ReadBool('Options', 'EditorCursorPastEOL', False);
FOptions.TabWidth := Ini.ReadInteger('Options', 'TabWidth', 2);
FOptions.UseTabCharacter := Ini.ReadBool('Options', 'UseTabCharacter', False);
FOptions.ShowWhiteSpace := Ini.ReadBool('Options', 'ShowWhiteSpace', False);
FOptions.UseFolding := Ini.ReadBool('Options', 'UseFolding', True);
FOptions.FindRegEx := Ini.ReadBool('Options', 'FindRegEx', False);
FOptions.WordWrap := Ini.ReadBool('Options', 'WordWrap', False);
Expand Down Expand Up @@ -2456,12 +2458,14 @@ procedure TMainForm.CompileFile(AFilename: String; const ReadFromFile: Boolean);
procedure TMainForm.SyncEditorOptions;
const
SquigglyStyles: array[Boolean] of Integer = (INDIC_HIDDEN, INDIC_SQUIGGLE);
WhiteSpaceStyles: array[Boolean] of Integer = (SCWS_INVISIBLE, SCWS_VISIBLEALWAYS);
var
Memo: TIDEScintEdit;
begin
for Memo in FMemos do begin
Memo.UseStyleAttributes := FOptions.UseSyntaxHighlighting;
Memo.Call(SCI_INDICSETSTYLE, minSquiggly, SquigglyStyles[FOptions.UnderlineErrors]);
Memo.Call(SCI_SETVIEWWS, WhiteSpaceStyles[FOptions.ShowWhiteSpace], 0);

if FOptions.CursorPastEOL then
Memo.VirtualSpaceOptions := [svsRectangularSelection, svsUserAccessible, svsNoWrapLineStart]
Expand Down Expand Up @@ -4250,10 +4254,11 @@ procedure TMainForm.UpdateMarginsAndSquigglyAndCaretWidths;
var LeftBlankMarginWidth := ToCurrentPPI(2); { 2 pixel margin between gutter and the main text }
var SquigglyWidth := ToCurrentPPI(100); { 100 = 1 pixel }
var CaretWidth := ToCurrentPPI(2);
var WhiteSpaceSize := CaretWidth;

for var Memo in FMemos do
Memo.UpdateMarginsAndSquigglyAndCaretWidths(IconMarkersWidth, BaseChangeHistoryWidth,
FolderMarkersWidth, LeftBlankMarginWidth, 0, SquigglyWidth, CaretWidth);
Memo.UpdateWidthsAndSizes(IconMarkersWidth, BaseChangeHistoryWidth, FolderMarkersWidth,
LeftBlankMarginWidth, 0, SquigglyWidth, CaretWidth, WhiteSpaceSize);
end;

procedure TMainForm.SplitPanelMouseMove(Sender: TObject;
Expand Down Expand Up @@ -4407,6 +4412,7 @@ procedure TMainForm.TOptionsClick(Sender: TObject);
OptionsForm.CursorPastEOLCheck.Checked := FOptions.CursorPastEOL;
OptionsForm.TabWidthEdit.Text := IntToStr(FOptions.TabWidth);
OptionsForm.UseTabCharacterCheck.Checked := FOptions.UseTabCharacter;
OptionsForm.ShowWhiteSpaceCheck.Checked := FOptions.ShowWhiteSpace;
OptionsForm.UseFoldingCheck.Checked := FOptions.UseFolding;
OptionsForm.AutoIndentCheck.Checked := FOptions.AutoIndent;
OptionsForm.IndentationGuidesCheck.Checked := FOptions.IndentationGuides;
Expand Down Expand Up @@ -4440,6 +4446,7 @@ procedure TMainForm.TOptionsClick(Sender: TObject);
FOptions.CursorPastEOL := OptionsForm.CursorPastEOLCheck.Checked;
FOptions.TabWidth := StrToInt(OptionsForm.TabWidthEdit.Text);
FOptions.UseTabCharacter := OptionsForm.UseTabCharacterCheck.Checked;
FOptions.ShowWhiteSpace := OptionsForm.ShowWhiteSpaceCheck.Checked;
FOptions.UseFolding := OptionsForm.UseFoldingCheck.Checked;
FOptions.AutoIndent := OptionsForm.AutoIndentCheck.Checked;
FOptions.IndentationGuides := OptionsForm.IndentationGuidesCheck.Checked;
Expand Down Expand Up @@ -4489,6 +4496,7 @@ procedure TMainForm.TOptionsClick(Sender: TObject);
Ini.WriteBool('Options', 'EditorCursorPastEOL', FOptions.CursorPastEOL);
Ini.WriteInteger('Options', 'TabWidth', FOptions.TabWidth);
Ini.WriteBool('Options', 'UseTabCharacter', FOptions.UseTabCharacter);
Ini.WriteBool('Options', 'ShowWhiteSpace', FOptions.ShowWhiteSpace);
Ini.WriteBool('Options', 'UseFolding', FOptions.UseFolding);
Ini.WriteBool('Options', 'AutoIndent', FOptions.AutoIndent);
Ini.WriteBool('Options', 'IndentationGuides', FOptions.IndentationGuides);
Expand Down
12 changes: 10 additions & 2 deletions Projects/Src/IDE.OptionsForm.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ object OptionsForm: TOptionsForm
object Label3: TNewStaticText
Left = 8
Top = 243
Width = 45
Width = 56
Height = 14
Caption = 'Menu &keys:'
FocusControl = KeyMappingComboBox
Expand Down Expand Up @@ -316,7 +316,7 @@ object OptionsForm: TOptionsForm
object Label5: TNewStaticText
Left = 8
Top = 243
Width = 45
Width = 27
Height = 14
Caption = 'Ke&ys:'
FocusControl = MemoKeyMappingComboBox
Expand All @@ -330,6 +330,14 @@ object OptionsForm: TOptionsForm
Style = csDropDownList
TabOrder = 12
end
object ShowWhiteSpaceCheck: TCheckBox
Left = 120
Top = 338
Width = 120
Height = 17
Caption = 'Show whitespace'
TabOrder = 20
end
end
object OKButton: TButton
Left = 428
Expand Down
1 change: 1 addition & 0 deletions Projects/Src/IDE.OptionsForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ TOptionsForm = class(TUIStateForm)
HighlightSelTextOccurrencesCheck: TCheckBox;
Label5: TNewStaticText;
MemoKeyMappingComboBox: TComboBox;
ShowWhiteSpaceCheck: TCheckBox;
procedure AssocButtonClick(Sender: TObject);
procedure ChangeFontButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
Expand Down
1 change: 1 addition & 0 deletions whatsnew.htm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<li>Moved the <i>Word Wrap</i> option to the <i>View</i> menu and added a shortcut for it (Alt+Z).</li>
<li>Added a right-click popup menu to the editor's gutter column for breakpoints.</li>
<li>Added dark mode support to autocompletion lists and also added a minimum width.</li>
<li>Added new <i>Show whitespace</i> option. Disabled by default.</li>
<li>Improved brace highlighting.</li>
<li>Fixed an issue when the <i>Auto indent mode</i> and <i>Allow cursor to move beyond end of lines</i> options are both enabled.</li>
</ul>
Expand Down

0 comments on commit 51d663f

Please sign in to comment.