A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: add go to next/previous tab shortcut (#7109)
01zulfi71db85458d8a
diff --git a/apps/web/__e2e__/editor.test.ts b/apps/web/__e2e__/editor.test.tsindex fff0c7056..5f79ab377 100644--- a/apps/web/__e2e__/editor.test.ts+++ b/apps/web/__e2e__/editor.test.ts@@ -370,3 +370,57 @@ test("when autosave is disabled, closing the note should save it", async ({await expect(notes.editor.savedIcon).toBeVisible();expect(await notes.editor.getContent("text")).toBe(content.trim());});++test("control + alt + right arrow should go to next note", async ({ page }) => {+ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ const note1 = await notes.createNote({+ title: "Note 1",+ content: "Note 1 content"+ });+ const note2 = await notes.createNote({+ title: "Note 2",+ content: "Note 2 content"+ });++ await note1?.openNote();+ await note2?.openNote();+ await page.keyboard.press("Control+Alt+ArrowRight");++ expect(await notes.editor.getTitle()).toBe("Note 1");+ expect(await notes.editor.getContent("text")).toBe("Note 1 content");++ await page.keyboard.press("Control+Alt+ArrowRight");++ expect(await notes.editor.getTitle()).toBe("Note 2");+ expect(await notes.editor.getContent("text")).toBe("Note 2 content");+});++test("control + alt + left arrow should go to previous note", async ({+ page+}) => {+ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ const note1 = await notes.createNote({+ title: "Note 1",+ content: "Note 1 content"+ });+ const note2 = await notes.createNote({+ title: "Note 2",+ content: "Note 2 content"+ });++ await note1?.openNote();+ await note2?.openNote();+ await page.keyboard.press("Control+Alt+ArrowLeft");++ expect(await notes.editor.getTitle()).toBe("Note 1");+ expect(await notes.editor.getContent("text")).toBe("Note 1 content");++ await page.keyboard.press("Control+Alt+ArrowLeft");++ expect(await notes.editor.getTitle()).toBe("Note 2");+ expect(await notes.editor.getContent("text")).toBe("Note 2 content");+});diff --git a/apps/web/src/components/editor/action-bar.tsx b/apps/web/src/components/editor/action-bar.tsxindex 2a3302ca9..2324e5f75 100644--- a/apps/web/src/components/editor/action-bar.tsx+++ b/apps/web/src/components/editor/action-bar.tsx@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import { Button, Flex, Text } from "@theme-ui/components";-import { useState } from "react";+import { useEffect, useRef, useState } from "react";import {ArrowLeft,Cross,@@ -474,10 +474,25 @@ function Tab(props: TabProps) {: Note;const { attributes, listeners, setNodeRef, transform, transition, active } =useSortable({ id });+ const activeTabRef = useRef<HTMLElement | null>(null);++ useEffect(() => {+ if (activeTabRef.current && isActive) {+ const tab = activeTabRef.current;+ tab.scrollIntoView({+ behavior: "smooth",+ block: "nearest",+ inline: "nearest"+ });+ }+ }, [isActive]);return (<Flex- ref={setNodeRef}+ ref={(el) => {+ setNodeRef(el);+ activeTabRef.current = el;+ }}className="tab"data-test-id={`tab-${id}`}sx={{diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex 5f57263fd..c702be5df 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -125,6 +125,31 @@ export default function TabsView() {const isTOCVisible = useEditorStore((store) => store.isTOCVisible);const [dropRef, overlayRef] = useDragOverlay();+ useEffect(() => {+ const onKeyDown = (event: KeyboardEvent) => {+ if (+ (event.ctrlKey || event.metaKey) &&+ event.altKey &&+ event.key === "ArrowRight"+ ) {+ event.preventDefault();+ useEditorStore.getState().openNextSession();+ }+ if (+ (event.ctrlKey || event.metaKey) &&+ event.altKey &&+ event.key === "ArrowLeft"+ ) {+ event.preventDefault();+ useEditorStore.getState().openPreviousSession();+ }+ };+ document.body.addEventListener("keydown", onKeyDown);+ return () => {+ document.body.removeEventListener("keydown", onKeyDown);+ };+ }, []);+return (<><Flexdiff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsxindex 91255fd71..6530dc25e 100644--- a/apps/web/src/components/editor/tiptap.tsx+++ b/apps/web/src/components/editor/tiptap.tsx@@ -166,7 +166,7 @@ function TipTap(props: TipTapProps) {const tiptapOptions = useMemo<Partial<TiptapOptions>>(() => {return {editorProps: {- handleKeyDown(view, event) {+ handleKeyDown(_, event) {if ((event.ctrlKey || event.metaKey) && event.key === "s") {event.preventDefault();onChange?.(diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.tsindex ad19a5e6e..7b6c18460 100644--- a/apps/web/src/stores/editor-store.ts+++ b/apps/web/src/stores/editor-store.ts@@ -717,6 +717,32 @@ class EditorStore extends BaseStore<EditorStore> {}};+ openNextSession = () => {+ const { sessions, activeSessionId } = this.get();+ if (sessions.length === 0 || sessions.length === 1) return;++ const index = sessions.findIndex((s) => s.id === activeSessionId);+ if (index === -1) return;++ if (index === sessions.length - 1) {+ return this.openSession(sessions[0].id);+ }+ return this.openSession(sessions[index + 1].id);+ };++ openPreviousSession = () => {+ const { sessions, activeSessionId } = this.get();+ if (sessions.length === 0 || sessions.length === 1) return;++ const index = sessions.findIndex((s) => s.id === activeSessionId);+ if (index === -1) return;++ if (index === 0) {+ return this.openSession(sessions[sessions.length - 1].id);+ }+ return this.openSession(sessions[index - 1].id);+ };+addSession = (session: EditorSession, activate = true) => {let oldSessionId: string | null = null;