Files

49 lines
1.3 KiB
Go

// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package review
import (
"strings"
"git.stormux.org/storm/fenrir/internal/command"
"git.stormux.org/storm/fenrir/internal/i18n"
"git.stormux.org/storm/fenrir/internal/presentation"
)
func (r *Review) spelling_text(scope command.ID, phonetic bool) string {
var text string
if r.tableMode && scope != command.CurrentLine {
cells := r.current_table_cells()
if len(cells) == 0 || r.tableColumn >= len(cells) {
return i18n.T("no table data")
}
cell := cells[r.tableColumn]
if scope == command.CurrentWord {
// Spell the complete selected cell, excluding its spoken header.
text = string(r.screen.Line(r.y)[cell.start:cell.end])
} else if cell.start != cell.end {
first, last := min(cell.start, r.screen.Cols-1), min(cell.end-1, r.screen.Cols-1)
if r.x < first || r.x > last {
r.x = first
}
text = string(r.screen.Line(r.y)[r.x])
}
} else {
switch scope {
case command.CurrentLine:
text = r.screen.Text(r.y)
case command.CurrentWord:
text = r.raw_word()
case command.CurrentChar:
text = string(r.screen.Line(r.y)[r.x])
}
}
if strings.TrimSpace(text) == "" {
r.result.Cue = presentation.Blank
return i18n.T("blank")
}
r.result.Spelling = &presentation.Spelling{Text: text, Phonetic: phonetic}
return text
}