Skip to content

Commit

Permalink
Merge pull request #170 from vicky16898/feature/161-add-save-hotkey
Browse files Browse the repository at this point in the history
#161 - Add Hotkey support(ctrl + s/cmd + s) to save opened requests.
  • Loading branch information
SoulKa authored Dec 25, 2024
2 parents cdc9f11 + 4410a01 commit 630420e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/renderer/components/mainWindow/MainTopBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent, useCallback, useState } from 'react';
import { ChangeEvent, useCallback, useEffect, useState } from 'react';
import { RequestMethod } from 'shim/objects/request-method';
import { useErrorHandler } from '@/components/ui/use-toast';
import { HttpService } from '@/services/http/http-service';
Expand Down Expand Up @@ -63,6 +63,24 @@ export function MainTopBar() {
[request, requestEditor]
);

useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
//isSaveShortcut is true if save combination is recorded
const isSaveShortcut = (event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 's';
//if save combination is pressed and request is in draft mode, perform save
if (isSaveShortcut && request?.draft) {
event.preventDefault();
saveRequest();
}
};
//add keyboard event listener
window.addEventListener('keydown', handleKeyDown);
//cleanup
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [saveRequest]);

return (
<div className={cn('flex mb-[24px] gap-6')}>
<div className="flex w-full relative">
Expand Down

0 comments on commit 630420e

Please sign in to comment.