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

Method cursorBackwardWord

core/textfield.go:676–727  ·  view source on GitHub ↗

cursorBackwardWord moves the cursor backward by words

(steps int)

Source from the content-addressed store, hash-verified

674
675// cursorBackwardWord moves the cursor backward by words
676func (tf *TextField) cursorBackwardWord(steps int) {
677 for i := 0; i < steps; i++ {
678 sz := len(tf.editText)
679 if sz > 0 && tf.cursorPos > 0 {
680 ch := min(tf.cursorPos, sz-1)
681 var done = false
682 for ch < sz && !done { // if on a wb, go past
683 r1 := tf.editText[ch]
684 r2 := rune(-1)
685 if ch > 0 {
686 r2 = tf.editText[ch-1]
687 }
688 if IsWordBreak(r1, r2) {
689 ch--
690 if ch == -1 {
691 done = true
692 }
693 } else {
694 done = true
695 }
696 }
697 done = false
698 for ch < sz && ch >= 0 && !done {
699 r1 := tf.editText[ch]
700 r2 := rune(-1)
701 if ch > 0 {
702 r2 = tf.editText[ch-1]
703 }
704 if !IsWordBreak(r1, r2) {
705 ch--
706 } else {
707 done = true
708 }
709 }
710 tf.cursorPos = ch
711 } else {
712 tf.cursorPos = 0
713 }
714 }
715 if tf.cursorPos < 0 {
716 tf.cursorPos = 0
717 }
718 if tf.cursorPos <= tf.startPos {
719 dec := min(tf.startPos, 8)
720 tf.startPos -= dec
721 }
722 tf.cursorLine, _, _ = tf.renderAll.RuneSpanPos(tf.cursorPos)
723 if tf.selectMode {
724 tf.selectRegionUpdate(tf.cursorPos)
725 }
726 tf.NeedsRender()
727}
728
729// cursorDown moves the cursor down
730func (tf *TextField) cursorDown(steps int) {

Callers 2

cursorBackspaceWordMethod · 0.95
handleKeyEventsMethod · 0.95

Calls 4

selectRegionUpdateMethod · 0.95
IsWordBreakFunction · 0.85
RuneSpanPosMethod · 0.80
NeedsRenderMethod · 0.80

Tested by

no test coverage detected