diff --git a/ivette/src/dome/renderer/text/editor.tsx b/ivette/src/dome/renderer/text/editor.tsx index 6b35a575188c54fe11f579bac72888b93a925855..73c25804d25a743c0bf431ea66b39aeae69f7a41 100644 --- a/ivette/src/dome/renderer/text/editor.tsx +++ b/ivette/src/dome/renderer/text/editor.tsx @@ -1,3 +1,25 @@ +/* ************************************************************************ */ +/* */ +/* This file is part of Frama-C. */ +/* */ +/* Copyright (C) 2007-2022 */ +/* CEA (Commissariat à l'énergie atomique et aux énergies */ +/* alternatives) */ +/* */ +/* you can redistribute it and/or modify it under the terms of the GNU */ +/* Lesser General Public License as published by the Free Software */ +/* Foundation, version 2.1. */ +/* */ +/* It is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU Lesser General Public License for more details. */ +/* */ +/* See the GNU Lesser General Public License version 2.1 */ +/* for more details (enclosed in the file licenses/LGPLv2.1). */ +/* */ +/* ************************************************************************ */ + import React from 'react'; import { EditorState, StateField, Facet, Extension } from '@codemirror/state'; @@ -276,17 +298,18 @@ export const LanguageHighlighter: Extension = // Editor component // ----------------------------------------------------------------------------- -export type Editor = [ EditorView | null, JSX.Element ]; +export interface Editor { view: EditorView | null; component: JSX.Element } export function Editor(extensions: Extension[]): Editor { const parent = React.useRef(null); const editor = React.useRef<EditorView | null>(null); + const component = <div className='cm-global-box' ref={parent} />; React.useEffect(() => { if (!parent.current) return; const state = EditorState.create({ extensions }); editor.current = new EditorView({ state, parent: parent.current }); - }, [parent]); - return [ editor.current, <div className='cm-global-box' ref={parent} /> ]; + }, [parent, extensions]); + return { view: editor.current, component }; } // ----------------------------------------------------------------------------- diff --git a/ivette/src/frama-c/kernel/ASTview.tsx b/ivette/src/frama-c/kernel/ASTview.tsx index 2adc5b73ec7bd8690e8383d4efae2e42ab390093..61fb3192a7e48d01bfa1c0cc396df71eaab1f05d 100644 --- a/ivette/src/frama-c/kernel/ASTview.tsx +++ b/ivette/src/frama-c/kernel/ASTview.tsx @@ -20,10 +20,6 @@ /* */ /* ************************************************************************ */ -// -------------------------------------------------------------------------- -// --- AST Source Code -// -------------------------------------------------------------------------- - import React from 'react'; import Lodash from 'lodash'; @@ -594,7 +590,7 @@ const baseExtensions: Editor.Extension[] = [ // The component in itself. export default function ASTview(): JSX.Element { - const [view, editor] = Editor.Editor(baseExtensions); + const { view, component } = Editor.Editor(baseExtensions); // Updating CodeMirror when the selection or its callback are changed. const [selection, updateSelection] = States.useSelection(); @@ -629,7 +625,7 @@ export default function ASTview(): JSX.Element { Callers.set(view, useFctCallers(fct)); TaintedLvalues.set(view, useFctTaints(fct)); - return editor; + return component; } // --------------------------------------------------------------------------