From 757870398ea8780ea402f58a4f782494fad29a89 Mon Sep 17 00:00:00 2001 From: ransome1 Date: Fri, 27 Oct 2023 20:24:54 +0200 Subject: [PATCH] Fixed a bug in todo deletion, added keyboard shortcuts for handling search field visibility and adding todo from search field --- .gitignore | 3 +- flatpak/com.github.ransome1.sleek.appdata.xml | 2 +- flatpak/com.github.ransome1.sleek.desktop | 2 +- package.json | 2 +- release/app/package.json | 2 +- release/app/yarn.lock | 30 +++++++++---------- snap/snapcraft.yaml | 2 +- src/main/modules/File/Write.tsx | 2 +- src/main/modules/Ipc.tsx | 12 ++++++-- src/renderer/App.tsx | 2 ++ src/renderer/Drawer/Attributes.scss | 1 - src/renderer/Drawer/Drawer.tsx | 5 +++- src/renderer/Search.tsx | 24 +++++++++++++-- src/renderer/ToolBar.tsx | 3 +- 14 files changed, 61 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 4f2db524..4bd895b5 100755 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,5 @@ npm-debug.log.* *.dtmp *.drawio *.snap -*FilterLang.js \ No newline at end of file +*FilterLang.js +*package-lock.json \ No newline at end of file diff --git a/flatpak/com.github.ransome1.sleek.appdata.xml b/flatpak/com.github.ransome1.sleek.appdata.xml index 9e1ec569..b9b5da63 100755 --- a/flatpak/com.github.ransome1.sleek.appdata.xml +++ b/flatpak/com.github.ransome1.sleek.appdata.xml @@ -9,7 +9,7 @@ Robin Ahle - + https://github.com/ransome1/sleek https://github.com/ransome1/sleek/issues diff --git a/flatpak/com.github.ransome1.sleek.desktop b/flatpak/com.github.ransome1.sleek.desktop index 8323b059..4023a165 100755 --- a/flatpak/com.github.ransome1.sleek.desktop +++ b/flatpak/com.github.ransome1.sleek.desktop @@ -1,5 +1,5 @@ [Desktop Entry] -Version=2.0.0 +Version=2.0.0-dev19 Name=sleek Exec=sleek Type=Application diff --git a/package.json b/package.json index aed80edf..7655d0b2 100644 --- a/package.json +++ b/package.json @@ -156,7 +156,7 @@ "webpack-merge": "^5.9.0" }, "build": { - "buildVersion": "27", + "buildVersion": "28", "asar": true, "asarUnpack": "**\\*.{node,dll}", "files": [ diff --git a/release/app/package.json b/release/app/package.json index f018eac7..c70664ae 100644 --- a/release/app/package.json +++ b/release/app/package.json @@ -1,6 +1,6 @@ { "name": "sleek", - "version": "2.0.0-dev18", + "version": "2.0.0-dev19", "description": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)", "synopsis": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)", "keywords": [ diff --git a/release/app/yarn.lock b/release/app/yarn.lock index 428ab690..c808bbe6 100644 --- a/release/app/yarn.lock +++ b/release/app/yarn.lock @@ -4,7 +4,7 @@ anymatch@~3.1.2: version "3.1.3" - resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e" + resolved "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz" integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw== dependencies: normalize-path "^3.0.0" @@ -12,19 +12,19 @@ anymatch@~3.1.2: binary-extensions@^2.0.0: version "2.2.0" - resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" + resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== braces@~3.0.2: version "3.0.2" - resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" + resolved "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz" integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== dependencies: fill-range "^7.0.1" chokidar@^3.5.3: version "3.5.3" - resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" + resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz" integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== dependencies: anymatch "~3.1.2" @@ -39,67 +39,67 @@ chokidar@^3.5.3: fill-range@^7.0.1: version "7.0.1" - resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40" + resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz" integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ== dependencies: to-regex-range "^5.0.1" fsevents@~2.3.2: version "2.3.3" - resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== glob-parent@~5.1.2: version "5.1.2" - resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" + resolved "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz" integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== dependencies: is-glob "^4.0.1" is-binary-path@~2.1.0: version "2.1.0" - resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" + resolved "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz" integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== dependencies: binary-extensions "^2.0.0" is-extglob@^2.1.1: version "2.1.1" - resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" + resolved "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz" integrity sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ== is-glob@^4.0.1, is-glob@~4.0.1: version "4.0.3" - resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" + resolved "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz" integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== dependencies: is-extglob "^2.1.1" is-number@^7.0.0: version "7.0.0" - resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" + resolved "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz" integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng== normalize-path@^3.0.0, normalize-path@~3.0.0: version "3.0.0" - resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" + resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz" integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== picomatch@^2.0.4, picomatch@^2.2.1: version "2.3.1" - resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" + resolved "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz" integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== readdirp@~3.6.0: version "3.6.0" - resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7" + resolved "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz" integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA== dependencies: picomatch "^2.2.1" to-regex-range@^5.0.1: version "5.0.1" - resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4" + resolved "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz" integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ== dependencies: is-number "^7.0.0" diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index cb21bb91..6455e2dc 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,6 +1,6 @@ name: sleek base: core18 -version: "2.0.0" +version: "2.0.0-dev19" summary: todo.txt manager for Linux, free and open-source (FOSS) description: | sleek is an open-source (FOSS) todo manager based on the todo.txt syntax. Stripped down to only the most necessary features, and with a clean and simple interface, sleek aims to help you focus on getting things done. diff --git a/src/main/modules/File/Write.tsx b/src/main/modules/File/Write.tsx index 7a0eaac6..ea248a0f 100644 --- a/src/main/modules/File/Write.tsx +++ b/src/main/modules/File/Write.tsx @@ -10,7 +10,7 @@ async function removeLineFromFile(id: number) { const files = configStorage.get('files') as File[]; const activeFile = getActiveFile(files); - if (activeFile && activeFile.todoFilePath) { // Check if activeFile and todoFilePath are defined + if (activeFile && activeFile.todoFilePath) { lines.splice(id, 1); const modifiedContent = lines.join('\n'); diff --git a/src/main/modules/Ipc.tsx b/src/main/modules/Ipc.tsx index 171f6612..ab0c82b8 100644 --- a/src/main/modules/Ipc.tsx +++ b/src/main/modules/Ipc.tsx @@ -109,6 +109,14 @@ function handleChangeDoneFilePath(event: IpcMainEvent, index: number): void { } } +function handleRemoveLineFromFile(event: IpcMainEvent, index: number): void { + try { + removeLineFromFile(index); + } catch (error: any) { + console.error('ipcEvents.ts:', error); + } +} + function handleSaveToClipboard(event: IpcMainEvent, string: string): void { try { clipboard.writeText(string); @@ -138,7 +146,7 @@ function removeEventListeners(): void { ipcMain.off('saveToClipboard', handleSaveToClipboard); ipcMain.off('revealFile', handleRevealFile); ipcMain.off('changeDoneFilePath', handleChangeDoneFilePath); - ipcMain.off('removeLineFromFile', removeLineFromFile); + ipcMain.off('removeLineFromFile', handleRemoveLineFromFile); } app.on('before-quit', removeEventListeners); @@ -158,4 +166,4 @@ ipcMain.on('droppedFile', handleDroppedFile); ipcMain.on('saveToClipboard', handleSaveToClipboard); ipcMain.on('revealFile', handleRevealFile); ipcMain.on('changeDoneFilePath', handleChangeDoneFilePath); -ipcMain.on('removeLineFromFile', removeLineFromFile); +ipcMain.on('removeLineFromFile', handleRemoveLineFromFile); diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 658df21b..4f3da418 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -211,6 +211,7 @@ const App = () => { sorting={sorting} setSorting={setSorting} attributeMapping={attributeMapping} + searchFieldRef={searchFieldRef} /> )} @@ -231,6 +232,7 @@ const App = () => { setSearchString={setSearchString} isSearchOpen={isSearchOpen} setIsSearchOpen={setIsSearchOpen} + setIsSearchOpen={setIsSearchOpen} searchFieldRef={searchFieldRef} /> ; t: typeof i18n.t; } @@ -28,6 +29,7 @@ const DrawerComponent: React.FC = ({ attributes, filters, attributeMapping, + searchFieldRef, t }) => { const [activeTab, setActiveTab] = useState('attributes'); @@ -57,7 +59,8 @@ const DrawerComponent: React.FC = ({ }; const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === 'Escape') { + const isSearchFocused = document.activeElement === searchFieldRef.current; + if (!isSearchFocused && event.key === 'Escape') { setIsDrawerOpen(false); } }; diff --git a/src/renderer/Search.tsx b/src/renderer/Search.tsx index 8539e963..58f9335c 100644 --- a/src/renderer/Search.tsx +++ b/src/renderer/Search.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, ChangeEvent } from 'react'; +import React, { useEffect, ChangeEvent, useCallback } from 'react'; import { TextField, InputAdornment, Button, Box } from '@mui/material'; import CancelIcon from '@mui/icons-material/Cancel'; import { withTranslation, WithTranslation } from 'react-i18next'; @@ -22,6 +22,7 @@ const Search: React.FC = ({ searchString, setSearchString, isSearchOpen, + setIsSearchOpen, searchFieldRef, t, }) => { @@ -43,11 +44,21 @@ const Search: React.FC = ({ searchFieldRef.current?.focus(); }; + const handleKeyDown = useCallback((event: KeyboardEvent) => { + const isSearchFocused = document.activeElement === searchFieldRef.current; + if(isSearchFocused && event.key === 'Escape' && searchString) { + setSearchString(''); + } else if(isSearchFocused && event.key === 'Escape' && !searchString) { + setIsSearchOpen(false); + } else if(searchString && (event.metaKey || event.ctrlKey) && event.key === 'Enter') { + ipcRenderer.send('writeTodoToFile', undefined, searchString); + setSearchString(''); + } + }); + useEffect(() => { if (searchString === null) return; - let delayedSearch: NodeJS.Timeout; - const handleSearch = () => { ipcRenderer.send('requestData', searchString); }; @@ -65,6 +76,13 @@ const Search: React.FC = ({ } }, [isSearchOpen, searchFieldRef]); + useEffect(() => { + document.addEventListener('keydown', handleKeyDown); + return () => { + document.removeEventListener('keydown', handleKeyDown); + }; + }, [handleKeyDown]); + return ( <> {isSearchOpen && ( diff --git a/src/renderer/ToolBar.tsx b/src/renderer/ToolBar.tsx index 2eaeb24f..6a357032 100644 --- a/src/renderer/ToolBar.tsx +++ b/src/renderer/ToolBar.tsx @@ -18,8 +18,7 @@ const ToolBar: React.FC = ({ setIsSearchOpen((prevIsSearchOpen) => !prevIsSearchOpen); }; - const handleKeyDown = useCallback( - (event: KeyboardEvent) => { + const handleKeyDown = useCallback((event: KeyboardEvent) => { const isSearchFocused = document.activeElement === searchFieldRef.current; if ((event.metaKey || event.ctrlKey) && event.key === 'f' && isSearchOpen && !isSearchFocused) { event.preventDefault();