Skip to content

Commit

Permalink
added ctrl plus o opening urls or hashtags
Browse files Browse the repository at this point in the history
  • Loading branch information
FRex committed Mar 1, 2021
1 parent ce2b321 commit 89090db
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ the first instance properly (just how programs like VLC, Notepad++ and VS Code d
* Ctrl + F - use find (beware - it's quite crude).
* Ctrl + D - toggle between `[ ]` and `[x]` at the start of the line (for TODO lists).
* Double click on status bar - open directory `Botes` is in.
* Ctrl + O - open URL or hashtag that's selected or (if nothing's selected) under cursor


# Font
Expand Down
1 change: 1 addition & 0 deletions allnotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15983,6 +15983,7 @@ Ctrl + T - open a new tab.
Ctrl + Shift + T - undo closing last tab.
Ctrl + W - close current tab.
Ctrl + D - (for TODO lists), toggle between [ ] and [x] if current line starts with either.
Ctrl + O - open URL or hashtag that's selected or (if nothing's selected) under cursor

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

Expand Down
4 changes: 4 additions & 0 deletions mainunit.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ object Form1: TForm1
item
Command = ecUserDefined0
ShortCut = 16452
end
item
Command = ecUserDefined1
ShortCut = 16463
end>
MouseActions = <>
MouseTextActions = <>
Expand Down
95 changes: 73 additions & 22 deletions mainunit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ TForm1 = class(TForm)
procedure UndoCloseTabActionExecute(Sender: TObject);
procedure UniqueInstance1OtherInstance(Sender: TObject;
ParamCount: integer; const Parameters: array of string);
procedure SelectOrAddTab(const query: string);
procedure OpenShortcutFile(const fname: string);
private
FAllLines, FDiscardedLines, FAllTags, FTabCaretsAndViews: TStringList;
Expand Down Expand Up @@ -209,6 +210,23 @@ function GetOldDirSize: string;
list.Free;
end;

function GetWordTouchingCursor(const line: string; idx: integer): string;
var
tmp: string;
start, ending: integer;
begin
tmp := ' ' + line + ' ';
start := idx + 1;
ending := idx + 1;
while tmp[start - 1] <> ' ' do
start := start - 1;

while tmp[ending] <> ' ' do
ending := ending + 1;

Result := Copy(tmp, start, ending - start);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
caretmarkup: TSynEditMarkupHighlightAllCaret;
Expand Down Expand Up @@ -448,10 +466,10 @@ procedure TForm1.SuggestionsKeyDown(Sender: TObject; var Key: word; Shift: TShif
procedure TForm1.TextEditorCommandProcessed(Sender: TObject;
var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer);
var
mark: string;
mark, word, line, url: string;
a, b: TPoint;
begin
if Command = ecUserDefinedFirst then
if Command = (ecUserDefinedFirst + 0) then
begin
a.Create(1, TextEditor.CaretY);
b.Create(4, TextEditor.CaretY);
Expand All @@ -466,6 +484,36 @@ procedure TForm1.TextEditorCommandProcessed(Sender: TObject;
if mark = '[x]' then
TextEditor.TextBetweenPoints[a, b] := '[ ]';
end;

if Command = (ecUserDefinedFirst + 1) then
begin
url := '';

//if anything is selected try to open it, otherwise open 'word' near cursor
if TextEditor.SelText <> '' then
url := TextEditor.SelText
else
begin
line := TextEditor.Lines[TextEditor.CaretY - 1];
if (Length(line) + 1) >= TextEditor.CaretX then
begin
word := GetWordTouchingCursor(line, TextEditor.CaretX);

//looking for substring :/ catches absolute Windows paths (with forward
//slashes) and URLs, looking for starting / catches absolute Linux paths
//starting with hashtag is to catch links to other notes within the app
if (Pos(':/', word) <> 0) or word.StartsWith('/') or word.StartsWith('#') then
url := word;
end;
end;

if url.StartsWith('#') then
SelectOrAddTab(Copy(url, 2, Length(url) + 100))
else if url <> '' then
OpenUrl(url);

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

end;

procedure TForm1.TextEditorEnter(Sender: TObject);
Expand Down Expand Up @@ -582,32 +630,35 @@ procedure TForm1.UniqueInstance1OtherInstance(Sender: TObject;
Application.BringToFront;
end;

procedure TForm1.OpenShortcutFile(const fname: string);
procedure TForm1.SelectOrAddTab(const query: string);
var
i: integer;
begin
if query = '' then
Exit;

//backwards to select rightmost tab if there are duplicates
for i := (MainTabs.Tabs.Count - 1) downto 0 do
begin
if MainTabs.Tabs[i] = query then
begin
MainTabs.TabIndex := i;
Exit;
end;
end; //for

//if above loop didn't find and select a tab we must add it
MainTabs.Tabs.Append(query);
MainTabs.TabIndex := MainTabs.Tabs.Count - 1;
end;

procedure TForm1.OpenShortcutFile(const fname: string);
var
shortcutquery: string;
shortcutqueryopen: boolean;
begin
try
shortcutquery := LoadQueryFromShortcutFile(fname);
shortcutqueryopen := False;
if shortcutquery <> '' then
begin
for i := 0 to MainTabs.Tabs.Count - 1 do
begin
if MainTabs.Tabs[i] = shortcutquery then
begin
MainTabs.TabIndex := i;
shortcutqueryopen := True;
end;
end; //for

if not shortcutqueryopen then
begin
MainTabs.Tabs.Append(shortcutquery);
MainTabs.TabIndex := MainTabs.Tabs.Count - 1;
end;
end; //if shortcutquery <> '' then
SelectOrAddTab(shortcutquery);
except
on EFOpenError do
MessageDlg('File not found', Format('Failed to open shortcut file: %s', [fname]),
Expand Down
Binary file modified sshots/sshot0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 89090db

Please sign in to comment.