Skip to content

Commit

Permalink
fix docs for selection, add support for renderLine
Browse files Browse the repository at this point in the history
  • Loading branch information
scniro committed Jul 1, 2018
1 parent b829b85 commit 3d29515
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
5.1.0
==================
* add support for `renderLine` (#98)


5.0.3
==================
* #88
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,18 @@ require('codemirror/mode/javascript/javascript');
onScroll={(editor, data) => {}}
/>
```
- `selection={array<{anchor, head}>}` - *[setSelections](https://codemirror.net/doc/manual.html#setSelections)*
- `selection={{ranges: array<{anchor, head}>, focus?: boolean}` - *[setSelections](https://codemirror.net/doc/manual.html#setSelections)*
> will programmatically select the ranges specified
```jsx
<CodeMirror
[...]
selection={[{
anchor: {ch: 8, line: 5},
head: {ch: 37, line: 5}
}]}
selection={{
ranges: [{
anchor: {ch: 8, line: 5},
head: {ch: 37, line: 5}
}],
focus: true // defaults false if not specified
}}
onSelection={(editor, data) => {}}
/>
```
Expand Down
2 changes: 1 addition & 1 deletion docs/app.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-codemirror2",
"version": "5.0.4",
"version": "5.1.0",
"description": "a tiny react codemirror component wrapper",
"main": "index.js",
"typings": "index.d.ts",
Expand Down
8 changes: 7 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface ICodeMirror {
onKeyUp?: DomEvent;
onMouseDown?: DomEvent;
onPaste?: DomEvent;
onRenderLine?: (editor: IInstance, line: codemirror.LineHandle, element: HTMLElement) => void;
onScroll?: (editor: IInstance, data: codemirror.ScrollInfo) => void;
onSelection?: (editor: IInstance, data: IGetSelectionOptions) => void;
onTouchStart?: DomEvent;
Expand Down Expand Up @@ -206,7 +207,6 @@ class Shared implements ICommon {
public wire(props: IControlledCodeMirror | IUnControlledCodeMirror) {

Object.keys(props || {}).filter(p => /^on/.test(p)).forEach(prop => {

switch (prop) {
case 'onBlur': {
(this.editor as any).on('blur', (cm, event) => {
Expand Down Expand Up @@ -322,6 +322,12 @@ class Shared implements ICommon {
});
break;
}
case 'onRenderLine': {
this.editor.on('renderLine', (cm, line, element) => {
this.props.onRenderLine(this.editor, line, element);
});
break;
}
case 'onScroll': {
this.editor.on('scroll', (cm) => {
this.props.onScroll(this.editor, this.editor.getScrollInfo());
Expand Down
16 changes: 16 additions & 0 deletions test/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ describe('DOM Events', () => {
wrapper.instance().editor.getInputField().blur();
expect(callback.called).toBeTruthy();
});

it('onRenderLine(editor, line, element)', () => {

let callback;

let wrapper = Enzyme.mount(
<Controlled
value='foo'
onRenderLine={(editor, line, element) => {
callback = sinon.spy();
callback();
}}/>
);
wrapper.setProps({value: 'bar'});
expect(callback.called).toBeTruthy();
});
});

describe('Change', () => {
Expand Down

0 comments on commit 3d29515

Please sign in to comment.