Skip to content

Instantly share code, notes, and snippets.

@dkandalov
Last active September 12, 2021 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkandalov/11326385 to your computer and use it in GitHub Desktop.
Save dkandalov/11326385 to your computer and use it in GitHub Desktop.
Makes cursor move in circle (this is a mini-plugin for https://github.com/dkandalov/live-plugin)
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition
import liveplugin.PluginUtil
import static java.lang.Math.*
import static liveplugin.PluginUtil.*
if (isIdeStartup) return
def r = 10
def steps = 20
def editor = currentEditorIn(project)
def startX = editor.caretModel.logicalPosition.column
def startY = editor.caretModel.logicalPosition.line
def virtualSpace = editor.settings.virtualSpace
editor.settings.virtualSpace = true
doInBackground {
for (double a = 0; a <= 2 * PI; a += 2 * PI / steps) {
invokeOnEDT {
int x = clamp(-sin(a) * r * 2.5 + startX)
int y = clamp(-cos(a) * r + startY + r)
editor.caretModel.moveToLogicalPosition(new LogicalPosition(y, x))
}
Thread.sleep(30)
}
invokeOnEDT {
editor.settings.virtualSpace = virtualSpace
}
}
def clamp(n) {
n < 0 ? 0 : n
}
@humazed
Copy link

humazed commented Mar 8, 2019

This is not working on windows

@dkandalov
Copy link
Author

Hi. Sorry just read the message 🙄
I'm pretty sure this code doesn't depend on OS.

I updated the snippet to temporarily enable virtual space in the text editor (Settings -> Editor -> General -> Allow caret placement at the end of line). Maybe that was the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment