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

Method SelectWord

internal/buffer/cursor.go:334–363  ·  view source on GitHub ↗

SelectWord selects the word the cursor is currently on

()

Source from the content-addressed store, hash-verified

332
333// SelectWord selects the word the cursor is currently on
334func (c *Cursor) SelectWord() {
335 if len(c.buf.LineBytes(c.Y)) == 0 {
336 return
337 }
338
339 if !util.IsWordChar(c.RuneUnder(c.X)) {
340 c.SetSelectionStart(c.Loc)
341 c.SetSelectionEnd(c.Loc.Move(1, c.buf))
342 c.OrigSelection = c.CurSelection
343 return
344 }
345
346 forward, backward := c.X, c.X
347
348 for backward > 0 && util.IsWordChar(c.RuneUnder(backward-1)) {
349 backward--
350 }
351
352 c.SetSelectionStart(Loc{backward, c.Y})
353 c.OrigSelection[0] = c.CurSelection[0]
354
355 lineLen := util.CharacterCount(c.buf.LineBytes(c.Y)) - 1
356 for forward < lineLen && util.IsWordChar(c.RuneUnder(forward+1)) {
357 forward++
358 }
359
360 c.SetSelectionEnd(Loc{forward, c.Y}.Move(1, c.buf))
361 c.OrigSelection[1] = c.CurSelection[1]
362 c.Loc = c.CurSelection[1]
363}
364
365// AddWordToSelection adds the word the cursor is currently on
366// to the selection

Callers 3

MousePressMethod · 0.80
SpawnMultiCursorMethod · 0.80
TextFilterCmdMethod · 0.80

Calls 7

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

Tested by

no test coverage detected