-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Listen to editor events instead of polling
- Loading branch information
Showing
5 changed files
with
70 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package code_view.client_idea.utils | ||
|
||
import com.intellij.openapi.editor.EditorFactory | ||
import com.intellij.openapi.editor.event.* | ||
|
||
|
||
class EditorListener(val ctx: Context) : CaretListener, DocumentListener, SelectionListener, VisibleAreaListener { | ||
val editorManager: EditorEventMulticaster = EditorFactory.getInstance().eventMulticaster | ||
|
||
fun listen() { | ||
editorManager.addDocumentListener(this) | ||
editorManager.addSelectionListener(this) | ||
editorManager.addCaretListener(this) | ||
editorManager.addVisibleAreaListener(this) | ||
} | ||
|
||
fun stop() { | ||
editorManager.removeSelectionListener(this) | ||
editorManager.removeDocumentListener(this) | ||
editorManager.removeCaretListener(this) | ||
editorManager.removeVisibleAreaListener(this) | ||
} | ||
|
||
override fun documentChanged(event: DocumentEvent) { | ||
ctx.sync.sync() | ||
} | ||
|
||
override fun caretAdded(caretEvent: CaretEvent) { | ||
ctx.sync.sync() | ||
} | ||
|
||
override fun caretRemoved(caretEvent: CaretEvent) { | ||
ctx.sync.sync() | ||
} | ||
|
||
override fun beforeDocumentChange(event: DocumentEvent) { | ||
ctx.sync.sync() | ||
} | ||
|
||
override fun caretPositionChanged(event: CaretEvent) { | ||
ctx.sync.sync() | ||
} | ||
|
||
override fun visibleAreaChanged(event: VisibleAreaEvent) { | ||
ctx.sync.sync() | ||
} | ||
|
||
override fun selectionChanged(event: SelectionEvent) { | ||
ctx.sync.sync() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters