From fefb10c63907ebadd92e3da2b4f7416fee7f0e3a Mon Sep 17 00:00:00 2001 From: Jakob Klaushofer Date: Fri, 4 Jul 2025 19:20:19 +0200 Subject: [PATCH] [ai-completion] IJPL-195112 Fix out of bounds document access on terminal resize GitOrigin-RevId: 53878f683772ff41c0298016ad19483b46e746ff --- .../com/intellij/terminal/frontend/ReworkedTerminalView.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/ReworkedTerminalView.kt b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/ReworkedTerminalView.kt index d03ce4ee4e50..b2d568434a16 100644 --- a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/ReworkedTerminalView.kt +++ b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/ReworkedTerminalView.kt @@ -465,6 +465,10 @@ internal class ReworkedTerminalView( val inlineCompletionTypingSession = InlineCompletion.getHandlerOrNull(editor)?.typingSessionTracker val lastBlock = editor.getUserData(TerminalBlocksModel.KEY)?.blocks?.lastOrNull() ?: return val lastBlockCommandStartIndex = if (lastBlock.commandStartOffset != -1) lastBlock.commandStartOffset else lastBlock.startOffset + + // When resizing the terminal, the blocks model may fall out of sync for a short time. + // These updates will never trigger a completion, so we return early to avoid reading out of bounds. + if (lastBlockCommandStartIndex >= editor.document.textLength) return val curCommandText = editor.document.text.substring(lastBlockCommandStartIndex, editor.document.textLength).trim() if (isTypeAhead) {