Skip to content

Commit 7b58f6d

Browse files
authored
Merge pull request #3639 from processing/cm6-search-and-find
Codemirror 6 update: add MVP search and find
2 parents 7290b04 + 004f890 commit 7b58f6d

File tree

9 files changed

+36
-877
lines changed

9 files changed

+36
-877
lines changed

client/modules/IDE/components/Editor/codemirror.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { autocompletion, closeBrackets } from '@codemirror/autocomplete';
99
// import 'codemirror/addon/search/jump-to-line';
1010

1111
import { debounce } from 'lodash';
12+
import { openSearchPanel } from '@codemirror/search';
1213

1314
import {
1415
getFileMode,
@@ -20,9 +21,6 @@ import { useEffectWithComparison } from '../../hooks/custom-hooks';
2021
import tidyCodeWithPrettier from './tidier';
2122

2223
// ----- GENERAL TODOS (in order of priority) -----
23-
// - autocomplete (hinter)
24-
// - p5-javascript
25-
// - search, find & replace
2624
// - color themes
2725
// - any features lost in the p5 conversion git merge
2826
// - javascript color picker (extension works for css but needs to be forked for js)
@@ -208,13 +206,9 @@ export default function useCodeMirror({
208206
return updatedFile;
209207
};
210208

211-
// TODO: Add find and replace functionality.
212-
// const showFind = () => {
213-
// cmInstance.current.execCommand('findPersistent');
214-
// };
215-
// const showReplace = () => {
216-
// cmInstance.current.execCommand('replace');
217-
// };
209+
const showSearch = () => {
210+
openSearchPanel(cmView.current);
211+
};
218212

219213
const tidyCode = () => {
220214
const fileMode = getFileMode(file.name);
@@ -225,8 +219,7 @@ export default function useCodeMirror({
225219
setupCodeMirrorOnContainerMounted,
226220
teardownCodeMirror,
227221
getContent,
228-
tidyCode
229-
// showFind,
230-
// showReplace
222+
tidyCode,
223+
showSearch
231224
};
232225
}

client/modules/IDE/components/Editor/index.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ function Editor({
8787
teardownCodeMirror,
8888
// cmInstance,
8989
getContent,
90-
tidyCode
91-
// showFind,
92-
// showReplace
90+
tidyCode,
91+
showSearch
9392
} = useCodeMirror({
9493
theme,
9594
lineNumbers,
@@ -115,9 +114,7 @@ function Editor({
115114
provideController({
116115
tidyCode,
117116
getContent,
118-
// TODO: Reimplement these.
119-
showFind: () => {},
120-
showReplace: () => {}
117+
showSearch
121118
});
122119
}, [getContent]);
123120

client/modules/IDE/components/Editor/stateUtils.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ import {
2020
syntaxHighlighting,
2121
defaultHighlightStyle
2222
} from '@codemirror/language';
23-
import { highlightSelectionMatches } from '@codemirror/search';
2423
import {
2524
autocompletion,
2625
closeBrackets,
2726
closeBracketsKeymap
2827
} from '@codemirror/autocomplete';
28+
import {
29+
highlightSelectionMatches,
30+
search,
31+
searchKeymap
32+
} from '@codemirror/search';
2933
import {
3034
defaultKeymap,
3135
history,
@@ -297,7 +301,8 @@ export function createNewFileState(filename, document, settings) {
297301
closeBracketsKeymap,
298302
defaultKeymap,
299303
historyKeymap,
300-
foldKeymap
304+
foldKeymap,
305+
searchKeymap
301306
];
302307

303308
// https://github.com/codemirror/basic-setup/blob/main/src/codemirror.ts
@@ -312,6 +317,7 @@ export function createNewFileState(filename, document, settings) {
312317

313318
// Everything below here should always be on.
314319
history(),
320+
search(),
315321
// Highlight extensions
316322
highlightActiveLine(),
317323
highlightActiveLineGutter(),

client/modules/IDE/components/Header/MobileNav.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ const MoreMenu = () => {
427427
<MobileMenuItem onClick={cmRef.current?.tidyCode}>
428428
{t('Nav.Edit.TidyCode')}
429429
</MobileMenuItem>
430-
<MobileMenuItem onClick={cmRef.current?.showFind}>
430+
<MobileMenuItem onClick={cmRef.current?.showSearch}>
431431
{t('Nav.Edit.Find')}
432432
</MobileMenuItem>
433433
<b>{t('Nav.Sketch.Title')}</b>

client/modules/IDE/components/Header/Nav.jsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ const ProjectMenu = () => {
169169
shareSketch
170170
} = useSketchActions();
171171

172-
const replaceCommand =
173-
metaKey === 'Ctrl' ? `${metaKeyName}+H` : `${metaKeyName}+⌥+F`;
174172
const newFileCommand =
175173
metaKey === 'Ctrl' ? `${metaKeyName}+Alt+N` : `${metaKeyName}+⌥+N`;
176174

@@ -242,14 +240,10 @@ const ProjectMenu = () => {
242240
{t('Nav.Edit.TidyCode')}
243241
<span className="nav__keyboard-shortcut">{metaKeyName}+Shift+F</span>
244242
</MenubarItem>
245-
<MenubarItem id="edit-find" onClick={cmRef.current?.showFind}>
243+
<MenubarItem id="edit-find" onClick={cmRef.current?.showSearch}>
246244
{t('Nav.Edit.Find')}
247245
<span className="nav__keyboard-shortcut">{metaKeyName}+F</span>
248246
</MenubarItem>
249-
<MenubarItem id="edit-replace" onClick={cmRef.current?.showReplace}>
250-
{t('Nav.Edit.Replace')}
251-
<span className="nav__keyboard-shortcut">{replaceCommand}</span>
252-
</MenubarItem>
253247
</MenubarSubmenu>
254248
<MenubarSubmenu id="sketch" title={t('Nav.Sketch.Title')}>
255249
<MenubarItem

client/modules/IDE/components/Header/__snapshots__/Nav.unit.test.jsx.snap

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -586,14 +586,6 @@ exports[`Nav renders editor version for desktop 1`] = `
586586
Ctrl+F
587587
</span>
588588
</li>
589-
<li>
590-
Replace
591-
<span
592-
class="nav__keyboard-shortcut"
593-
>
594-
Ctrl+H
595-
</span>
596-
</li>
597589
</ul>
598590
</li>
599591
<li

0 commit comments

Comments
 (0)