More work on LibreOffice support.

This commit is contained in:
Storm Dragon committed 2026-10-15 00:50:49 -04:00
1 parent e0c8c6198c
commit 4ac59d4ced
25 files changed
+392 -57

No files matched your search

+27
View File
@@ -49,3 +49,30 @@ func libreOfficeFocusSnapshot(snapshot atspi.Snapshot, options Options) atspi.Sn
}
return snapshot
}
// LibreOfficeCellFormula limits Office presentation to verified Calc cells.
func LibreOfficeCellFormula(snapshot atspi.Snapshot) string {
context := snapshot.LibreOffice
if !atspi.IsLibreOfficeProcess(snapshot.ApplicationProcess) || snapshot.Defunct ||
snapshot.Role != "table cell" || context == nil || !context.InSpreadsheet || !context.Cell {
return ""
}
return context.Formula
}
// LibreOfficeFormulaText follows Orca's explicit formula command: non-formula
// cells report their value, including "empty" when there is no value.
func LibreOfficeFormulaText(snapshot atspi.Snapshot) string {
context := snapshot.LibreOffice
if !atspi.IsLibreOfficeProcess(snapshot.ApplicationProcess) || snapshot.Defunct ||
snapshot.Role != "table cell" || context == nil || !context.InSpreadsheet || !context.Cell {
return "Not in a table."
}
if formula := LibreOfficeCellFormula(snapshot); formula != "" {
return formula
}
if strings.TrimSpace(context.CellText) != "" {
return context.CellText
}
return "empty"
}
+46
View File
@@ -44,3 +44,49 @@ func TestLibreOfficePresentationRequiresVerifiedCellContext(t *testing.T) {
}
}
}
func TestLibreOfficeFormulaPresentation(t *testing.T) {
for _, value := range []string{"43", ""} {
snapshot := atspi.Snapshot{Role: "table cell", ApplicationProcess: "soffice.bin",
LibreOffice: &atspi.LibreOfficeContext{InSpreadsheet: true, Cell: true,
Coordinates: "C1", CellText: value, Formula: "=B1+1"}}
want := value + ", C1, has formula"
if value == "" {
want = "blank, C1, has formula"
}
if got := FocusText(snapshot); got != want {
t.Fatalf("formula cell = %q, want %q", got, want)
}
if got := LibreOfficeFormulaText(snapshot); got != "=B1+1" {
t.Fatalf("formula command = %q", got)
}
options := DefaultOptions()
reading := config.DefaultSettings().Reading
reading.OnlySpeakDisplayedText = true
options.Reading = &reading
if got := FocusTextWithOptions(snapshot, options); got != value {
t.Fatalf("displayed text includes formula metadata: %q", got)
}
snapshot.LibreOffice.Formula = ""
want = value
if value == "" {
want = "empty"
}
if got := LibreOfficeFormulaText(snapshot); got != want {
t.Fatalf("non-formula command = %q, want %q", got, want)
}
}
for _, snapshot := range []atspi.Snapshot{
{},
{Role: "paragraph", ApplicationProcess: "soffice.bin"},
{Role: "table cell", ApplicationProcess: "chromium", LibreOffice: &atspi.LibreOfficeContext{InSpreadsheet: true, Cell: true, Formula: "wrong"}},
{Role: "table cell", Defunct: true, ApplicationProcess: "soffice.bin", LibreOffice: &atspi.LibreOfficeContext{InSpreadsheet: true, Cell: true, Formula: "wrong"}},
} {
if got := LibreOfficeFormulaText(snapshot); got != "Not in a table." {
t.Fatalf("unverified cell = %q", got)
}
if got := LibreOfficeCellFormula(snapshot); got != "" {
t.Fatalf("unverified formula = %q", got)
}
}
}
+3
View File
@@ -173,6 +173,9 @@ func FocusSpeechWithOptions(snapshot atspi.Snapshot, options Options) Speech {
if reading.SpeakMisspelledIndicator && snapshot.Misspelled {
fields = append(fields, "misspelled")
}
if LibreOfficeCellFormula(snapshot) != "" {
fields = append(fields, "has formula")
}
for _, part := range fields {
if part != "" && !contains(parts, part) {
parts = append(parts, part)