Skip to content

Commit 3bbbb2c

Browse files
committed
fix: Correct taking content after cursor
1 parent ca0fb5e commit 3bbbb2c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

context/DocumentContextReader.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,20 @@ QString DocumentContextReader::getContextBetween(int startLine, int endLine, int
184184
if (!block.isValid()) {
185185
break;
186186
}
187-
if (i == endLine) {
187+
188+
if (i == startLine && cursorPosition >= 0) {
189+
QString text = block.text();
190+
if (cursorPosition < text.length()) {
191+
context += text.mid(cursorPosition);
192+
}
193+
} else if (i == endLine && cursorPosition >= 0) {
188194
context += block.text().left(cursorPosition);
189195
} else {
190-
context += block.text() + "\n";
196+
context += block.text();
197+
}
198+
199+
if (i < endLine) {
200+
context += "\n";
191201
}
192202
}
193203

@@ -238,7 +248,7 @@ QString DocumentContextReader::getContextAfter(int lineNumber, int cursorPositio
238248
int endLine = qMin(
239249
m_document->blockCount() - 1,
240250
lineNumber + Settings::codeCompletionSettings().readStringsAfterCursor());
241-
return getContextBetween(lineNumber + 1, endLine, -1);
251+
return getContextBetween(lineNumber, endLine, cursorPosition);
242252
}
243253
}
244254

0 commit comments

Comments
 (0)