Skip to content

Commit

Permalink
added ctrl k to sort todo lists
Browse files Browse the repository at this point in the history
  • Loading branch information
FRex committed Nov 22, 2021
1 parent 62f21d9 commit f0f5dec
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
7 changes: 7 additions & 0 deletions allnotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15987,6 +15987,13 @@ Ctrl + O - open URL or hashtag that's selected or (if nothing's selected) under

Ctrl + F when in main text area will open a simple search

Ctrl + K - sorts a TODO list (putting done at the end), try:
[ ] item 1
[x] item 2
[x] item 3
[ ] item 4
[x] item 5

Double click on status bar to open the directory Botes is in.

Create old directory there to get a duplicate of every saved file.
Expand Down
6 changes: 5 additions & 1 deletion mainunit.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,14 @@ object Form1: TForm1
item
Command = ecUserDefined0
ShortCut = 16452
end
end
item
Command = ecUserDefined1
ShortCut = 16463
end
item
Command = ecUserDefined2
ShortCut = 16459
end>
MouseActions = <>
MouseTextActions = <>
Expand Down
57 changes: 57 additions & 0 deletions mainunit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ TForm1 = class(TForm)
procedure MoveCursorToNextFind;
procedure SaveCaretAndView(tabindex: integer);
procedure LoadCaretAndView(tabindex: integer);
procedure SortTodoListAroundCurrentLine;
{ private declarations }
public
{ public declarations }
Expand Down Expand Up @@ -514,6 +515,62 @@ procedure TForm1.TextEditorCommandProcessed(Sender: TObject;

end; //if command is user defined first + 1

if Command = (ecUserDefinedFirst + 2) then
SortTodoListAroundCurrentLine;
end;

function IsTodoLine(line: string): boolean;
begin
Exit((line.Substring(0, 3) = '[ ]') or (line.Substring(0, 3) = '[x]'));
end;

procedure TForm1.SortTodoListAroundCurrentLine;
var
firstTodo, lastTodo, cur: integer;
completed, pending: TStringList;
line: string;
begin
if not IsTodoLine(TextEditor.Lines[TextEditor.CaretY - 1]) then
Exit;

for cur := TextEditor.CaretY - 1 downto 0 do
begin
if not IsTodoLine(TextEditor.Lines[cur]) then
break;
firstTodo := cur;
end;

for cur := TextEditor.CaretY - 1 to TextEditor.Lines.Count - 1 do
begin
if not IsTodoLine(TextEditor.Lines[cur]) then
break;
lastTodo := cur;
end;

completed := TStringList.Create;
pending := TStringList.Create;

for cur := firstTodo to lastTodo do
if TextEditor.Lines[cur][2] = 'x' then
completed.Append(TextEditor.Lines[cur])
else
pending.Append(TextEditor.Lines[cur]);

TextEditor.BeginUpdate;
for cur := firstTodo to lastTodo do
begin
if (cur - firstTodo) < pending.Count then
line := pending[cur - firstTodo]
else
line := completed[cur - firstTodo - pending.Count];

TextEditor.TextBetweenPoints[TPoint.Create(0, cur + 1),
TPoint.Create(maxLongint, cur + 1)] := line;
end;
TextEditor.EndUpdate;

completed.Free;
pending.Free;
end;

procedure TForm1.TextEditorEnter(Sender: TObject);
Expand Down

0 comments on commit f0f5dec

Please sign in to comment.