Skip to content

Commit f4dc069

Browse files
committed
1 parent ce6eff4 commit f4dc069

File tree

9 files changed

+19
-43
lines changed

9 files changed

+19
-43
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
5.0.0
2+
==================
3+
* #75 - remove `autoFocus` in favor of codemirror.options.autofocus
4+
15
4.3.0
26
==================
37
* #74 => add support for more DOM events => onContextMenu | onCopy | onCut | onDblClick | onDragLeave | onDragStart | onMouseDown | onPaste | onTouchStart

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ require('codemirror/mode/javascript/javascript');
7171

7272
| prop | type *`default`* | components | description |
7373
|--------------|------------------------|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------|
74-
| `autoCursor` | boolean *`true`* | `Controlled` `UnControlled` | should component cursor position correct when `value` changed |
75-
| `autoFocus` | boolean *`false`* | `Controlled` `UnControlled` | should component focus on mount |
74+
| `autoCursor` | boolean *`true`* | `Controlled` `UnControlled` | should component cursor position correct when `value` changed | |
7675
| `autoScroll` | boolean *`true`* | `Controlled` `UnControlled` | should component scroll cursor position into view when `value` changed |
7776
| `className` | string | `Controlled` `UnControlled` | pass through class *`class="react-codemirror2 className"`* |
7877
| `defineMode` | object | `Controlled` `UnControlled` | pass a [custom mode](http://marijnhaverbeke.nl/blog/codemirror-mode-system.html) via `{name: 'custom', fn: myModeFn}` |

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: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

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

package-lock.json

Lines changed: 1 addition & 1 deletion
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": "4.3.0",
3+
"version": "5.0.0",
44
"description": "a tiny react codemirror component wrapper",
55
"main": "index.js",
66
"typings": "index.d.ts",

src/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export interface DomEvent {
5050

5151
export interface ICodeMirror {
5252
autoCursor?: boolean; // default: true
53-
autoFocus?: boolean; // default: false
5453
autoScroll?: boolean; // default: false
5554
className?: string;
5655
cursor?: codemirror.Position;
@@ -165,7 +164,7 @@ class Shared implements ICommon {
165164

166165
// init cursor
167166
if (props && props.cursor) {
168-
this.delegateCursor(props.cursor, (props.autoScroll || false), (props.autoFocus || false));
167+
this.delegateCursor(props.cursor, (props.autoScroll || false), (this.editor.getOption('autofocus') || false));
169168
}
170169

171170
// init scroll
@@ -200,7 +199,7 @@ class Shared implements ICommon {
200199

201200
public applyUserDefined(props: IControlledCodeMirror | IUnControlledCodeMirror, preserved?: any) {
202201
if (preserved && preserved.cursor) {
203-
this.delegateCursor(preserved.cursor, (props.autoScroll || false), (props.autoFocus || false));
202+
this.delegateCursor(preserved.cursor, (props.autoScroll || false), (this.editor.getOption('autofocus') || false));
204203
}
205204
}
206205

@@ -562,6 +561,10 @@ export class Controlled extends React.Component<IControlledCodeMirror, any> {
562561

563562
this.shared.wire(this.props);
564563

564+
if (this.editor.getOption('autofocus')) {
565+
this.editor.focus();
566+
}
567+
565568
if (this.props.editorDidMount) {
566569
this.props.editorDidMount(this.editor, this.editor.getValue(), this.initCb);
567570
}

test/index.spec.tsx

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -853,38 +853,6 @@ describe('Props', () => {
853853
// </value>
854854

855855
// <misc>
856-
it('[Controlled]: autoFocus', () => {
857-
let wrapper = Enzyme.mount(
858-
<Controlled
859-
value='foo'
860-
autoFocus={true}
861-
cursor={{
862-
line: 0,
863-
ch: 3
864-
}}/>
865-
);
866-
867-
let editor = wrapper.instance().editor;
868-
869-
expect(editor.state.focused).toBeTruthy();
870-
});
871-
872-
it('[UnControlled]: autoFocus', () => {
873-
let wrapper = Enzyme.mount(
874-
<UnControlled
875-
value='foo'
876-
autoFocus={true}
877-
cursor={{
878-
line: 0,
879-
ch: 3
880-
}}/>
881-
);
882-
883-
let editor = wrapper.instance().editor;
884-
885-
expect(editor.state.focused).toBeTruthy();
886-
});
887-
888856
it('[UnControlled]: detached | should detach', () => {
889857
const spy = sinon.spy();
890858
const wrapper = Enzyme.mount(

0 commit comments

Comments
 (0)