Skip to content

Commit

Permalink
A better editing flow for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
rberenguel committed Nov 10, 2024
1 parent 7049181 commit 715fb02
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
*.md
*.md
local_*
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ is. Everything is in this folder (except for backgrounds).
I will add some more documentation of the functions you can use at some point, but they should be pretty
descriptive.

Note that `index.html` points to `local_main.js`, which is gitignored. This is because I pass my local basepath
so I can edit tasks with VS Code. Other than that, it is exactly the same as `main.js`.

## <a name='Safari'></a>Safari?

[Extension auto-porting](https://developer.apple.com/documentation/safariservices/converting-a-web-extension-for-safari),
Expand Down
2 changes: 0 additions & 2 deletions backgrounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ const backgrounds = [
"bubbles.jpg",
"flows-78259.jpg",
"creation.jpg",
"big-bang.jpg",
"underwater.jpg",
];
Binary file removed backgrounds/big-bang.jpg
Binary file not shown.
Binary file removed backgrounds/underwater.jpg
Binary file not shown.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
<script src="lib/linkUtils.js"></script>
<script src="timezones.js"></script>
<script src="backgrounds.js"></script>
<script src="main.js"></script>
<script src="local_main.js"></script>
</html>
28 changes: 25 additions & 3 deletions lib/taskUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ prio: 12
*/

function textToTaskObject(text) {
function textToTaskObject(text, hPos = 0, filepath) {
const lines = text.split("\n");
let obj = {};
obj._hPos = hPos;
obj._filepath = filepath;
let settings = false;
let projects = false;
for (let i = 0; i < lines.length; i++) {
Expand Down Expand Up @@ -204,7 +206,9 @@ function textToTaskObject(text) {
return obj;
}

function tasksFromMarkdown(paths, cb) {
function tasksFromMarkdown(paths, cb, basepath) {
// By providing a basepath, shift + right clicking on the task opens VS Code at the
// exact task heading
const promises = [];

// Handle single string or array of strings
Expand All @@ -218,10 +222,22 @@ function tasksFromMarkdown(paths, cb) {
.then((response) => response.text())
.then((markdown) => {
let tasks = [];
const headingLineNumbers = markdown
.split("\n")
.map((line, index) => (line.startsWith("#") ? index + 1 : null))
.filter((number) => number !== null);
const blocks = markdown.split(/---/);
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i];
const obj = textToTaskObject(block);
let obj = textToTaskObject(block, (hPos = headingLineNumbers[i]));
if (basepath) {
obj = textToTaskObject(
block,
(hPos = headingLineNumbers[i]),
(filepath = basepath + path),
);
}

if (!obj._valid) {
tasks.push({
text: `Error loading task ${i} from file ${path}`,
Expand Down Expand Up @@ -373,6 +389,12 @@ function addTasksToDiv(_tasks, targetDivId) {
taskExtra.innerHTML = extra;
taskTitle.addEventListener("contextmenu", (e) => {
e.preventDefault();
if (e.shiftKey) {
if (task._filepath) {
window.open(`vscode://file/${task._filepath}:${task._hPos}`);
}
return;
}
const allRows = Array.from(document.querySelectorAll(".taskRow"));
let skip = false;
if (taskWrapper.classList.contains("highlight")) {
Expand Down

0 comments on commit 715fb02

Please sign in to comment.