Skip to content

Commit

Permalink
Added custom file env, fixed jumping auto insert
Browse files Browse the repository at this point in the history
  • Loading branch information
ransome1 committed Jul 7, 2021
1 parent df82f91 commit 842be9d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sleek",
"productName": "sleek",
"version": "1.0.8",
"version": "1.0.9-rc.1",
"description": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source",
"synopsis": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source",
"category": "ProjectManagement",
Expand Down
15 changes: 12 additions & 3 deletions src/js/filters.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ function generateFilterData(autoCompleteCategory, autoCompleteValue, autoComplet
categories = ["priority", "contexts", "projects"];
}
categories.forEach((category) => {
console.log(category);

// TODO build empty container shells here
//console.log(category);

// array to collect all the available filters in the data
let filters = new Array();
let filterArray;
Expand Down Expand Up @@ -457,8 +460,14 @@ function generateFilterButtons(category, autoCompleteValue, autoCompletePrefix,
// add filter to input
todoFiltersItem.addEventListener("click", (event) => {
if(autoCompletePrefix && autoCompleteValue) {
// remove composed filter first, then add selected filter
document.getElementById("modalFormInput").value = document.getElementById("modalFormInput").value.replace(autoCompletePrefix + autoCompleteValue, autoCompletePrefix + todoFiltersItem.getAttribute("data-filter") + " ");
// remove composed filter first
let newValue = document.getElementById("modalFormInput").value.slice(0, caretPosition - autoCompleteValue.length) + document.getElementById("modalFormInput").value.slice(caretPosition);
// split string into single characters
newValue = newValue.split("");
//then add selected filter at index
newValue.splice(caretPosition - autoCompleteValue.length, 0, todoFiltersItem.getAttribute("data-filter"));
// join back from single characters to string
document.getElementById("modalFormInput").value = newValue.join("");
} else if(autoCompletePrefix) {
// add button data value to the exact caret position
document.getElementById("modalFormInput").value = [document.getElementById("modalFormInput").value.slice(0, caretPosition), todoFiltersItem.getAttribute('data-filter'), document.getElementById("modalFormInput").value.slice(caretPosition)].join('') + " ";
Expand Down
5 changes: 1 addition & 4 deletions src/js/form.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ function positionAutoCompleteContainer() {
autoCompleteContainer.style.left = modalFormInputPosition.left + "px";
}
function modalFormInputEvent(event) {
//if(event.key==="Enter") return false;
positionAutoCompleteContainer();
resizeInput(document.getElementById("modalFormInput"));
let autoCompleteValue ="";
Expand Down Expand Up @@ -411,7 +410,7 @@ function submitForm() {
// jump to index, remove 1 item there and add the value from the input at that position
items.objects.splice(index, 1, todo);
// Add todo
} else if(modalForm.getAttribute("data-item")==null && document.getElementById("modalFormInput").value!="") {
} else if(!modalForm.getAttribute("data-item") && document.getElementById("modalFormInput").value!="") {
// in case there hasn't been a passed data item, we just push the input value as a new item into the array
// replace new lines with spaces (https://stackoverflow.com/a/34936253)
let todo = new TodoTxtItem(document.getElementById("modalFormInput").value.replaceAll(/[\r\n]+/g, String.fromCharCode(16)), [ new SugarDueExtension(), new HiddenExtension(), new RecExtension() ]);
Expand Down Expand Up @@ -482,8 +481,6 @@ function toggleInputSize(type) {
newInputElement.id = "modalFormInput";
newInputElement.setAttribute("tabindex", 0);
newInputElement.setAttribute("class", "input is-medium");
//newInputElement.value = document.getElementById("modalFormInput").value.replaceAll(String.fromCharCode(16)," ");
//newInputElement.setAttribute("placeholder", translations.formTodoInputPlaceholder);
// replace old element with the new one
document.getElementById("modalFormInput").replaceWith(newInputElement);
// replace special char with line break before passing it to textarea
Expand Down
46 changes: 21 additions & 25 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,33 +173,29 @@ const createWindow = async function() {
// skip persisted files and go with ENV if set
if(process.env.SLEEK_CUSTOM_FILE && fs.existsSync(process.env.SLEEK_CUSTOM_FILE)) {
file = process.env.SLEEK_CUSTOM_FILE;
// regular process
}
// use the loop to check if the new path is already in the user data
let fileFound = false;
if(userData.data.files) {
userData.data.files.forEach(function(element) {
// if path is found it is set active
if(element[1]===file) {
element[0] = 1
fileFound = true;
// if this entry is not equal to the new path it is set 0
} else {
element[0] = 0;
}
});
} else {
// use the loop to check if the new path is already in the user data
let fileFound = false;
if(userData.data.files) {
userData.data.files.forEach(function(element) {
// if path is found it is set active
if(element[1]===file) {
element[0] = 1
fileFound = true;
// if this entry is not equal to the new path it is set 0
} else {
element[0] = 0;
}
});
} else {
userData.data.files = new Array;
}
// only push new path if it is not already in the user data
if((!fileFound || !userData.data.files) && file) userData.data.files.push([1, file]);
userData.set("files", userData.data.files);
userData.data.file = file;
userData.set("file", file);
userData.data.files = new Array;
}

console.log(file);

// only push new path if it is not already in the user data
if((!fileFound || !userData.data.files) && file) userData.data.files.push([1, file]);
userData.set("files", userData.data.files);
userData.data.file = file;
userData.set("file", file);
// TODO describe
if(fileWatcher) fileWatcher.close();
fileWatcher = chokidar.watch(file);
fileWatcher
Expand Down

0 comments on commit 842be9d

Please sign in to comment.