MCPcopy Create free account
hub / github.com/cogentcore/core / SpanPosToRuneIndex

Method SpanPosToRuneIndex

paint/textlayout.go:41–55  ·  view source on GitHub ↗

SpanPosToRuneIndex returns the absolute rune index for a given span, rune index position -- i.e., the inverse of RuneSpanPos. Returns false if given input position is out of range, and returns last valid index in that case.

(si, ri int)

Source from the content-addressed store, hash-verified

39// index position -- i.e., the inverse of RuneSpanPos. Returns false if given
40// input position is out of range, and returns last valid index in that case.
41func (tx *Text) SpanPosToRuneIndex(si, ri int) (idx int, ok bool) {
42 idx = 0
43 for i := range tx.Spans {
44 sr := &tx.Spans[i]
45 if si > i {
46 idx += len(sr.Render)
47 continue
48 }
49 if ri <= len(sr.Render) {
50 return idx + ri, true
51 }
52 return idx + (len(sr.Render)), false
53 }
54 return 0, false
55}
56
57// RuneRelPos returns the relative (starting) position of the given rune
58// index, counting progressively through all spans present (adds Span RelPos

Callers 11

cursorDownMethod · 0.80
cursorUpMethod · 0.80
pixelToCursorMethod · 0.80
cursorDownMethod · 0.80
cursorUpMethod · 0.80
cursorStartLineMethod · 0.80
cursorEndLineMethod · 0.80
findNextLinkMethod · 0.80
findPrevLinkMethod · 0.80
PixelToCursorMethod · 0.80
OpenLinkAtMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected