Browse Source

Add new Show whitespace option.

Martijn Laan 9 months ago
parent
commit
51d663f2ea

+ 8 - 4
Projects/Src/IDE.IDEScintEdit.pas

@@ -101,9 +101,9 @@ type
     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;
@@ -436,9 +436,9 @@ begin
   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);
 
@@ -463,6 +463,8 @@ begin
   Call(SCI_INDICSETSTROKEWIDTH, minSquiggly, SquigglyWidth);
 
   Call(SCI_SETCARETWIDTH, CaretWidth, 0);
+
+  Call(SCI_SETWHITESPACESIZE, WhiteSpaceSize, 0);
 end;
 
 procedure TIDEScintEdit.UpdateThemeColorsAndStyleAttributes;
@@ -491,6 +493,8 @@ begin
     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]);

+ 10 - 2
Projects/Src/IDE.MainForm.pas

@@ -424,6 +424,7 @@ type
       CursorPastEOL: Boolean;
       TabWidth: Integer;
       UseTabCharacter: Boolean;
+      ShowWhiteSpace: Boolean;
       UseFolding: Boolean;
       FindRegEx: Boolean;
       WordWrap: Boolean;
@@ -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);
@@ -2456,12 +2458,14 @@ end;
 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]
@@ -4250,10 +4254,11 @@ begin
   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;
@@ -4407,6 +4412,7 @@ begin
     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;
@@ -4440,6 +4446,7 @@ begin
     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;
@@ -4489,6 +4496,7 @@ begin
       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);

+ 10 - 2
Projects/Src/IDE.OptionsForm.dfm

@@ -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
@@ -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
@@ -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

+ 1 - 0
Projects/Src/IDE.OptionsForm.pas

@@ -57,6 +57,7 @@ type
     HighlightSelTextOccurrencesCheck: TCheckBox;
     Label5: TNewStaticText;
     MemoKeyMappingComboBox: TComboBox;
+    ShowWhiteSpaceCheck: TCheckBox;
     procedure AssocButtonClick(Sender: TObject);
     procedure ChangeFontButtonClick(Sender: TObject);
     procedure FormCreate(Sender: TObject);

+ 1 - 0
whatsnew.htm

@@ -68,6 +68,7 @@ For conditions of distribution and use, see <a href="files/is/license.txt">LICEN
   <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>