Files

56 lines
1.5 KiB
Go

// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package app
import (
"context"
"time"
"git.stormux.org/storm/cthulhu/internal/interaction"
)
type emojiTextSource interface {
TypeText(context.Context, string) error
}
func (ui *internalUI) emoji_insertion_allowed() bool {
if owner, ok := ui.keys.(interface{ BrowseNavigationEnabled() bool }); ok {
return !owner.BrowseNavigationEnabled()
}
return true
}
func (ui *internalUI) select_emoji(ctx context.Context, selection interaction.Value, copyChecked bool) {
if ctx.Err() != nil || ui.gate.Locked() || ui.gate.Suspended() {
return
}
actionCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
var message string
if copyChecked {
message = "Copy failed"
if ui.emojiCopier != nil && ui.emojiCopier.Copy(actionCtx, selection.Selected) == nil {
message = "Copied " + selection.Text + " to clipboard"
}
} else if !ui.emoji_insertion_allowed() {
message = "Emoji insertion unavailable in browse mode"
} else {
message = "Emoji insertion unavailable"
if ui.emojiSource != nil && ui.emojiSource.TypeText(actionCtx, selection.Selected) == nil {
message = "Inserted " + selection.Text
}
}
ui.emoji_message(message)
}
func (ui *internalUI) emoji_message(message string) {
if ui.gate.Locked() || ui.gate.Suspended() {
return
}
ui.speech.Enqueue(speechRequest{Text: message, Role: "system", Cause: "emoji"})
if ui.braille != nil {
ui.braille.EnqueueMessage(message)
}
}