|
|
@@ -1,18 +1,12 @@
|
|
|
import { FC } from 'react'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
-import { useCodeMirrorStateContext } from '../codemirror-editor'
|
|
|
import { Button } from 'react-bootstrap'
|
|
|
-import { resolveCommandNode } from '../../extensions/command-tooltip'
|
|
|
-import {
|
|
|
- FilePathArgument,
|
|
|
- LiteralArgContent,
|
|
|
-} from '../../lezer-latex/latex.terms.mjs'
|
|
|
-import Icon from '../../../../shared/components/icon'
|
|
|
-import { EditorState } from '@codemirror/state'
|
|
|
+import Icon from '@/shared/components/icon'
|
|
|
+import { useIncludedFile } from '@/features/source-editor/hooks/use-included-file'
|
|
|
|
|
|
export const IncludeTooltipContent: FC = () => {
|
|
|
const { t } = useTranslation()
|
|
|
- const state = useCodeMirrorStateContext()
|
|
|
+ const { openIncludedFile } = useIncludedFile('IncludeArgument')
|
|
|
|
|
|
return (
|
|
|
<div className="ol-cm-command-tooltip-content">
|
|
|
@@ -20,17 +14,7 @@ export const IncludeTooltipContent: FC = () => {
|
|
|
type="button"
|
|
|
bsStyle="link"
|
|
|
className="ol-cm-command-tooltip-link"
|
|
|
- onClick={() => {
|
|
|
- const name = readFileName(state)
|
|
|
- if (name) {
|
|
|
- window.dispatchEvent(
|
|
|
- new CustomEvent('editor:open-file', {
|
|
|
- detail: { name },
|
|
|
- })
|
|
|
- )
|
|
|
- // TODO: handle file not found
|
|
|
- }
|
|
|
- }}
|
|
|
+ onClick={openIncludedFile}
|
|
|
>
|
|
|
<Icon type="edit" fw />
|
|
|
{t('open_file')}
|
|
|
@@ -38,15 +22,3 @@ export const IncludeTooltipContent: FC = () => {
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
-
|
|
|
-const readFileName = (state: EditorState) => {
|
|
|
- const commandNode = resolveCommandNode(state)
|
|
|
- const argumentNode = commandNode
|
|
|
- ?.getChild('IncludeArgument')
|
|
|
- ?.getChild(FilePathArgument)
|
|
|
- ?.getChild(LiteralArgContent)
|
|
|
-
|
|
|
- if (argumentNode) {
|
|
|
- return state.sliceDoc(argumentNode.from, argumentNode.to)
|
|
|
- }
|
|
|
-}
|