Skip to content
Snippets Groups Projects
Commit 2e8bdcd2 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

Merge branch 'feature/ivette/search-ast' into 'master'

[Ivette] Allow searching text in the AST view

See merge request frama-c/frama-c!4846
parents 45a098e6 6bdd3a9c
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,8 @@ import { DOMEventMap as EventMap } from '@codemirror/view'; ...@@ -32,7 +32,8 @@ import { DOMEventMap as EventMap } from '@codemirror/view';
import { GutterMarker, gutter } from '@codemirror/view'; import { GutterMarker, gutter } from '@codemirror/view';
import { Tooltip, showTooltip } from '@codemirror/view'; import { Tooltip, showTooltip } from '@codemirror/view';
import { lineNumbers, keymap } from '@codemirror/view'; import { lineNumbers, keymap } from '@codemirror/view';
import { searchKeymap, search, openSearchPanel } from '@codemirror/search'; import { searchKeymap, search, openSearchPanel, closeSearchPanel,
searchPanelOpen, gotoLine } from '@codemirror/search';
import { parser } from '@lezer/cpp'; import { parser } from '@lezer/cpp';
import { tags } from '@lezer/highlight'; import { tags } from '@lezer/highlight';
...@@ -357,10 +358,20 @@ export const LanguageHighlighter: Extension = ...@@ -357,10 +358,20 @@ export const LanguageHighlighter: Extension =
export const ReadOnly = EditorState.readOnly.of(true); export const ReadOnly = EditorState.readOnly.of(true);
export const toggleSearchPanel = (view: EditorView) : void => {
if (searchPanelOpen(view.state))
closeSearchPanel(view);
else
openSearchPanel(view);
};
const SearchAlternativeKey = [{ key: 'Alt-f', run: openSearchPanel }]; const SearchAlternativeKey = [{ key: 'Alt-f', run: openSearchPanel }];
const SearchKeymap = searchKeymap.slice(1).concat(SearchAlternativeKey); const SearchKeymap = searchKeymap.slice(1).concat(SearchAlternativeKey);
export const Search : Extension = [ search(), keymap.of(SearchKeymap) ]; export const Search : Extension = [ search(), keymap.of(SearchKeymap) ];
const GotoKeymap = [{ key: 'Alt-g', run: gotoLine }];
export const GotoLine : Extension = [ search(), keymap.of(GotoKeymap) ];
export const Selection = createSelectionField(); export const Selection = createSelectionField();
function createSelectionField(): Field<EditorSelection> { function createSelectionField(): Field<EditorSelection> {
const cursor = EditorSelection.cursor(0); const cursor = EditorSelection.cursor(0);
......
...@@ -29,6 +29,7 @@ import * as Utils from 'dome/data/arrays'; ...@@ -29,6 +29,7 @@ import * as Utils from 'dome/data/arrays';
import * as States from 'frama-c/states'; import * as States from 'frama-c/states';
import * as Settings from 'dome/data/settings'; import * as Settings from 'dome/data/settings';
import { IconButton } from 'dome/controls/buttons'; import { IconButton } from 'dome/controls/buttons';
import { Inset } from 'dome/frame/toolbars';
import * as Ast from 'frama-c/kernel/api/ast'; import * as Ast from 'frama-c/kernel/api/ast';
import { text } from 'frama-c/kernel/api/data'; import { text } from 'frama-c/kernel/api/data';
import * as Eva from 'frama-c/plugins/eva/api/general'; import * as Eva from 'frama-c/plugins/eva/api/general';
...@@ -663,6 +664,7 @@ const extensions: Editor.Extension[] = [ ...@@ -663,6 +664,7 @@ const extensions: Editor.Extension[] = [
Editor.ReadOnly, Editor.ReadOnly,
Editor.FoldGutter, Editor.FoldGutter,
Editor.LanguageHighlighter, Editor.LanguageHighlighter,
Editor.Search,
]; ];
// The component in itself. // The component in itself.
...@@ -711,9 +713,21 @@ export default function ASTview(): JSX.Element { ...@@ -711,9 +713,21 @@ export default function ASTview(): JSX.Element {
const taints = useTaints(scope); const taints = useTaints(scope);
React.useEffect(() => TaintedLvalues.set(view, taints), [view, taints]); React.useEffect(() => TaintedLvalues.set(view, taints), [view, taints]);
// Toggle search panel
const toggleSearchPanel = React.useCallback(() => {
if (view) Editor.toggleSearchPanel(view);
}, [view]);
return ( return (
<> <>
<TitleBar> <TitleBar>
<IconButton
icon="SEARCH"
enabled={!!scope}
onClick={toggleSearchPanel}
title='Search in AST'
/>
<Inset />
<IconButton <IconButton
icon={icon} icon={icon}
onClick={unFoldButtonClicked} onClick={unFoldButtonClicked}
......
...@@ -167,6 +167,7 @@ function useSourceFileContents(file: string | undefined): string { ...@@ -167,6 +167,7 @@ function useSourceFileContents(file: string | undefined): string {
// Necessary extensions. // Necessary extensions.
const extensions: Editor.Extension[] = [ const extensions: Editor.Extension[] = [
Source, Source,
Editor.GotoLine,
Editor.Search, Editor.Search,
Editor.ReadOnly, Editor.ReadOnly,
Editor.Selection, Editor.Selection,
...@@ -201,6 +202,10 @@ export default function SourceCode(): JSX.Element { ...@@ -201,6 +202,10 @@ export default function SourceCode(): JSX.Element {
const markerAtCursor = States.useRequestResponse(Ast.getMarkerAt, cursor); const markerAtCursor = States.useRequestResponse(Ast.getMarkerAt, cursor);
const { sloc: slocAtCursor } = States.useMarker(markerAtCursor); const { sloc: slocAtCursor } = States.useMarker(markerAtCursor);
const toggleSearchPanel = React.useCallback(() => {
if (view) Editor.toggleSearchPanel(view);
}, [view]);
const openFile = React.useCallback(() => { const openFile = React.useCallback(() => {
if (file) openSourceFile(command, file, getCursorPosition(view)); if (file) openSourceFile(command, file, getCursorPosition(view));
}, [ command, file, view ] }, [ command, file, view ]
...@@ -242,12 +247,19 @@ export default function SourceCode(): JSX.Element { ...@@ -242,12 +247,19 @@ export default function SourceCode(): JSX.Element {
<Ivette.TitleBar> <Ivette.TitleBar>
<Buttons.IconButton <Buttons.IconButton
icon="DUPLICATE" icon="DUPLICATE"
visible={!file} visible={!!file}
onClick={openFile} onClick={openFile}
title='externalEditorTitle' title='Open file in external editor'
/> />
<Labels.Code title={file}>{filename}</Labels.Code> <Labels.Code title={file}>{filename}</Labels.Code>
<Toolbars.Filler /> <Toolbars.Filler />
<Buttons.IconButton
icon="SEARCH"
enabled={!!file}
onClick={toggleSearchPanel}
title='Search in source code'
/>
<Toolbars.Inset />
<Buttons.IconButton <Buttons.IconButton
icon="HELP" icon="HELP"
onClick={displayShortcuts} onClick={displayShortcuts}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment