From 5aaf3db2bad5e0aa0e0324f8183d68fb3f3b6625 Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Tue, 4 Mar 2025 15:33:29 +0100 Subject: [PATCH] fix: Correct taking content after cursor --- context/DocumentContextReader.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/context/DocumentContextReader.cpp b/context/DocumentContextReader.cpp index b0ba207..3bcdba3 100644 --- a/context/DocumentContextReader.cpp +++ b/context/DocumentContextReader.cpp @@ -180,10 +180,20 @@ QString DocumentContextReader::getContextBetween(int startLine, int endLine, int if (!block.isValid()) { break; } - if (i == endLine) { + + if (i == startLine && cursorPosition >= 0) { + QString text = block.text(); + if (cursorPosition < text.length()) { + context += text.mid(cursorPosition); + } + } else if (i == endLine && cursorPosition >= 0) { context += block.text().left(cursorPosition); } else { - context += block.text() + "\n"; + context += block.text(); + } + + if (i < endLine) { + context += "\n"; } } @@ -234,7 +244,7 @@ QString DocumentContextReader::getContextAfter(int lineNumber, int cursorPositio int endLine = qMin( m_document->blockCount() - 1, lineNumber + Settings::codeCompletionSettings().readStringsAfterCursor()); - return getContextBetween(lineNumber + 1, endLine, -1); + return getContextBetween(lineNumber, endLine, cursorPosition); } }