diff --git a/kate/ollie_ghost.cpp b/kate/ollie_ghost.cpp index ba07f9e..93fdf0d 100644 --- a/kate/ollie_ghost.cpp +++ b/kate/ollie_ghost.cpp @@ -144,12 +144,13 @@ QVector 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(); + } } }