···2828 clearFilters
2929 } = useFilter();
3030 const [currentAction, setCurrentAction] = useState("add");
3131+ const [savedText, setSavedText] = useState("");
31323233 // Get current conditions and parameters for SQL query
3334 const { conditions: newConditions, params: newParams } = getWhereClause();
···5354 ...todo,
5455 priority: todo.priority === '1'
5556 }));
5656-5757- // Keep newText in sync with filterText when in filter mode
5858- useEffect(() => {
5959- // Only update if we're in filter mode
6060- if (currentAction === "filter") {
6161- setNewText(filterText);
6262- }
6363- }, [filterText, currentAction]);
64576558 // Listen for filter update events from sidebar - primarily for debugging
6659 useEffect(() => {
···165158 }
166159 }, [parsedCommand, todos, selectedItems]);
167160168168- // When parsed command changes to a filter action, update the filter text
169169- useEffect(() => {
170170- if (parsedCommand.action === "filter") {
171171- // Set the filter text in the context when a filter command is parsed
172172- setFilterText(newText);
173173- }
174174- }, [parsedCommand, newText, setFilterText]);
175175-176161 const handleActionChange = (action: string) => {
177177- // If switching to filter action, use the current filter text from context
162162+ // If switching to filter action, save current text and use filter text from context
178163 if (action === "filter") {
164164+ setSavedText(newText);
165165+ setCurrentAction(action);
166166+ // If there is saved filter text, use that
179167 if (filterText) {
180168 setNewText(filterText);
181181- }
169169+ } else {
170170+ // otherwise adopt current text as filter text
171171+ setFilterText(newText)
172172+ }
182173 } else if (currentAction === "filter" && action !== "filter") {
183183- // If switching away from filter, clear the text input but keep the filter active
184184- setNewText("");
174174+ // If switching away from filter, set action first then restore the saved text
175175+ setCurrentAction(action);
176176+ if (savedText !== "") {
177177+ setNewText(savedText)
178178+ }
179179+ } else {
180180+ setCurrentAction(action);
185181 }
186186-187187- setCurrentAction(action);
188182 };
189183190184 const handleNewTextChange = (text: string) => {
191191- // Update the local state
192185 setNewText(text);
193186194194- // If the current action is filter, also update the filter text in the context
195195- // This enables real-time filtering as the user types
196187 if (currentAction === "filter") {
197197- // Only update the filter text if it's different to avoid circular updates
198188 if (text !== filterText) {
199189 setFilterText(text);
200190 }
···244234 const handleEnter = (e) => {
245235 if (e.key === "Enter") {
246236 executeCommand();
247247- }
248248- if (e.keyCode === 8) {
249249- if (newText.trim().length === 0) {
250250- clearFilters();
251251- }
252237 }
253238 };
254239