taniarascia / takenote

📝 ‎ A web-based notes app for developers.

Home Page:https://takenote.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature] Ctrl + S saves the current note

gitsocks opened this issue · comments

commented

Problem
When pressing CTRL+S to save the note out of habit, it prompts me to save the webpage.

Solution
When pressing CTRL+S, it should save/sync the current note and not prompt me to save the webpage.

Notes
I am aware of the current keyboard shortcuts, but CTRL+S is built in muscle memory so that would be much more convenient.

Hey @taniarascia , I am totally new to the open source world. I would like to explore and contribute to it.
Can you please assign this task to me? I hold good knowledge on React.

Thanks :)

hey @gitsocks im new to open source world. And want to contribute to this project. Can I take this issue???
As i run the project locally i found out the note get save when we click the sync key on r3rd from right side of note menu bar. If we can add key binding there the problem can be solved
And if my approach is correct can I take this issue

commented

Hy @rajat844! I actually created this ticket because I am also new to open source and wanted to work on something but I don't mind if you or someone else picks it up :).

I do not think I can assign it to you though. I do not have the permissions. I think only @taniarascia or other admins can do that.

I find it better not to override the browser defaults for web apps, and instead use new shortcuts.

You do not need to have a ticket assigned to you to work on it. In fact, I don't assign tickets to people in the TakeNote project.

I find it better not to override the browser defaults for web apps, and instead use new shortcuts.

You do not need to have a ticket assigned to you to work on it. In fact, I don't assign tickets to people in the TakeNote project.

🤔 I think I can relate to not wanting to change the browser's default shortcuts, but I also feel it'd be really nice to use "CTRL+S" to save a note. We could add an option in the settings where users can choose to use "CTRL+S" for saving a note or not.
I think that would work well for many people 💁‍♂️

after checking some blogs, this is totally possible by just preventing default event with the e.preventDefault
this is how i think it should work:

useEffect(() => {
    const ctrl1 = (e: KeyboardEvent) => e.ctrlKey && e.key === "s"

    const handler= (e: KeyboardEvent) => {
      if (ctrl1(e)) {
        save()
      }
    };

    const ignore = (e: KeyboardEvent) => {
      if (ctrl1(e)) {
        e.preventDefault();
      }
    };

    window.addEventListener("keyup", handler);
    window.addEventListener("keydown", ignore);

    return () => {
      window.removeEventListener("keyup",handler);
      window.removeEventListener("keydown", ignore);
    };
  }, []);

if you think this would work, i would be happy to create a pull request with this feature.

FYI:

export enum Shortcuts {
  NEW_NOTE = 'ctrl+alt+n',
  NEW_CATEGORY = 'ctrl+alt+c',
  DELETE_NOTE = 'ctrl+alt+u',
  SYNC_NOTES = 'ctrl+alt+l',
  DOWNLOAD_NOTES = 'ctrl+alt+o',
  PREVIEW = 'alt+ctrl+p',
  TOGGLE_THEME = 'alt+ctrl+k',
  SEARCH = 'alt+ctrl+f',
  PRETTIFY = 'ctrl+alt+i',
}