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:
Levi Neely 2026-08-06 13:49:22 +02:00
parent 9887751690
commit d90a2e6f27
1 changed files with 22 additions and 7 deletions

View File

@ -144,12 +144,13 @@ QVector<int> OllieGhostProvider::inlineNotes(int line) const
if (m_suggestionLines[0].isEmpty()) if (m_suggestionLines[0].isEmpty())
return {}; 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 lineLen = m_view->document()->lineLength(line);
int col = m_suggestionStartCol; if (m_suggestionStartCol < lineLen)
if (col < lineLen) return {};
col = lineLen;
return {col}; return {lineLen};
} }
QSize OllieGhostProvider::inlineNoteSize(const KTextEditor::InlineNote &note) const QSize OllieGhostProvider::inlineNoteSize(const KTextEditor::InlineNote &note) const
@ -367,9 +368,18 @@ void OllieGhostProvider::onCompletionReply(const QString &result)
// Notify Kate to repaint the first line (inline note) // Notify Kate to repaint the first line (inline note)
emit inlineNotesChanged(m_suggestionStartLine); 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) { 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); emit inlineNotesChanged(m_suggestionStartLine);
if (m_suggestionLines.size() > 1) { 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();
}
} }
} }