Skip to content

Commit

Permalink
feat(Editor): jump to part (without offset)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarpl committed Feb 9, 2024
1 parent 0b7027a commit 4101cdd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const CurrentRundown = observer((): React.JSX.Element => {
const objId = RootAppStore.uiStore.selectedLineId
if (objId === null) return

console.log(objId)

RootAppStore.control.jumpToObject(objId)
}, [isListFocused])

Expand Down
31 changes: 31 additions & 0 deletions packages/apps/client/src/components/ScriptEditor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { deselectAll } from './commands/deselectAll'
import { fromMarkdown, toMarkdown } from 'src/lib/prosemirrorDoc'
import { RootAppStore } from 'src/stores/RootAppStore'
import { IReactionDisposer, reaction } from 'mobx'
import { AnyTriggerAction } from 'src/lib/triggerActions/triggerActions'

export function Editor({
className,
Expand All @@ -26,6 +27,36 @@ export function Editor({
const containerEl = useRef<HTMLDivElement>(null)
const editorView = useRef<EditorView>()

const onMovePrompterToHere = useCallback(() => {
if (!editorView.current) return

const view = editorView.current
const state = view.state

const nodeAtHead = state.selection.$head
const parentOfHead = nodeAtHead.node(nodeAtHead.depth - 1)

const objId = parentOfHead.attrs['lineId']
if (!objId) return

console.log(view.coordsAtPos(state.selection.$head.pos))

RootAppStore.control.jumpToObject(objId)
}, [])

useEffect(() => {
function onAction(action: AnyTriggerAction) {
if (!editorView.current || !editorView.current.hasFocus()) return
if (action.type === 'movePrompterToHere') onMovePrompterToHere()
}

RootAppStore.triggerStore.addListener('action', onAction)

return () => {
RootAppStore.triggerStore.removeListener('action', onAction)
}
}, [onMovePrompterToHere])

useEffect(() => {
if (!containerEl.current) return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'src/PrompterStyles.css'
import classes from './ScriptEditor.module.scss'
import { observer } from 'mobx-react-lite'
import { RootAppStore } from 'src/stores/RootAppStore'
import { useDebouncedCallback } from 'src/lib/lib'
import { useSize } from 'src/lib/useSize'

export const ScriptEditor = observer(function ScriptEditor(): React.JSX.Element {
Expand Down

0 comments on commit 4101cdd

Please sign in to comment.