selectWord selects the word (whitespace delimited) that the cursor is on
()
| 933 | |
| 934 | // selectWord selects the word (whitespace delimited) that the cursor is on |
| 935 | func (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 |
| 982 | func (tf *TextField) selectReset() { |
no test coverage detected