@@ -6,7 +6,7 @@ import {bracketMatching} from '@codemirror/language';
66import {
77 defaultKeymap , history , historyKeymap , indentWithTab ,
88} from '@codemirror/commands' ;
9- import { EditorState } from '@codemirror/state' ;
9+ import { Compartment , EditorState } from '@codemirror/state' ;
1010import { getTheme } from './themes' ;
1111
1212/**
@@ -17,12 +17,37 @@ function common(parentEl) {
1717 return [
1818 getTheme ( parentEl ) ,
1919 lineNumbers ( ) ,
20- highlightActiveLineGutter ( ) ,
2120 drawSelection ( ) ,
2221 dropCursor ( ) ,
2322 bracketMatching ( ) ,
2423 rectangularSelection ( ) ,
25- highlightActiveLine ( ) ,
24+ ] ;
25+ }
26+
27+ /**
28+ * @returns {({extension: Extension}|readonly Extension[])[] }
29+ */
30+ function getDynamicActiveLineHighlighter ( ) {
31+ const highlightingCompartment = new Compartment ( ) ;
32+ const domEvents = {
33+ focus ( event , view ) {
34+ view . dispatch ( {
35+ effects : highlightingCompartment . reconfigure ( [
36+ highlightActiveLineGutter ( ) ,
37+ highlightActiveLine ( ) ,
38+ ] ) ,
39+ } ) ;
40+ } ,
41+ blur ( event , view ) {
42+ view . dispatch ( {
43+ effects : highlightingCompartment . reconfigure ( [ ] ) ,
44+ } ) ;
45+ } ,
46+ } ;
47+
48+ return [
49+ highlightingCompartment . of ( [ ] ) ,
50+ EditorView . domEventHandlers ( domEvents ) ,
2651 ] ;
2752}
2853
@@ -33,6 +58,7 @@ function common(parentEl) {
3358export function viewerExtensions ( parentEl ) {
3459 return [
3560 ...common ( parentEl ) ,
61+ getDynamicActiveLineHighlighter ( ) ,
3662 keymap . of ( [
3763 ...defaultKeymap ,
3864 ] ) ,
@@ -47,6 +73,8 @@ export function viewerExtensions(parentEl) {
4773export function editorExtensions ( parentEl ) {
4874 return [
4975 ...common ( parentEl ) ,
76+ highlightActiveLineGutter ( ) ,
77+ highlightActiveLine ( ) ,
5078 history ( ) ,
5179 keymap . of ( [
5280 ...defaultKeymap ,
0 commit comments