Skip to content

Commit 7a2a1e9

Browse files
committed
refactor(diff-editor): add focus and blur event
1 parent 845b139 commit 7a2a1e9

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

projects/code-editor/diff-editor.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,21 @@ export class DiffEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
130130
/** Event emitted when the editor's original value changes. */
131131
@Output() originalValueChange = new EventEmitter<string>();
132132

133+
/** Event emitted when focus on the original editor. */
134+
@Output() originalFocus = new EventEmitter<void>();
135+
136+
/** Event emitted when blur on the original editor. */
137+
@Output() originalBlur = new EventEmitter<void>();
138+
133139
/** Event emitted when the editor's modified value changes. */
134140
@Output() modifiedValueChange = new EventEmitter<string>();
135141

142+
/** Event emitted when focus on the modified editor. */
143+
@Output() modifiedFocus = new EventEmitter<void>();
144+
145+
/** Event emitted when blur on the modified editor. */
146+
@Output() modifiedBlur = new EventEmitter<void>();
147+
136148
private _onChange: (value: DiffEditorModel) => void = () => {};
137149
private _onTouched: () => void = () => {};
138150

@@ -224,6 +236,26 @@ export class DiffEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
224236
diffConfig: this.diffConfig,
225237
});
226238

239+
this.mergeView?.a.contentDOM.addEventListener('focus', () => {
240+
this._onTouched();
241+
this.originalFocus.emit();
242+
});
243+
244+
this.mergeView?.a.contentDOM.addEventListener('blur', () => {
245+
this._onTouched();
246+
this.originalBlur.emit();
247+
});
248+
249+
this.mergeView?.b.contentDOM.addEventListener('focus', () => {
250+
this._onTouched();
251+
this.modifiedFocus.emit();
252+
});
253+
254+
this.mergeView?.b.contentDOM.addEventListener('blur', () => {
255+
this._onTouched();
256+
this.modifiedBlur.emit();
257+
});
258+
227259
this.setEditable('a', !this.disabled);
228260
this.setEditable('b', !this.disabled);
229261
}

0 commit comments

Comments
 (0)