feat: button return to note selection from journal entry selection

This commit is contained in:
2026-06-02 14:03:05 +02:00
parent 2a8392ac2e
commit e666ca32de
3 changed files with 26 additions and 14 deletions
+19 -11
View File
@@ -695,24 +695,32 @@ backup_config_end:
int *journalWasUpdated = malloc(sizeof(int));
*journalWasUpdated = 0;
// used to go back to note selection
int *returnNoteSelection = malloc(sizeof(int));
*returnNoteSelection = 0;
if (!regexReturn) { // if the regex matches -> it's a journal
debug("%s is a journal. Updating it...", noteSelected);
fullPath = updateJournal(fullPath, noteSelected, timeFormat, journalWasUpdated,
fullPath = updateJournal(fullPath, noteSelected, timeFormat, journalWasUpdated, returnNoteSelection,
shouldDebug); // we return the path. As if it is a divided journal we
// must point to the correct entry
}
if (newLineOnOpening) {
if (*journalWasUpdated) {
appendToFile(fullPath, "\n",
shouldDebug); // when updating the journal it adds a \n char at the
// end. So appendToFile(\n) does not work. We append a
// (special and rare) whitespace character + \n to
// bypass this issue.
if (!*returnNoteSelection) { // if we don't need to return to the note selection
if (newLineOnOpening) {
if (*journalWasUpdated) {
appendToFile(fullPath, "\n",
shouldDebug); // when updating the journal it adds a \n char at the
// end. So appendToFile(\n) does not work. We append a
// (special and rare) whitespace character + \n to
// bypass this issue.
}
appendToFile(fullPath, "\n", shouldDebug);
}
appendToFile(fullPath, "\n", shouldDebug);
openEditor(fullPath, editorToOpen, shouldRender, shouldJumpToEnd, shouldDebug);
free(fullPath);
}
openEditor(fullPath, editorToOpen, shouldRender, shouldJumpToEnd, shouldDebug);
free(fullPath);
free(returnNoteSelection);
} else if (strcmp(noteSelected, "Create new note") == 0) {
note_creation:
noteSelected = createNewNote(notesDirectoryString, vaultSelected, bypassSelectionNote, bypassSelectionNoteValue, journalRegex, shouldDebug);
+5 -2
View File
@@ -188,7 +188,7 @@ char **getVaultsFromDirectories(char **directoryStringArray, int directoryNumber
return vaultsArray;
}
char *updateJournal(char *path, char *journal, char *timeFormat, int *journalWasUpdated, int shouldDebug) {
char *updateJournal(char *path, char *journal, char *timeFormat, int *journalWasUpdated, int *returnNoteSelection, int shouldDebug) {
path[PATH_MAX] = '\0'; // it assures it is a string (Most cases this does nothing). But rewriting at least
// one bytes make the compile happy. He doesn't want to return an unchanged input.
debug("Handling the journal %s", path);
@@ -221,13 +221,14 @@ char *updateJournal(char *path, char *journal, char *timeFormat, int *journalWas
that the Create new entry in journal is on top entryArray = realloc(entryArray,
sizeof(char*));*/
// simpler to just malloc 2 and later realloc
const int extraOptions = 3;
const int extraOptions = 4;
char **entryArray = malloc(extraOptions * sizeof(char *));
char *createEntryMessage = malloc(PATH_MAX);
snprintf(createEntryMessage, PATH_MAX, "Create new entry for the journal %s", journal);
entryArray[0] = createEntryMessage;
entryArray[1] = "Open random entry";
entryArray[2] = "Search inside entries";
entryArray[3] = "Return to the note selection";
int entryCount = extraOptions; // we need to count how many dirs there is to always readjust
// how many memory we alloc
// Refer https://pubs.opengroup.org/onlinepubs/7990989775/xsh/readdir.html
@@ -301,6 +302,8 @@ char *updateJournal(char *path, char *journal, char *timeFormat, int *journalWas
snprintf(selectedOption, PATH_MAX, "%s/%s", path, temp);
path = strdup(selectedOption);
free(selectedOption);
} else if (strcmp(selectedOption, "Return to the note selection") == 0) {
*returnNoteSelection = 1;
} else { // we just recreate the path to the selected entry
// snprintf does not like to have the same variable as input and output so we use a
// buffer
+2 -1
View File
@@ -25,6 +25,7 @@ char **getVaultsFromDirectories(char **directoryStringArray, int directoryNumber
// handles both type of journal (divided and unified).
// creates new entry with date.
// for divided select if we want to acces to a new entry or a old one.
// returnNoteSelection tells us if the user wants to go back to the note selection.
// returns the path to the file that needs to be opened.
char *updateJournal(char *path, char *journal, char *timeFormat, int *journalWasUpdated, int shouldDebug);
char *updateJournal(char *path, char *journal, char *timeFormat, int *journalWasUpdated, int *returnNoteSelection, int shouldDebug);
#endif