SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Function evalTargetForSelection

    • What a text selection in a formula resolves to — the eval tip's target, and F9's.

      Three rules, in order, because no single one is right:

      1. Exactly a subtree → evaluate it in place (evalIndex). The common case: selecting SUM(A1:A5) inside =SUM(A1:A5)*2.

      2. A whole-token run that parses on its own → evaluate that TEXT as its own expression. The subtree rule alone is not enough, because an operator chain is left-nested: =1+1+1+1 is (((1+1)+1)+1), so the middle 1+1 is not any node — its two operands live in different subtrees. Rule 1 would widen to 1+1+1 and answer 3 for a selection that plainly reads as 2. Excel's F9 works this way throughout (it evaluates the selected text, not a node), and this is where that shows.

        Whole-token alignment is what keeps this honest: 1*2 inside =A1*2 parses, but it starts mid-token (A1), so it never reaches this rule and can't invent a value out of a coincidence.

      3. Otherwise → snap OUTWARD to the smallest evaluable segment containing the selection. A drag that lands mid-token (UM(A1:A5 in =SUM(A1:A5)*2) still answers — for SUM(A1:A5) — and the host's outline shows that it widened. Requiring a clean selection instead would leave the tip silent most of the time a human made the selection by hand.

      null when the selection touches nothing evaluable (whitespace only, an unparsed tail, or a selection past the tokens).

      Parameters

      • tokens: readonly FormulaToken[] | null
      • base: number

        The offset of the first token within the text (formulaPrefixLen — a stripped =).

      • text: string
      • start: number
      • end: number
      • OptionalisFragment: (fragment: string) => boolean

        Whether a run of text compiles as a standalone expression. Supplied by the host (it owns the calc engine); rule 2 is skipped entirely without it.

      Returns SelectionTarget | null