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

Method selectWord

core/textfield.go:935–979  ·  view source on GitHub ↗

selectWord selects the word (whitespace delimited) that the cursor is on

()

Source from the content-addressed store, hash-verified

933
934// selectWord selects the word (whitespace delimited) that the cursor is on
935func (tf *TextField) selectWord() {
936 sz := len(tf.editText)
937 if sz <= 3 {
938 tf.selectAll()
939 return
940 }
941 tf.selectStart = tf.cursorPos
942 if tf.selectStart >= sz {
943 tf.selectStart = sz - 2
944 }
945 if !tf.isWordBreak(tf.editText[tf.selectStart]) {
946 for tf.selectStart > 0 {
947 if tf.isWordBreak(tf.editText[tf.selectStart-1]) {
948 break
949 }
950 tf.selectStart--
951 }
952 tf.selectEnd = tf.cursorPos + 1
953 for tf.selectEnd < sz {
954 if tf.isWordBreak(tf.editText[tf.selectEnd]) {
955 break
956 }
957 tf.selectEnd++
958 }
959 } else { // keep the space start -- go to next space..
960 tf.selectEnd = tf.cursorPos + 1
961 for tf.selectEnd < sz {
962 if !tf.isWordBreak(tf.editText[tf.selectEnd]) {
963 break
964 }
965 tf.selectEnd++
966 }
967 for tf.selectEnd < sz { // include all trailing spaces
968 if tf.isWordBreak(tf.editText[tf.selectEnd]) {
969 break
970 }
971 tf.selectEnd++
972 }
973 }
974 tf.selectInit = tf.selectStart
975 if TheApp.SystemPlatform().IsMobile() {
976 tf.Send(events.ContextMenu)
977 }
978 tf.NeedsRender()
979}
980
981// selectReset resets the selection
982func (tf *TextField) selectReset() {

Callers 1

InitMethod · 0.95

Calls 6

selectAllMethod · 0.95
isWordBreakMethod · 0.95
IsMobileMethod · 0.80
NeedsRenderMethod · 0.80
SystemPlatformMethod · 0.65
SendMethod · 0.45

Tested by

no test coverage detected