ghost: fix completion overlapping existing document text
- Don't show inline ghost note when cursor is mid-line (text exists after cursor) — the ghost would visually conflict with real content - Only show multi-line overlay when cursor is near EOF, so continuation lines don't paint on top of existing document lines - Tab-accept still works regardless of visual display
This commit is contained in:
parent
9887751690
commit
d90a2e6f27
|
|
@ -144,12 +144,13 @@ QVector<int> OllieGhostProvider::inlineNotes(int line) const
|
|||
if (m_suggestionLines[0].isEmpty())
|
||||
return {};
|
||||
|
||||
// Don't show ghost text if cursor was mid-line — the suggestion would
|
||||
// visually overlap or conflict with existing text after the cursor.
|
||||
int lineLen = m_view->document()->lineLength(line);
|
||||
int col = m_suggestionStartCol;
|
||||
if (col < lineLen)
|
||||
col = lineLen;
|
||||
if (m_suggestionStartCol < lineLen)
|
||||
return {};
|
||||
|
||||
return {col};
|
||||
return {lineLen};
|
||||
}
|
||||
|
||||
QSize OllieGhostProvider::inlineNoteSize(const KTextEditor::InlineNote ¬e) const
|
||||
|
|
@ -367,9 +368,18 @@ void OllieGhostProvider::onCompletionReply(const QString &result)
|
|||
// Notify Kate to repaint the first line (inline note)
|
||||
emit inlineNotesChanged(m_suggestionStartLine);
|
||||
|
||||
// Show overlay for continuation lines (if multi-line)
|
||||
// Show overlay for continuation lines only if they won't overlap
|
||||
// existing document content (i.e. cursor is at or near EOF).
|
||||
if (m_suggestionLines.size() > 1) {
|
||||
showOverlay();
|
||||
auto *doc = m_view->document();
|
||||
int linesBelow = doc->lines() - 1 - m_suggestionStartLine;
|
||||
int continuationLines = m_suggestionLines.size() - 1;
|
||||
|
||||
// Only show overlay if there's enough empty space below
|
||||
// (cursor line is within continuationLines of EOF)
|
||||
if (linesBelow <= continuationLines) {
|
||||
showOverlay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -439,7 +449,12 @@ void OllieGhostProvider::showSuggestionFromHistory()
|
|||
|
||||
emit inlineNotesChanged(m_suggestionStartLine);
|
||||
if (m_suggestionLines.size() > 1) {
|
||||
showOverlay();
|
||||
auto *doc = m_view->document();
|
||||
int linesBelow = doc->lines() - 1 - m_suggestionStartLine;
|
||||
int continuationLines = m_suggestionLines.size() - 1;
|
||||
if (linesBelow <= continuationLines) {
|
||||
showOverlay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in New Issue