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

Method wordBefore

texteditor/select.go:90–111  ·  view source on GitHub ↗

wordBefore returns the word before the lexer.Pos uses IsWordBreak to determine the bounds of the word

(tp lexer.Pos)

Source from the content-addressed store, hash-verified

88// wordBefore returns the word before the lexer.Pos
89// uses IsWordBreak to determine the bounds of the word
90func (ed *Editor) wordBefore(tp lexer.Pos) *text.Edit {
91 txt := ed.Buffer.Line(tp.Ln)
92 ch := tp.Ch
93 ch = min(ch, len(txt))
94 st := ch
95 for i := ch - 1; i >= 0; i-- {
96 if i == 0 { // start of line
97 st = 0
98 break
99 }
100 r1 := txt[i]
101 r2 := txt[i-1]
102 if core.IsWordBreak(r1, r2) {
103 st = i + 1
104 break
105 }
106 }
107 if st != ch {
108 return ed.Buffer.Region(lexer.Pos{Ln: tp.Ln, Ch: st}, tp)
109 }
110 return nil
111}
112
113// isWordEnd returns true if the cursor is just past the last letter of a word
114// word is a string of characters none of which are classified as a word break

Callers 1

iSpellKeyInputMethod · 0.95

Calls 3

IsWordBreakFunction · 0.92
LineMethod · 0.65
RegionMethod · 0.45

Tested by

no test coverage detected