@@ -32,61 +32,61 @@ class Cursortracker(
3232 var remoteProxy: RemoteEthersyncClientProtocol ? = null
3333
3434 fun handleRemoteCursorEvent (cursorEvent : CursorEvent ) {
35- val fileEditorManager = FileEditorManager .getInstance(project)
36-
37- val fileEditor = fileEditorManager.allEditors
35+ val fileEditor = FileEditorManager .getInstance(project)
36+ .allEditors
37+ .filterIsInstance<TextEditor >()
38+ .filter { editor -> editor.file.canonicalFile != null }
3839 .firstOrNull { editor -> editor.file.canonicalFile!! .url == cursorEvent.documentUri } ? : return
3940
40- if (fileEditor is TextEditor ) {
41- val editor = fileEditor.editor
41+ val editor = fileEditor.editor
4242
43- cs.launch {
44- withContext(Dispatchers .EDT ) {
45- synchronized(highlighter) {
46- val markupModel = editor.markupModel
43+ cs.launch {
44+ withContext(Dispatchers .EDT ) {
45+ synchronized(highlighter) {
46+ val markupModel = editor.markupModel
47+
48+ val previous = highlighter.remove(cursorEvent.userId)
49+ if (previous != null ) {
50+ for (hl in previous) {
51+ markupModel.removeHighlighter(hl)
52+ }
53+ }
4754
48- val previous = highlighter.remove(cursorEvent.userId)
49- if (previous != null ) {
50- for (hl in previous) {
51- markupModel.removeHighlighter(hl)
52- }
55+ val newHighlighter = LinkedList <RangeHighlighter >()
56+ for (range in cursorEvent.ranges) {
57+ val startPosition = editor.logicalPositionToOffset(LogicalPosition (range.start.line, range.start.character))
58+ val endPosition = editor.logicalPositionToOffset(LogicalPosition (range.end.line, range.end.character))
59+
60+ val textAttributes = TextAttributes ().apply {
61+ // foregroundColor = JBColor(JBColor.YELLOW, JBColor.DARK_GRAY)
62+
63+ // TODO: unclear which is the best effect type
64+ effectType = EffectType .ROUNDED_BOX
65+ effectColor = JBColor (JBColor .YELLOW , JBColor .DARK_GRAY )
5366 }
5467
55- val newHighlighter = LinkedList <RangeHighlighter >()
56- for (range in cursorEvent.ranges) {
57- val startPosition = editor.logicalPositionToOffset(LogicalPosition (range.start.line, range.start.character))
58- val endPosition = editor.logicalPositionToOffset(LogicalPosition (range.end.line, range.end.character))
59-
60- val textAttributes = TextAttributes ().apply {
61- // foregroundColor = JBColor(JBColor.YELLOW, JBColor.DARK_GRAY)
62-
63- // TODO: unclear which is the best effect type
64- effectType = EffectType .ROUNDED_BOX
65- effectColor = JBColor (JBColor .YELLOW , JBColor .DARK_GRAY )
66- }
67-
68- val hl = markupModel.addRangeHighlighter(
69- startPosition,
70- endPosition + 1 ,
71- HighlighterLayer .ADDITIONAL_SYNTAX ,
72- textAttributes,
73- HighlighterTargetArea .EXACT_RANGE
74- )
75- if (cursorEvent.name != null ) {
76- hl.errorStripeTooltip = cursorEvent.name
77- }
78-
79- newHighlighter.add(hl)
68+ val hl = markupModel.addRangeHighlighter(
69+ startPosition,
70+ endPosition + 1 ,
71+ HighlighterLayer .ADDITIONAL_SYNTAX ,
72+ textAttributes,
73+ HighlighterTargetArea .EXACT_RANGE
74+ )
75+ if (cursorEvent.name != null ) {
76+ hl.errorStripeTooltip = cursorEvent.name
8077 }
81- highlighter[cursorEvent.userId] = newHighlighter
78+
79+ newHighlighter.add(hl)
8280 }
81+ highlighter[cursorEvent.userId] = newHighlighter
8382 }
8483 }
8584 }
8685 }
8786
8887 override fun caretPositionChanged (event : CaretEvent ) {
89- val uri = event.editor.virtualFile.canonicalFile!! .url
88+ val canonicalFile = event.editor.virtualFile?.canonicalFile ? : return
89+ val uri = canonicalFile.url
9090 val pos = Position (event.newPosition.line, event.newPosition.column)
9191 val range = Range (pos, pos)
9292 launchCursorRequest(CursorRequest (uri, Collections .singletonList(range)))
0 commit comments