Skip to content

Commit a6b44a1

Browse files
Merge pull request #2112 from vagostep/feature/2111/emit-editor-index-onfocus
#2111 Adding to onFocus event for Split editor, the index of the editor focused
2 parents aa23641 + 4967394 commit a6b44a1

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

docs/Split.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ render(
6767
| onPaste | | Function | Triggered by editor `paste` event, and passes text as argument |
6868
| onSelectionChange | | Function | triggered by editor `selectionChange` event, and passes a [Selection](https://ace.c9.io/#nav=api&api=selection) as it's first argument and the event as the second |
6969
| onCursorChange | | Function | triggered by editor `changeCursor` event, and passes a [Selection](https://ace.c9.io/#nav=api&api=selection) as it's first argument and the event as the second |
70-
| onFocus | | Function | triggered by editor `focus` event |
70+
| onFocus | | Function | triggered by editor `focus` event, and passes the index of the edifor focused as it's first argument and the event as the second |
7171
| onBlur | | Function | triggered by editor `blur` event |
7272
| onInput | | Function | triggered by editor `input` event |
7373
| onScroll | | Function | triggered by editor `scroll` event |

example/split.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class App extends Component {
6060
value: newValue
6161
});
6262
}
63+
onFocus(event, index) {
64+
console.log(`Editor ${index} has been focused. Event emitted: `, event);
65+
}
6366

6467
onSelectionChange(newValue, event) {
6568
console.log("select-change", newValue);
@@ -337,6 +340,7 @@ class App extends Component {
337340
splits={this.state.splits}
338341
theme={this.state.theme}
339342
name="blah2"
343+
onFocus={this.onFocus}
340344
onLoad={this.onLoad}
341345
debounceChangePeriod={1000}
342346
onChange={this.onChange}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
"node-forge": "1.3.1",
5151
"prettier": "^3.2.5",
5252
"pretty-quick": "^4.0.0",
53-
"react": "^19.0.0",
54-
"react-dom": "^19.0.0",
53+
"react": "^19.1.0",
54+
"react-dom": "^19.1.0",
5555
"react-test-renderer": "^19.0.0",
5656
"rimraf": "6.0.1",
5757
"ts-loader": "^9.5.1",

src/split.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export interface ISplitEditorProps {
6464
onSelection?: (selectedText: string, event?: any) => void;
6565
onCopy?: (value: string) => void;
6666
onPaste?: (value: string) => void;
67-
onFocus?: (value: Event) => void;
67+
onFocus?: (value: Event, index: number) => void;
6868
onBlur?: (value: Event) => void;
6969
onScroll?: (editor: IEditorProps) => void;
7070
editorProps?: IEditorProps;
@@ -257,7 +257,7 @@ export default class SplitComponent extends React.Component<ISplitEditorProps> {
257257
editor.renderer.setShowGutter(showGutter);
258258
editor.getSession().setUseWrapMode(wrapEnabled);
259259
editor.setShowPrintMargin(showPrintMargin);
260-
editor.on("focus", this.onFocus);
260+
editor.on("focus", event => this.onFocus(event, index));
261261
editor.on("blur", this.onBlur);
262262
editor.on("input" as any, this.onInput);
263263
editor.on("copy", this.onCopy as any);
@@ -459,9 +459,9 @@ export default class SplitComponent extends React.Component<ISplitEditorProps> {
459459
this.props.onCursorChange(value, event);
460460
}
461461
}
462-
public onFocus(event: any) {
462+
public onFocus(event: any, index: number) {
463463
if (this.props.onFocus) {
464-
this.props.onFocus(event);
464+
this.props.onFocus(event, index);
465465
}
466466
}
467467

tests/src/split.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ describe("Split Component", () => {
309309
expect(onPasteCallback).toBeCalledWith(expectText);
310310
});
311311

312-
it.skip("should call the onFocus method callback", () => {
312+
it("should call the onFocus method callback", () => {
313313
const onFocusCallback = jest.fn();
314314
const wrapper = mount(
315315
<SplitEditor

0 commit comments

Comments
 (0)