Skip to content

Commit

Permalink
Add shortcuts to fold and unfold.
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnlaan committed Jun 22, 2024
1 parent cc812b8 commit 86fe1c9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
14 changes: 14 additions & 0 deletions Components/ScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ TScintEdit = class(TWinControl)
const Options: TScintFindOptions; out MatchRange: TScintRange): Boolean;
function FindText(const StartPos, EndPos: Integer; const S: String;
const Options: TScintFindOptions; out MatchRange: TScintRange): Boolean;
procedure FoldLine(const Line: Integer; const Fold: Boolean);
function FormatRange(const Draw: Boolean;
const RangeToFormat: PScintRangeToFormat): Integer;
procedure ForceModifiedState;
Expand Down Expand Up @@ -849,6 +850,19 @@ function TScintEdit.FindText(const StartPos, EndPos: Integer; const S: String;
Options, MatchRange);
end;

procedure TScintEdit.FoldLine(const Line: Integer; const Fold: Boolean);
begin
FLines.CheckIndexRange(Line);
{ If the line is not part of a fold the following will return False }
var Folded := Call(SCI_GETFOLDEXPANDED, Line, 0) = 0;
if Fold <> Folded then begin
{ If the line is not part of a fold the following will do nothing
and else if the line is not the header Scintilla will lookup the
header for us }
Call(SCI_TOGGLEFOLD, Line, 0);
end;
end;

procedure TScintEdit.ForceModifiedState;
begin
if not FForceModified then begin
Expand Down
6 changes: 6 additions & 0 deletions ISHelp/isetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3269,6 +3269,12 @@ Filename: "{win}\MYPROG.INI"; Section: "InstallSettings"; Key: "InstallPath"; St
<tr>
<td>Select all.</td><td>Ctrl+A or Ctrl+Click on line number</td>
</tr>
<tr>
<td>Fold line.</td><td>Ctrl+Shift+[</td>
</tr>
<tr>
<td>Unfold line.</td><td>Ctrl+Shift+]</td>
</tr>
<tr>
<td>Complete word.</td><td>Ctrl+Space or Ctrl+I or<br />Alt+Right if the Visual Studio menu key map is active</td>
</tr>
Expand Down
2 changes: 2 additions & 0 deletions Projects/Src/CompForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,8 @@ procedure TCompileForm.MemoKeyDown(Sender: TObject; var Key: Word;
ESelectAllOccurrencesClick(Self);
ccSelectAllFindMatches:
ESelectAllFindMatchesClick(Self);
ccUnfoldLine, ccFoldLine:
FActiveMemo.FoldLine(FActiveMemo.CaretLine, ComplexCommand = ccFoldLine);
ccSimplifySelection:
begin
{ The built in Esc (SCI_CANCEL) simply drops all additional selections
Expand Down
5 changes: 4 additions & 1 deletion Projects/Src/CompScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ interface
{ Commands which require more than 1 parameterless SCI_XXXXX and need help
from the container }
TCompScintComplexCommand = (ccNone, ccSelectNextOccurrence,
ccSelectAllOccurrences, ccSelectAllFindMatches, ccSimplifySelection);
ccSelectAllOccurrences, ccSelectAllFindMatches, ccSimplifySelection,
ccUnfoldLine, ccFoldLine);

TCompScintEdit = class(TScintEdit)
private
Expand Down Expand Up @@ -415,6 +416,8 @@ procedure TCompScintEdit.UpdateComplexCommands;

AddComplexCommand(ShortCut(VK_RETURN, [ssAlt]), ccSelectAllFindMatches);
AddComplexCommand(ShortCut(VK_ESCAPE, []), ccSimplifySelection);
AddComplexCommand(ShortCut(VK_OEM_6, [ssShift, ssCtrl]), ccUnfoldLine);
AddComplexCommand(ShortCut(VK_OEM_4, [ssShift, ssCtrl]), ccFoldLine);
end;

procedure TCompScintEdit.SetUseFolding(const Value: Boolean);
Expand Down
4 changes: 2 additions & 2 deletions whatsnew.htm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</ul>
<p>Other editor changes:</p>
<ul>
<li>Added new <i>Enable section folding</i> option which allows you to temporarily hide sections while editing. Enabled by default.</li>
<li>Added new <i>Enable section folding</i> option which allows you to temporarily hide sections while editing by clicking the new minus or plus icons in the editor's gutter or by using the new keyboard shortcuts (Ctrl+Shift+[ to fold and Ctrl+Shift+] to unfold). Enabled by default.</li>
<li>The editor's gutter now shows change history to keep track of saved and unsaved modifications.</li>
<li>The editor's font now defaults to Consolas if available, consistent with most other modern 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>
Expand All @@ -61,7 +61,7 @@
<li>Added shortcuts to select a tab (Ctrl+1 through Ctrl+9).</li>
<li>Added new <i>Word Wrap</i> menu item to the <i>View</i> menu (Alt+Z).</li>
<li>Added shortcut to the <i>Options</i> menu item in the <i>Tools</i> menu (Ctrl+,).</li>
<li>Minor tweaks and documentation improvements.</li>
<li>Minor tweaks and documentation improvements, including an update of the <a href="https://jrsoftware.org/ishelp/index.php?topic=compformshortcuts">Compiler IDE Keyboard And Mouse Commands</a> help topic.</li>
</ul>

<p>Contributions via <a href="https://github.com/jrsoftware/issrc" target="_blank">GitHub</a>: Thanks to Sergii Leonov for their contributions.</p>
Expand Down

0 comments on commit 86fe1c9

Please sign in to comment.