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

Method AddWordToSelection

internal/buffer/cursor.go:367–397  ·  view source on GitHub ↗

AddWordToSelection adds the word the cursor is currently on to the selection

()

Source from the content-addressed store, hash-verified

365// AddWordToSelection adds the word the cursor is currently on
366// to the selection
367func (c *Cursor) AddWordToSelection() {
368 if c.Loc.GreaterThan(c.OrigSelection[0]) && c.Loc.LessThan(c.OrigSelection[1]) {
369 c.CurSelection = c.OrigSelection
370 return
371 }
372
373 if c.Loc.LessThan(c.OrigSelection[0]) {
374 backward := c.X
375
376 for backward > 0 && util.IsWordChar(c.RuneUnder(backward-1)) {
377 backward--
378 }
379
380 c.SetSelectionStart(Loc{backward, c.Y})
381 c.SetSelectionEnd(c.OrigSelection[1])
382 }
383
384 if c.Loc.GreaterThan(c.OrigSelection[1]) {
385 forward := c.X
386
387 lineLen := util.CharacterCount(c.buf.LineBytes(c.Y)) - 1
388 for forward < lineLen && util.IsWordChar(c.RuneUnder(forward+1)) {
389 forward++
390 }
391
392 c.SetSelectionEnd(Loc{forward, c.Y}.Move(1, c.buf))
393 c.SetSelectionStart(c.OrigSelection[0])
394 }
395
396 c.Loc = c.CurSelection[1]
397}
398
399// SelectTo selects from the current cursor location to the given
400// location

Callers 1

MouseDragMethod · 0.80

Calls 9

RuneUnderMethod · 0.95
SetSelectionStartMethod · 0.95
SetSelectionEndMethod · 0.95
IsWordCharFunction · 0.92
CharacterCountFunction · 0.92
MoveMethod · 0.80
LineBytesMethod · 0.65
GreaterThanMethod · 0.45
LessThanMethod · 0.45

Tested by

no test coverage detected