feat: add handlers for different actions

This commit is contained in:
Jacob Kim 2025-08-14 19:18:13 -07:00
parent 1ee5e1f331
commit 2de814bbff
3 changed files with 168 additions and 0 deletions

View file

@ -0,0 +1,58 @@
package com.github.continuedev.continueintellijextension.listeners
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.project.Project
/**
* Handler for cursor movements during typing sessions.
* Preserves the chain when user is actively typing.
*/
class TypingSessionHandler(
private val project: Project
) : CursorMovementHandler {
override val handlerId = "typingSession"
private var lastDocumentChangeTime = 0L
private val TYPING_DELAY = 1000L // ms - consider movements within this time as typing
fun updateTypingTime() {
lastDocumentChangeTime = System.currentTimeMillis()
}
override suspend fun onCursorMoved(
editor: Editor,
oldPosition: LogicalPosition?,
newPosition: LogicalPosition
): Boolean {
val now = System.currentTimeMillis()
val timeSinceLastEdit = now - lastDocumentChangeTime
// If recent document change and cursor moved forward/down, likely typing
if (timeSinceLastEdit < TYPING_DELAY) {
val isTypingMovement = oldPosition?.let { old ->
// Same line, moving forward
(newPosition.line == old.line && newPosition.column > old.column) ||
// Next line, typical of pressing Enter
(newPosition.line == old.line + 1 && newPosition.column <= old.column)
} ?: false
if (isTypingMovement) {
println("TypingSessionHandler: Cursor movement during typing session")
return true
}
}
println("TypingSessionHandler: Not a typing movement (time since edit: ${timeSinceLastEdit}ms)")
return false
}
override fun onDeactivated() {
println("TypingSessionHandler: Deactivated")
}
override fun dispose() {
onDeactivated()
}
}

View file

@ -0,0 +1,61 @@
package com.github.continuedev.continueintellijextension.nextEdit
import com.github.continuedev.continueintellijextension.listeners.CursorMovementHandler
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.project.Project
/**
* Handler for cursor movements during jump operations.
*/
class NextEditJumpHandler(
private val project: Project,
private val jumpManager: NextEditJumpManager
) : CursorMovementHandler {
override val handlerId = "nextEditJump"
override suspend fun onCursorMoved(
editor: Editor,
oldPosition: LogicalPosition?,
newPosition: LogicalPosition
): Boolean {
// Check if we're still in a jump operation
if (!jumpManager.isJumpInProgress()) {
// Jump is no longer in progress, cursor movement is deliberate
return false
}
val jumpPosition = jumpManager.getJumpPosition()
val originalPosition = jumpManager.getOriginalPosition()
return when {
// Cursor moved to the expected jump position - this is expected
jumpPosition != null && newPosition == jumpPosition -> {
println("NextEditJumpHandler: Cursor moved to expected jump position")
true
}
// Cursor is still at the original position - no movement yet
originalPosition != null && newPosition == originalPosition -> {
println("NextEditJumpHandler: Cursor still at original position")
true
}
// Cursor moved somewhere else - user moved manually, abort jump
else -> {
println("NextEditJumpHandler: Cursor moved to unexpected position, aborting jump")
jumpManager.abortJump()
false
}
}
}
override fun onDeactivated() {
println("NextEditJumpHandler: Deactivated")
}
override fun dispose() {
onDeactivated()
}
}

View file

@ -0,0 +1,49 @@
package com.github.continuedev.continueintellijextension.nextEdit
import com.github.continuedev.continueintellijextension.listeners.CursorMovementHandler
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.project.Project
/**
* Handler for cursor movements during next edit window operations.
*/
class NextEditWindowHandler(
private val project: Project,
private val windowManager: NextEditWindowManager,
private val expectedPosition: LogicalPosition
) : CursorMovementHandler {
override val handlerId = "nextEditWindow"
override suspend fun onCursorMoved(
editor: Editor,
oldPosition: LogicalPosition?,
newPosition: LogicalPosition
): Boolean {
// Check if window was just accepted
if (windowManager.hasAccepted()) {
println("NextEditWindowHandler: Window was accepted, cursor movement is expected")
return true
}
// Check if cursor is still near the expected position (within the same line)
if (newPosition.line == expectedPosition.line) {
println("NextEditWindowHandler: Cursor movement within same line as suggestion")
return true
}
// User moved away from the suggestion area - close window and treat as deliberate
println("NextEditWindowHandler: Cursor moved away from suggestion area")
windowManager.hideAllNextEditWindows()
return false
}
override fun onDeactivated() {
println("NextEditWindowHandler: Deactivated")
}
override fun dispose() {
onDeactivated()
}
}