From de3c038165cf5af0baa51764bead6d025ec36ebf Mon Sep 17 00:00:00 2001 From: Paul Sonnentag Date: Fri, 24 May 2024 11:55:03 +0200 Subject: [PATCH 01/59] hide comment highlights if timeline sidebar is open --- .../components/VersionControlEditor.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/os/versionControl/components/VersionControlEditor.tsx b/src/os/versionControl/components/VersionControlEditor.tsx index 36a2aa5a..d021ede1 100644 --- a/src/os/versionControl/components/VersionControlEditor.tsx +++ b/src/os/versionControl/components/VersionControlEditor.tsx @@ -334,6 +334,17 @@ export const VersionControlEditor: React.FC<{ const branches = doc.branchMetadata.branches ?? []; + // Currently we can't filter out comments that didn't exist in a previous version of the document + // this leads to seemingly random places in the document being highlighted. The problem is that + // the cursor api doesn't provide a way to detect if the op was present it always gives the closest + // position to that op in the current document. + // + // As a short term workaround we filter out all comments if the timeline sidebar is active + const visibleAnnotations = + sidebarMode === "timeline" + ? annotations.filter((annotation) => annotation.type !== "highlighted") + : annotations; + return (
@@ -546,7 +557,7 @@ export const VersionControlEditor: React.FC<{ datatypeId={datatypeId} docUrl={selectedBranch.url} docHeads={docHeads} - annotations={annotations} + annotations={visibleAnnotations} actorIdToAuthor={actorIdToAuthor} setSelectedAnchors={setSelectedAnchors} setHoveredAnchor={setHoveredAnchor} @@ -557,7 +568,7 @@ export const VersionControlEditor: React.FC<{ datatypeId={datatypeId} docUrl={selectedBranch?.url ?? mainDocUrl} docHeads={docHeads} - annotations={annotations} + annotations={visibleAnnotations} actorIdToAuthor={actorIdToAuthor} setSelectedAnchors={setSelectedAnchors} setHoveredAnchor={setHoveredAnchor} From 6c43b9c7a8caa975be0aa0656a5e4ec9921f63ac Mon Sep 17 00:00:00 2001 From: Paul Sonnentag Date: Thu, 16 May 2024 13:47:46 +0200 Subject: [PATCH 02/59] reset history state when switching to review mode --- .../components/VersionControlEditor.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/os/versionControl/components/VersionControlEditor.tsx b/src/os/versionControl/components/VersionControlEditor.tsx index d021ede1..788ae193 100644 --- a/src/os/versionControl/components/VersionControlEditor.tsx +++ b/src/os/versionControl/components/VersionControlEditor.tsx @@ -319,7 +319,17 @@ export const VersionControlEditor: React.FC<{ isCommentInputFocused, }); - const [sidebarMode, setSidebarMode] = useState("comments"); + const [sidebarMode, _setSidebarMode] = useState("comments"); + + const setSidebarMode = (sidebarMode: SidebarMode) => { + // reset state from history mode + if (sidebarMode === "comments") { + setDiffFromHistorySidebar(undefined); + setDocHeadsFromHistorySidebar(undefined); + } + + _setSidebarMode(sidebarMode); + }; const [ annotationsPositionsInSidebarMap, From 8a0215d8725b14f9ed4778c20170fb1e14a059a0 Mon Sep 17 00:00:00 2001 From: Paul Sonnentag Date: Thu, 16 May 2024 13:59:51 +0200 Subject: [PATCH 03/59] create a valid range when trying to comment on the end of the document --- src/tools/essay/components/CodeMirrorEditor.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tools/essay/components/CodeMirrorEditor.tsx b/src/tools/essay/components/CodeMirrorEditor.tsx index 10a9d694..9ee02f8a 100644 --- a/src/tools/essay/components/CodeMirrorEditor.tsx +++ b/src/tools/essay/components/CodeMirrorEditor.tsx @@ -269,11 +269,21 @@ export function MarkdownEditor({ if (transaction.newSelection && view.hasFocus) { const selection = view.state.selection.ranges[0]; - if (selection) { + if (selection && selection.from !== selection.to) { + const docLength = view.state.doc.length; + setSelectedAnchors([ { fromCursor: getCursorSafely(doc, ["content"], selection.from), - toCursor: getCursorSafely(doc, ["content"], selection.to), + toCursor: getCursorSafely( + doc, + ["content"], + + // we can't get a cursor to the end the document because cursors always point to characters + // in the future we want to have a cursor API in Automerge that allows to point to a side of a character similar to marks + // as a workaround for now we just point to the last character instead if the end of the document is selected + selection.to === docLength ? docLength - 1 : selection.to + ), }, ]); } else { From e012520d95e8e29ee70048aacbfe3d9bcdbb88dc Mon Sep 17 00:00:00 2001 From: Paul Sonnentag Date: Thu, 16 May 2024 14:28:15 +0200 Subject: [PATCH 04/59] filter out comments on empty ranges --- src/datatypes/markdown/datatype.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/datatypes/markdown/datatype.ts b/src/datatypes/markdown/datatype.ts index a651187d..b5564824 100644 --- a/src/datatypes/markdown/datatype.ts +++ b/src/datatypes/markdown/datatype.ts @@ -240,6 +240,12 @@ const valueOfAnchor = (doc: MarkdownDoc, anchor: MarkdownDocAnchor) => { const from = getCursorPositionSafely(doc, ["content"], anchor.fromCursor); const to = getCursorPositionSafely(doc, ["content"], anchor.toCursor); + // if the anchor points to an empty range return undefined + // so highlight comments that point to this will be filtered out + if (from === to) { + return undefined; + } + return doc.content.slice(from, to); }; From 622ea3b19c67ca633d5baa3918843207c980cae8 Mon Sep 17 00:00:00 2001 From: Paul Sonnentag Date: Fri, 24 May 2024 14:50:17 +0200 Subject: [PATCH 05/59] add global keyboard shortcut cmd+m+shift to comment --- .../components/ReviewSidebar.tsx | 13 ++++ .../components/VersionControlEditor.tsx | 71 +++++++++++-------- .../essay/components/CodeMirrorEditor.tsx | 14 ---- src/tools/tldraw/components/hooks.ts | 4 +- 4 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/os/versionControl/components/ReviewSidebar.tsx b/src/os/versionControl/components/ReviewSidebar.tsx index 3c626824..c63fa982 100644 --- a/src/os/versionControl/components/ReviewSidebar.tsx +++ b/src/os/versionControl/components/ReviewSidebar.tsx @@ -62,6 +62,18 @@ export const ReviewSidebar = React.memo( useState(); const account = useCurrentAccount(); + const [commentInputElement, setCommentInputElement] = + useState(); + + // sync focus state back to text area + useEffect(() => { + if (commentInputElement && isCommentInputFocused) { + setTimeout(() => { + commentInputElement.focus(); + }, 100); // hack : add a bit of a delay otherwise focusing the element doesn't work when the sidebar hasn't been opened before + } + }, [commentInputElement, isCommentInputFocused]); + const pendingAnnotationsForComment: HighlightAnnotation< unknown, unknown @@ -241,6 +253,7 @@ export const ReviewSidebar = React.memo(