Skip to content

Commit

Permalink
remove backlinks and writing assistant placeholder text
Browse files Browse the repository at this point in the history
  • Loading branch information
samlhuillier committed Nov 3, 2024
1 parent cb7c28d commit 8a5b1ad
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 73 deletions.
72 changes: 1 addition & 71 deletions src/components/Editor/EditorManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ const EditorManager: React.FC = () => {
const [contextMenuVisible, setContextMenuVisible] = useState(false)
const [menuPosition, setMenuPosition] = useState({ x: 0, y: 0 })
const [editorFlex, setEditorFlex] = useState(true)
const [showPlaceholder, setShowPlaceholder] = useState(false)
const [writingAssistantTextPosition, setWritingAssistantTextPosition] = useState({ top: 0, left: 0 })

const { editor, suggestionsState, vaultFilesFlattened, currentlyOpenFilePath } = useFileContext()
const { editor, suggestionsState, vaultFilesFlattened } = useFileContext()
const [showDocumentStats, setShowDocumentStats] = useState(false)
const { openContent } = useContentContext()

Expand Down Expand Up @@ -69,65 +67,6 @@ const EditorManager: React.FC = () => {
window.ipcRenderer.on('show-doc-stats-changed', handleDocStatsChange)
}, [])

useEffect(() => {
if (!editor) return

const handleUpdate = () => {
try {
const { state } = editor
const { from, to } = state.selection

const $from = state.doc.resolve(from)
const $to = state.doc.resolve(to)
const start = $from.before()
const end = $to.after()

const currentLineText = state.doc.textBetween(start, end, '\n', ' ').trim()

if (currentLineText === '') {
const { node } = editor.view.domAtPos(from)
const rect = (node as HTMLElement).getBoundingClientRect()
const editorRect = editor.view.dom.getBoundingClientRect()
setWritingAssistantTextPosition({ top: rect.top - editorRect.top, left: rect.left - editorRect.left })
setShowPlaceholder(true)
} else {
setShowPlaceholder(false)
}
} catch (error) {
setShowPlaceholder(false)
}
}

editor.on('update', handleUpdate)
editor.on('selectionUpdate', handleUpdate)

// eslint-disable-next-line consistent-return
return () => {
editor.off('update', handleUpdate)
editor.off('selectionUpdate', handleUpdate)
}
}, [editor])

const handleInput = () => {
if (editor) {
const { state } = editor
const { from, to } = state.selection

const $from = state.doc.resolve(from)
const $to = state.doc.resolve(to)
const start = $from.before()
const end = $to.after()

const currentLineText = state.doc.textBetween(start, end, '\n', ' ').trim()
setShowPlaceholder(currentLineText === '')
}
}
useEffect(() => {
if (editor) {
editor.commands.focus()
}
}, [editor, currentlyOpenFilePath])

return (
<div
className="relative size-full cursor-text overflow-hidden bg-dark-gray-c-eleven py-4 text-slate-400 opacity-80"
Expand All @@ -154,17 +93,8 @@ const EditorManager: React.FC = () => {
}}
onContextMenu={handleContextMenu}
onClick={handleClick}
onInput={handleInput}
editor={editor}
/>
{showPlaceholder && (
<div
className="pointer-events-none absolute text-gray-500"
style={{ top: writingAssistantTextPosition.top, left: writingAssistantTextPosition.left }}
>
Press &apos;space&apos; for AI writing assistant
</div>
)}
</div>
</div>
{suggestionsState && (
Expand Down
2 changes: 0 additions & 2 deletions src/contexts/FileContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
getNextAvailableFileNameGivenBaseName,
sortFilesAndDirectories,
} from '@/lib/file'
import { BacklinkExtension } from '@/components/Editor/BacklinkExtension'
import { SuggestionsState } from '@/components/Editor/BacklinkSuggestionsDisplay'
import HighlightExtension, { HighlightData } from '@/components/Editor/HighlightExtension'
import { RichTextLink } from '@/components/Editor/RichTextLink'
Expand Down Expand Up @@ -194,7 +193,6 @@ export const FileProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
linkOnPaste: true,
openOnClick: true,
}),
BacklinkExtension(setSuggestionsState),
CharacterCount,
],
})
Expand Down

0 comments on commit 8a5b1ad

Please sign in to comment.