MCPcopy
hub / github.com/micro-editor/micro / WordAt

Method WordAt

internal/buffer/buffer.go:666–684  ·  view source on GitHub ↗

WordAt returns the word around a given location in the buffer

(loc Loc)

Source from the content-addressed store, hash-verified

664
665// WordAt returns the word around a given location in the buffer
666func (b *Buffer) WordAt(loc Loc) []byte {
667 if len(b.LineBytes(loc.Y)) == 0 || !util.IsWordChar(b.RuneAt(loc)) {
668 return []byte{}
669 }
670
671 start := loc
672 end := loc.Move(1, b)
673
674 for start.X > 0 && util.IsWordChar(b.RuneAt(start.Move(-1, b))) {
675 start.X--
676 }
677
678 lineLen := util.CharacterCount(b.LineBytes(loc.Y))
679 for end.X < lineLen && util.IsWordChar(b.RuneAt(end)) {
680 end.X++
681 }
682
683 return b.Substr(start, end)
684}
685
686// Shared returns if there are other buffers with the same file as this buffer
687func (b *Buffer) Shared() bool {

Callers

nothing calls this directly

Calls 6

RuneAtMethod · 0.95
IsWordCharFunction · 0.92
CharacterCountFunction · 0.92
MoveMethod · 0.80
SubstrMethod · 0.80
LineBytesMethod · 0.65

Tested by

no test coverage detected