Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/frontend/src/page/document_page.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@
flex-direction: row;
height: 100%;
min-height: 0;
outline: none;
position: relative;
}

.document-pane-layout::after {
content: "";
position: absolute;
bottom: 8px;
left: 2px;
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--color-alert-question);
opacity: 0;
pointer-events: none;
}

.document-pane-layout:focus-within::after {
opacity: 1;
}

.document-pane-content {
Expand Down
52 changes: 48 additions & 4 deletions packages/frontend/src/page/document_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ function SplitPaneToolbar(props: {
<DocumentBreadcrumbs liveDoc={props.doc.liveDoc} docRefId={props.docRef.refId} />
<span class="filler" />
<Show when={!secondaryPanelSize()}>
<IconButton onClick={props.togglePrimaryHistorySidebar} tooltip="Toggle history">
<IconButton
onClick={props.togglePrimaryHistorySidebar}
onMouseDown={(e: MouseEvent) => e.preventDefault()}
tooltip="Toggle history"
>
<History size={20} />
</IconButton>
<PermissionsButton liveDoc={props.doc.liveDoc} docRef={props.docRef} />
Expand All @@ -233,6 +237,7 @@ function SplitPaneToolbar(props: {
>
<IconButton
onClick={props.togglePrimaryHistorySidebar}
onMouseDown={(e: MouseEvent) => e.preventDefault()}
tooltip="Toggle history"
>
<History size={20} />
Expand Down Expand Up @@ -288,7 +293,11 @@ function SecondaryToolbar(props: {
>
{(secondary) => (
<div class="secondary-permissions-toolbar toolbar">
<IconButton onClick={props.toggleHistorySidebar} tooltip="Toggle history">
<IconButton
onClick={props.toggleHistorySidebar}
onMouseDown={(e: MouseEvent) => e.preventDefault()}
tooltip="Toggle history"
>
<History size={20} />
</IconButton>
<PermissionsButton
Expand Down Expand Up @@ -401,10 +410,39 @@ export function DocumentPane(props: {

const history = useSnapshotHistory(() => props.docRef.refId);

let paneRef: HTMLDivElement | undefined;

createEffect(() => {
if (props.historySidebarOpen) {
paneRef?.focus();
}
});

const onKeyDown = (evt: KeyboardEvent) => {
const mod = evt.metaKey || evt.ctrlKey;
if (!mod || evt.altKey) {
return;
}

if (evt.key === "z" || evt.key === "Z") {
if (evt.shiftKey) {
if (history.canRedo()) {
evt.preventDefault();
history.onRedo();
}
} else {
if (history.canUndo()) {
evt.preventDefault();
history.onUndo();
}
}
}
};

// oxlint-disable solid/reactivity -- Context.Provider value getter is reactive
return (
<DocRefIdContext.Provider value={() => props.docRef.refId}>
<div class="document-pane-layout">
<div class="document-pane-layout" ref={paneRef} tabIndex={-1} onKeyDown={onKeyDown}>
<div class="document-pane-content">
<Show when={isDeleted()}>
<WarningBanner
Expand Down Expand Up @@ -464,7 +502,13 @@ export function DocumentPane(props: {
</div>
</div>
<Show when={props.historySidebarOpen && props.docRef.refId}>
<div class="history-sidebar">
<div
class="history-sidebar"
onMouseDown={(e: MouseEvent) => {
e.preventDefault();
paneRef?.focus();
}}
>
<HistorySidebar history={history} />
</div>
</Show>
Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/src/page/history_sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { HistoryNavigator } from "catcolab-ui-components";
import type { SnapshotHistory } from "./use_snapshot_history";

const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent);
const mod = isMac ? "\u2318" : "Ctrl";

export function HistorySidebar(props: { history: SnapshotHistory }) {
return (
<HistoryNavigator
Expand All @@ -10,8 +13,8 @@ export function HistorySidebar(props: { history: SnapshotHistory }) {
onUndo={props.history.onUndo}
onRedo={props.history.onRedo}
onSelect={props.history.navigate}
undoTooltip="Undo"
redoTooltip="Redo"
undoTooltip={`Undo (${mod}+Z)`}
redoTooltip={`Redo (${mod}+Shift+Z)`}
/>
);
}
Loading