Last active
September 12, 2021 12:01
-
-
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)
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
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 | |
} |
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
This is not working on windows