[editor] IJPL-793 clean up EditorImpl references on release

Signed-off-by: Stanislav Alekseev <stanislav.alekseev@jetbrains.com>

GitOrigin-RevId: 4147715ce92db7b5683a5c6fbca8cf7c9bbb43e9
This commit is contained in:
Stanislav Alekseev
2025-11-11 14:29:57 +00:00
committed by intellij-monorepo-bot
parent 71b9136858
commit 14b2a560f2
2 changed files with 7 additions and 5 deletions
@@ -46,8 +46,6 @@ internal class EditorCaretMoveService(coroutineScope: CoroutineScope) {
}
}
private val lastPosMap: MutableMap<Caret, Point2D> = ConcurrentHashMap()
/**
* Set the cursor position immediately without animation. This does not go through the
* coroutine-based logic which can delay the cursor position update. This is required for
@@ -56,7 +54,7 @@ internal class EditorCaretMoveService(coroutineScope: CoroutineScope) {
fun setCursorPositionImmediately(editor: EditorImpl) {
val animationStates = calculateUpdates(editor)
for (state in animationStates) {
lastPosMap[state.caret] = state.finalPos
editor.lastPosMap[state.caret] = state.finalPos
}
editor.myCaretCursor.setPositions(animationStates.map { state ->
EditorImpl.CaretRectangle(state.finalPos, state.width, state.caret, state.isRtl)
@@ -97,7 +95,7 @@ internal class EditorCaretMoveService(coroutineScope: CoroutineScope) {
val step = MILLIS_SECOND / (2 * refreshRate)
val animationStates = calculateUpdates(editor).map {
val lastPos = lastPosMap.getOrPut(it.caret) { it.finalPos }
val lastPos = editor.lastPosMap.getOrPut(it.caret) { it.finalPos }
AnimationState(lastPos, it)
}
@@ -132,7 +130,7 @@ internal class EditorCaretMoveService(coroutineScope: CoroutineScope) {
val y = startPos.y + (finalPos.y - startPos.y) * t
val interpolated = Point2D.Double(if (t >= 1) finalPos.x else x, if (t >= 1) finalPos.y else y)
lastPosMap[update.caret] = interpolated
editor.lastPosMap[update.caret] = interpolated
EditorImpl.CaretRectangle(interpolated, update.width, update.caret, update.isRtl)
}.toTypedArray()
@@ -127,6 +127,7 @@ import java.text.AttributedString;
import java.text.CharacterIterator;
import java.util.*;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
@@ -3177,6 +3178,9 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
}
}
@ApiStatus.Internal
final ConcurrentHashMap<Caret, Point2D> lastPosMap = new ConcurrentHashMap<>();
private final @NotNull EditorCaretMoveService caretMoveService = EditorCaretMoveService.getInstance();
private void setCursorPosition() {