Skip to content

Commit 3d29515

Browse files
committed
fix docs for selection, add support for renderLine
1 parent b829b85 commit 3d29515

File tree

8 files changed

+46
-8
lines changed

8 files changed

+46
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
5.1.0
2+
==================
3+
* add support for `renderLine` (#98)
4+
5+
16
5.0.3
27
==================
38
* #88

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,18 @@ require('codemirror/mode/javascript/javascript');
105105
onScroll={(editor, data) => {}}
106106
/>
107107
```
108-
- `selection={array<{anchor, head}>}` - *[setSelections](https://codemirror.net/doc/manual.html#setSelections)*
108+
- `selection={{ranges: array<{anchor, head}>, focus?: boolean}` - *[setSelections](https://codemirror.net/doc/manual.html#setSelections)*
109109
> will programmatically select the ranges specified
110110
```jsx
111111
<CodeMirror
112112
[...]
113-
selection={[{
114-
anchor: {ch: 8, line: 5},
115-
head: {ch: 37, line: 5}
116-
}]}
113+
selection={{
114+
ranges: [{
115+
anchor: {ch: 8, line: 5},
116+
head: {ch: 37, line: 5}
117+
}],
118+
focus: true // defaults false if not specified
119+
}}
117120
onSelection={(editor, data) => {}}
118121
/>
119122
```

docs/app.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

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

index.js

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-codemirror2",
3-
"version": "5.0.4",
3+
"version": "5.1.0",
44
"description": "a tiny react codemirror component wrapper",
55
"main": "index.js",
66
"typings": "index.d.ts",

src/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export interface ICodeMirror {
7878
onKeyUp?: DomEvent;
7979
onMouseDown?: DomEvent;
8080
onPaste?: DomEvent;
81+
onRenderLine?: (editor: IInstance, line: codemirror.LineHandle, element: HTMLElement) => void;
8182
onScroll?: (editor: IInstance, data: codemirror.ScrollInfo) => void;
8283
onSelection?: (editor: IInstance, data: IGetSelectionOptions) => void;
8384
onTouchStart?: DomEvent;
@@ -206,7 +207,6 @@ class Shared implements ICommon {
206207
public wire(props: IControlledCodeMirror | IUnControlledCodeMirror) {
207208

208209
Object.keys(props || {}).filter(p => /^on/.test(p)).forEach(prop => {
209-
210210
switch (prop) {
211211
case 'onBlur': {
212212
(this.editor as any).on('blur', (cm, event) => {
@@ -322,6 +322,12 @@ class Shared implements ICommon {
322322
});
323323
break;
324324
}
325+
case 'onRenderLine': {
326+
this.editor.on('renderLine', (cm, line, element) => {
327+
this.props.onRenderLine(this.editor, line, element);
328+
});
329+
break;
330+
}
325331
case 'onScroll': {
326332
this.editor.on('scroll', (cm) => {
327333
this.props.onScroll(this.editor, this.editor.getScrollInfo());

test/index.spec.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ describe('DOM Events', () => {
187187
wrapper.instance().editor.getInputField().blur();
188188
expect(callback.called).toBeTruthy();
189189
});
190+
191+
it('onRenderLine(editor, line, element)', () => {
192+
193+
let callback;
194+
195+
let wrapper = Enzyme.mount(
196+
<Controlled
197+
value='foo'
198+
onRenderLine={(editor, line, element) => {
199+
callback = sinon.spy();
200+
callback();
201+
}}/>
202+
);
203+
wrapper.setProps({value: 'bar'});
204+
expect(callback.called).toBeTruthy();
205+
});
190206
});
191207

192208
describe('Change', () => {

0 commit comments

Comments
 (0)