Skip to content

Commit 763040f

Browse files
committed
Add Codemirror search functionality
Update Codemirror to latest Update Codemirror typings to latest Add code mirror search functionality (include needed addons) Add some styling of replace search buttons by adding css to StyledContainer in CodeEditordd Add extraKeys: esc when search dialog found something and marked it - to clear the serach contents (without need of calling the serach again) Add extraKeys: Alt+F - persistant find/search to have dialog persistent while searching
1 parent 37d5c7c commit 763040f

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@babel/preset-react": "^7.0.0",
4747
"@babel/preset-typescript": "^7.6.0",
4848
"@testing-library/react-hooks": "^2.0.1",
49-
"@types/codemirror": "0.0.77",
49+
"@types/codemirror": "0.0.98",
5050
"@types/dashify": "^1.0.0",
5151
"@types/filenamify": "^2.0.2",
5252
"@types/history": "^4.7.3",
@@ -110,7 +110,7 @@
110110
"@mdi/react": "^1.2.1",
111111
"aws-amplify": "^1.2.4",
112112
"classcat": "^4.0.2",
113-
"codemirror": "^5.49.0",
113+
"codemirror": "^5.58.2",
114114
"codemirror-abap": "^0.2.2",
115115
"coffeescript": "^2.4.1",
116116
"copy-to-clipboard": "^3.3.1",

src/components/atoms/CodeEditor.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import CodeMirror, { getCodeMirrorTheme } from '../../lib/CodeMirror'
33
import styled from '../../lib/styled'
4+
import { borderRight } from '../../lib/styled/styleFunctions'
45
import {
56
EditorIndentTypeOptions,
67
EditorIndentSizeOptions,
@@ -11,6 +12,27 @@ const StyledContainer = styled.div`
1112
.CodeMirror {
1213
font-family: inherit;
1314
}
15+
16+
.CodeMirror-dialog button {
17+
// font-size: 70%;
18+
background-color: transparent;
19+
cursor: pointer;
20+
height: 26px;
21+
line-height: 26px;
22+
padding: 0 15px;
23+
transition: color 200ms ease-in-out;
24+
color: ${({ theme }) => theme.primaryDarkerColor};
25+
border: none;
26+
${borderRight}
27+
&:last-child {
28+
border-right: none;
29+
}
30+
}
31+
32+
.CodeMirror-dialog button:hover {
33+
color: ${({ theme }) => theme.primaryButtonLabelColor};
34+
background-color: ${({ theme }) => theme.primaryColor};
35+
}
1436
`
1537

1638
const defaultCodeMirrorOptions: CodeMirror.EditorConfiguration = {
@@ -60,6 +82,8 @@ class CodeEditor extends React.Component<CodeEditorProps> {
6082
extraKeys: {
6183
Enter: 'newlineAndIndentContinueMarkdownList',
6284
Tab: 'indentMore',
85+
"Alt-F": "findPersistent",
86+
Esc: "clearSearch"
6387
},
6488
})
6589
this.codeMirror.on('change', this.handleCodeMirrorChange)

src/lib/CodeMirror.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import 'codemirror/addon/runmode/runmode'
33
import 'codemirror/addon/mode/overlay'
44
import 'codemirror/addon/comment/comment'
55
import 'codemirror/addon/edit/continuelist'
6+
import 'codemirror/addon/dialog/dialog'
7+
import 'codemirror/addon/search/search'
8+
import 'codemirror/addon/search/searchcursor'
9+
import 'codemirror/addon/search/jump-to-line'
10+
import 'codemirror/addon/dialog/dialog.css'
611
import 'codemirror/mode/markdown/markdown'
712
import 'codemirror/mode/gfm/gfm'
813
import 'codemirror/mode/xml/xml'

0 commit comments

Comments
 (0)