Skip to content

Commit

Permalink
Add support for specifying line number when opening a file in single …
Browse files Browse the repository at this point in the history
…instance mode (#3384)
  • Loading branch information
AJenbo authored Jun 1, 2024
1 parent 341bd2e commit c2ea981
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions LiteEditor/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,11 @@ bool CodeLiteApp::IsSingleInstance(const wxCmdLineParser& m_parser)

JSON json(cJSON_Object);
json.toElement().addProperty("args", files);

long lineNumber(0);
m_parser.Found(wxT("l"), &lineNumber);
json.toElement().addProperty("lineno", lineNumber);

client.WriteMessage(json.toElement().format());
return false;

Expand Down
8 changes: 7 additions & 1 deletion LiteEditor/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3954,7 +3954,13 @@ void clMainFrame::OnSingleInstanceOpenFiles(clCommandEvent& e)
OnSwitchWorkspace(workspaceEvent);

} else {
GetMainBook()->OpenFile(files.Item(i), wxEmptyString);
long lineNumber = e.GetLineNumber();
if (lineNumber > 0) {
lineNumber--;
} else {
lineNumber = 0;
}
GetMainBook()->OpenFile(files.Item(i), wxEmptyString, lineNumber);
}
}

Expand Down
2 changes: 2 additions & 0 deletions LiteEditor/singleinstancethreadjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ void* clSingleInstanceThread::Entry()
} else {
clCommandEvent event(wxEVT_CMD_SINGLE_INSTANCE_THREAD_OPEN_FILES);
event.SetStrings(args);
long lineno = root.toElement().namedObject("lineno").toInt();
event.SetLineNumber(lineno);
EventNotifier::Get()->AddPendingEvent(event);
}
}
Expand Down

0 comments on commit c2ea981

Please sign in to comment.