package display

import (
	
	

	
)

// AcceptInline replaces the line buffer with the inline suggestion when one
// applies at the cursor, clears the suggestion, and reports whether it did so.
// Callers pass the line/cursor to accept onto, since the engine's own line may
// point at a minibuffer during completion or search.
func ( *Engine) ( *core.Line,  *core.Cursor) bool {
	if !.inlineAcceptable(, ) {
		return false
	}

	.Set([]rune(.inline)...)
	.Set(.Len())
	.inline = ""

	return true
}

// AcceptInlineWord accepts the next word of the inline suggestion, leaving the
// rest as a suggestion. It follows forward-word semantics: any leading
// whitespace plus the following run of non-whitespace runes are inserted.
func ( *Engine) ( *core.Line,  *core.Cursor) {
	if !.inlineAcceptable(, ) {
		return
	}

	 := []rune(.inline)
	 := .Len()
	 := [:]

	 := 0
	for  < len() && unicode.IsSpace([]) {
		++
	}

	for  < len() && !unicode.IsSpace([]) {
		++
	}

	.Set([:+]...)
	.Set(.Len())

	if + >= len() {
		.inline = ""
	}
}

// inlineAcceptable reports whether the inline suggestion can be accepted onto
// the given line: the cursor must be at the end of the line and the suggestion
// must extend it (mirrors the display gate in inlineSuggestionApplies).
func ( *Engine) ( *core.Line,  *core.Cursor) bool {
	return .inline != "" &&
		.Pos() == .Len() &&
		strings.HasPrefix(.inline, string(*)) &&
		len([]rune(.inline)) > .Len()
}