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) {