Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Siyamed Sinir | fd8bc42 | 2019-11-21 18:23:58 -0800 | [diff] [blame] | 17 | package androidx.ui.core.selection |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 18 | |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 19 | import androidx.ui.core.LayoutCoordinates |
Qingqing Deng | f2d0a2d | 2020-03-12 14:19:50 -0700 | [diff] [blame^] | 20 | import androidx.ui.core.clipboard.ClipboardManager |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 21 | import androidx.ui.core.gesture.DragObserver |
Qingqing Deng | bf370e7 | 2019-10-17 11:14:39 -0700 | [diff] [blame] | 22 | import androidx.ui.core.gesture.LongPressDragObserver |
Qingqing Deng | 25b8f8d | 2020-01-17 16:36:19 -0800 | [diff] [blame] | 23 | import androidx.ui.core.hapticfeedback.HapticFeedback |
| 24 | import androidx.ui.core.hapticfeedback.HapticFeedbackType |
Qingqing Deng | 648e1bf | 2019-12-30 11:49:48 -0800 | [diff] [blame] | 25 | import androidx.ui.text.AnnotatedString |
| 26 | import androidx.ui.text.length |
| 27 | import androidx.ui.text.subSequence |
George Mount | 842c8c1 | 2020-01-08 16:03:42 -0800 | [diff] [blame] | 28 | import androidx.ui.unit.PxPosition |
| 29 | import androidx.ui.unit.px |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 30 | |
Qingqing Deng | 35f97ea | 2019-09-18 19:24:37 -0700 | [diff] [blame] | 31 | /** |
Louis Pullen-Freilich | 5da28bd | 2019-10-15 17:05:07 +0100 | [diff] [blame] | 32 | * A bridge class between user interaction to the text composables for text selection. |
Qingqing Deng | 35f97ea | 2019-09-18 19:24:37 -0700 | [diff] [blame] | 33 | */ |
Siyamed Sinir | 700df845 | 2019-10-22 20:23:58 -0700 | [diff] [blame] | 34 | internal class SelectionManager(private val selectionRegistrar: SelectionRegistrarImpl) { |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 35 | /** |
| 36 | * The current selection. |
| 37 | */ |
| 38 | var selection: Selection? = null |
| 39 | |
| 40 | /** |
| 41 | * The manager will invoke this every time it comes to the conclusion that the selection should |
| 42 | * change. The expectation is that this callback will end up causing `setSelection` to get |
| 43 | * called. This is what makes this a "controlled component". |
| 44 | */ |
| 45 | var onSelectionChange: (Selection?) -> Unit = {} |
| 46 | |
| 47 | /** |
Qingqing Deng | 25b8f8d | 2020-01-17 16:36:19 -0800 | [diff] [blame] | 48 | * [HapticFeedback] handle to perform haptic feedback. |
| 49 | */ |
| 50 | var hapticFeedBack: HapticFeedback? = null |
| 51 | |
| 52 | /** |
Qingqing Deng | f2d0a2d | 2020-03-12 14:19:50 -0700 | [diff] [blame^] | 53 | * [ClipboardManager] to perform clipboard features. |
| 54 | */ |
| 55 | var clipboardManager: ClipboardManager? = null |
| 56 | |
| 57 | /** |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 58 | * Layout Coordinates of the selection container. |
| 59 | */ |
| 60 | lateinit var containerLayoutCoordinates: LayoutCoordinates |
| 61 | |
| 62 | /** |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 63 | * The beginning position of the drag gesture. Every time a new drag gesture starts, it wil be |
| 64 | * recalculated. |
| 65 | */ |
| 66 | private var dragBeginPosition = PxPosition.Origin |
| 67 | |
| 68 | /** |
| 69 | * The total distance being dragged of the drag gesture. Every time a new drag gesture starts, |
| 70 | * it will be zeroed out. |
| 71 | */ |
| 72 | private var dragTotalDistance = PxPosition.Origin |
| 73 | |
| 74 | /** |
Qingqing Deng | 0cb86fe | 2019-07-16 15:36:27 -0700 | [diff] [blame] | 75 | * A flag to check if the selection start or end handle is being dragged. |
| 76 | * If this value is true, then onPress will not select any text. |
| 77 | * This value will be set to true when either handle is being dragged, and be reset to false |
| 78 | * when the dragging is stopped. |
| 79 | */ |
| 80 | private var draggingHandle = false |
| 81 | |
| 82 | /** |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 83 | * Iterates over the handlers, gets the selection for each Composable, and merges all the |
| 84 | * returned [Selection]s. |
| 85 | * |
| 86 | * @param startPosition [PxPosition] for the start of the selection |
| 87 | * @param endPosition [PxPosition] for the end of the selection |
Siyamed Sinir | 0100f12 | 2019-11-16 00:23:12 -0800 | [diff] [blame] | 88 | * @param longPress the selection is a result of long press |
Qingqing Deng | 25b8f8d | 2020-01-17 16:36:19 -0800 | [diff] [blame] | 89 | * @param previousSelection previous selection |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 90 | * |
| 91 | * @return [Selection] object which is constructed by combining all Composables that are |
| 92 | * selected. |
| 93 | */ |
Qingqing Deng | 5819ff6 | 2019-11-18 15:26:23 -0800 | [diff] [blame] | 94 | // This function is internal for testing purposes. |
| 95 | internal fun mergeSelections( |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 96 | startPosition: PxPosition, |
| 97 | endPosition: PxPosition, |
Siyamed Sinir | 0100f12 | 2019-11-16 00:23:12 -0800 | [diff] [blame] | 98 | longPress: Boolean = false, |
Qingqing Deng | 25b8f8d | 2020-01-17 16:36:19 -0800 | [diff] [blame] | 99 | previousSelection: Selection? = null, |
Qingqing Deng | ff65ed6 | 2020-01-06 17:55:48 -0800 | [diff] [blame] | 100 | isStartHandle: Boolean = true |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 101 | ): Selection? { |
Qingqing Deng | 25b8f8d | 2020-01-17 16:36:19 -0800 | [diff] [blame] | 102 | |
Qingqing Deng | 247f2b4 | 2019-12-12 19:48:37 -0800 | [diff] [blame] | 103 | val newSelection = selectionRegistrar.sort(containerLayoutCoordinates) |
| 104 | .fold(null) { mergedSelection: Selection?, |
| 105 | handler: Selectable -> |
| 106 | merge( |
| 107 | mergedSelection, |
| 108 | handler.getSelection( |
| 109 | startPosition = startPosition, |
| 110 | endPosition = endPosition, |
| 111 | containerLayoutCoordinates = containerLayoutCoordinates, |
| 112 | longPress = longPress, |
| 113 | previousSelection = previousSelection, |
| 114 | isStartHandle = isStartHandle |
| 115 | ) |
Siyamed Sinir | 700df845 | 2019-10-22 20:23:58 -0700 | [diff] [blame] | 116 | ) |
Qingqing Deng | 247f2b4 | 2019-12-12 19:48:37 -0800 | [diff] [blame] | 117 | } |
Qingqing Deng | 25b8f8d | 2020-01-17 16:36:19 -0800 | [diff] [blame] | 118 | if (previousSelection != newSelection) hapticFeedBack?.performHapticFeedback( |
| 119 | HapticFeedbackType.TextHandleMove |
| 120 | ) |
| 121 | return newSelection |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Qingqing Deng | 648e1bf | 2019-12-30 11:49:48 -0800 | [diff] [blame] | 124 | internal fun getSelectedText(): AnnotatedString? { |
| 125 | val selectables = selectionRegistrar.sort(containerLayoutCoordinates) |
| 126 | var selectedText: AnnotatedString? = null |
| 127 | |
| 128 | selection?.let { |
| 129 | for (handler in selectables) { |
| 130 | // Continue if the current selectable is before the selection starts. |
| 131 | if (handler != it.start.selectable && handler != it.end.selectable && |
| 132 | selectedText == null |
| 133 | ) continue |
| 134 | |
| 135 | val currentSelectedText = getCurrentSelectedText( |
| 136 | selectable = handler, |
| 137 | selection = it |
| 138 | ) |
| 139 | selectedText = selectedText?.plus(currentSelectedText) ?: currentSelectedText |
| 140 | |
| 141 | // Break if the current selectable is the last selected selectable. |
| 142 | if (handler == it.end.selectable && !it.handlesCrossed || |
| 143 | handler == it.start.selectable && it.handlesCrossed |
| 144 | ) break |
| 145 | } |
| 146 | } |
| 147 | return selectedText |
| 148 | } |
| 149 | |
Qingqing Deng | f2d0a2d | 2020-03-12 14:19:50 -0700 | [diff] [blame^] | 150 | internal fun copy() { |
| 151 | val selectedText = getSelectedText() |
| 152 | selectedText?.let { clipboardManager?.setText(it) } |
| 153 | } |
| 154 | |
Qingqing Deng | b6f5d8a | 2019-11-11 18:19:22 -0800 | [diff] [blame] | 155 | // This is for PressGestureDetector to cancel the selection. |
| 156 | fun onRelease() { |
| 157 | // Call mergeSelections with an out of boundary input to inform all text widgets to |
| 158 | // cancel their individual selection. |
Qingqing Deng | a5d8095 | 2019-10-11 16:46:52 -0700 | [diff] [blame] | 159 | mergeSelections( |
Siyamed Sinir | 0100f12 | 2019-11-16 00:23:12 -0800 | [diff] [blame] | 160 | startPosition = PxPosition((-1).px, (-1).px), |
Qingqing Deng | 25b8f8d | 2020-01-17 16:36:19 -0800 | [diff] [blame] | 161 | endPosition = PxPosition((-1).px, (-1).px), |
| 162 | previousSelection = selection |
Siyamed Sinir | 0100f12 | 2019-11-16 00:23:12 -0800 | [diff] [blame] | 163 | ) |
Siyamed Sinir | e810eab | 2019-11-22 12:36:38 -0800 | [diff] [blame] | 164 | if (selection != null) onSelectionChange(null) |
Qingqing Deng | b6f5d8a | 2019-11-11 18:19:22 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Siyamed Sinir | e810eab | 2019-11-22 12:36:38 -0800 | [diff] [blame] | 167 | val longPressDragObserver = object : LongPressDragObserver { |
| 168 | override fun onLongPress(pxPosition: PxPosition) { |
| 169 | if (draggingHandle) return |
| 170 | val newSelection = mergeSelections( |
| 171 | startPosition = pxPosition, |
| 172 | endPosition = pxPosition, |
Qingqing Deng | 25b8f8d | 2020-01-17 16:36:19 -0800 | [diff] [blame] | 173 | longPress = true, |
| 174 | previousSelection = selection |
Siyamed Sinir | e810eab | 2019-11-22 12:36:38 -0800 | [diff] [blame] | 175 | ) |
| 176 | if (newSelection != selection) onSelectionChange(newSelection) |
| 177 | dragBeginPosition = pxPosition |
Siyamed Sinir | 700df845 | 2019-10-22 20:23:58 -0700 | [diff] [blame] | 178 | } |
Siyamed Sinir | 700df845 | 2019-10-22 20:23:58 -0700 | [diff] [blame] | 179 | |
Siyamed Sinir | e810eab | 2019-11-22 12:36:38 -0800 | [diff] [blame] | 180 | override fun onDragStart() { |
| 181 | super.onDragStart() |
| 182 | // selection never started |
| 183 | if (selection == null) return |
| 184 | // Zero out the total distance that being dragged. |
| 185 | dragTotalDistance = PxPosition.Origin |
| 186 | } |
| 187 | |
| 188 | override fun onDrag(dragDistance: PxPosition): PxPosition { |
| 189 | // selection never started, did not consume any drag |
| 190 | if (selection == null) return PxPosition.Origin |
| 191 | |
| 192 | dragTotalDistance += dragDistance |
| 193 | val newSelection = mergeSelections( |
| 194 | startPosition = dragBeginPosition, |
| 195 | endPosition = dragBeginPosition + dragTotalDistance, |
Qingqing Deng | 74baaa2 | 2019-12-12 13:28:25 -0800 | [diff] [blame] | 196 | longPress = true, |
Qingqing Deng | 25b8f8d | 2020-01-17 16:36:19 -0800 | [diff] [blame] | 197 | previousSelection = selection |
Siyamed Sinir | e810eab | 2019-11-22 12:36:38 -0800 | [diff] [blame] | 198 | ) |
| 199 | |
| 200 | if (newSelection != selection) onSelectionChange(newSelection) |
| 201 | return dragDistance |
| 202 | } |
| 203 | } |
| 204 | |
Qingqing Deng | 13743f7 | 2019-07-15 15:00:45 -0700 | [diff] [blame] | 205 | /** |
| 206 | * Adjust coordinates for given text offset. |
| 207 | * |
| 208 | * Currently [android.text.Layout.getLineBottom] returns y coordinates of the next |
| 209 | * line's top offset, which is not included in current line's hit area. To be able to |
| 210 | * hit current line, move up this y coordinates by 1 pixel. |
| 211 | */ |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 212 | private fun getAdjustedCoordinates(position: PxPosition): PxPosition { |
| 213 | return PxPosition(position.x, position.y - 1.px) |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 216 | fun handleDragObserver(isStartHandle: Boolean): DragObserver { |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 217 | return object : DragObserver { |
Andrey Kulikov | 0e6c40f | 2019-09-06 18:33:14 +0100 | [diff] [blame] | 218 | override fun onStart(downPosition: PxPosition) { |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 219 | val selection = selection!! |
Louis Pullen-Freilich | 5da28bd | 2019-10-15 17:05:07 +0100 | [diff] [blame] | 220 | // The LayoutCoordinates of the composable where the drag gesture should begin. This |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 221 | // is used to convert the position of the beginning of the drag gesture from the |
Louis Pullen-Freilich | 5da28bd | 2019-10-15 17:05:07 +0100 | [diff] [blame] | 222 | // composable coordinates to selection container coordinates. |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 223 | val beginLayoutCoordinates = if (isStartHandle) { |
Qingqing Deng | 6d1b7d2 | 2019-12-27 17:48:08 -0800 | [diff] [blame] | 224 | selection.start.selectable.getLayoutCoordinates()!! |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 225 | } else { |
Qingqing Deng | 6d1b7d2 | 2019-12-27 17:48:08 -0800 | [diff] [blame] | 226 | selection.end.selectable.getLayoutCoordinates()!! |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 229 | // The position of the character where the drag gesture should begin. This is in |
Louis Pullen-Freilich | 5da28bd | 2019-10-15 17:05:07 +0100 | [diff] [blame] | 230 | // the composable coordinates. |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 231 | val beginCoordinates = getAdjustedCoordinates( |
Qingqing Deng | 6d1b7d2 | 2019-12-27 17:48:08 -0800 | [diff] [blame] | 232 | if (isStartHandle) |
| 233 | selection.start.selectable.getHandlePosition( |
| 234 | selection = selection, isStartHandle = true |
| 235 | ) else |
| 236 | selection.end.selectable.getHandlePosition( |
| 237 | selection = selection, isStartHandle = false |
| 238 | ) |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 239 | ) |
| 240 | |
Louis Pullen-Freilich | 5da28bd | 2019-10-15 17:05:07 +0100 | [diff] [blame] | 241 | // Convert the position where drag gesture begins from composable coordinates to |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 242 | // selection container coordinates. |
| 243 | dragBeginPosition = containerLayoutCoordinates.childToLocal( |
| 244 | beginLayoutCoordinates, |
| 245 | beginCoordinates |
| 246 | ) |
| 247 | |
| 248 | // Zero out the total distance that being dragged. |
| 249 | dragTotalDistance = PxPosition.Origin |
Qingqing Deng | 0cb86fe | 2019-07-16 15:36:27 -0700 | [diff] [blame] | 250 | draggingHandle = true |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | override fun onDrag(dragDistance: PxPosition): PxPosition { |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 254 | val selection = selection!! |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 255 | dragTotalDistance += dragDistance |
| 256 | |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 257 | val currentStart = if (isStartHandle) { |
| 258 | dragBeginPosition + dragTotalDistance |
| 259 | } else { |
| 260 | containerLayoutCoordinates.childToLocal( |
Qingqing Deng | 6d1b7d2 | 2019-12-27 17:48:08 -0800 | [diff] [blame] | 261 | selection.start.selectable.getLayoutCoordinates()!!, |
| 262 | getAdjustedCoordinates( |
| 263 | selection.start.selectable.getHandlePosition( |
| 264 | selection = selection, |
| 265 | isStartHandle = true |
| 266 | ) |
| 267 | ) |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 268 | ) |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 269 | } |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 270 | |
| 271 | val currentEnd = if (isStartHandle) { |
| 272 | containerLayoutCoordinates.childToLocal( |
Qingqing Deng | 6d1b7d2 | 2019-12-27 17:48:08 -0800 | [diff] [blame] | 273 | selection.end.selectable.getLayoutCoordinates()!!, |
| 274 | getAdjustedCoordinates( |
| 275 | selection.end.selectable.getHandlePosition( |
| 276 | selection = selection, |
| 277 | isStartHandle = false |
| 278 | ) |
| 279 | ) |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 280 | ) |
| 281 | } else { |
| 282 | dragBeginPosition + dragTotalDistance |
| 283 | } |
| 284 | |
Qingqing Deng | a5d8095 | 2019-10-11 16:46:52 -0700 | [diff] [blame] | 285 | val finalSelection = mergeSelections( |
| 286 | startPosition = currentStart, |
| 287 | endPosition = currentEnd, |
Qingqing Deng | 25b8f8d | 2020-01-17 16:36:19 -0800 | [diff] [blame] | 288 | previousSelection = selection, |
Qingqing Deng | ff65ed6 | 2020-01-06 17:55:48 -0800 | [diff] [blame] | 289 | isStartHandle = isStartHandle |
Qingqing Deng | a5d8095 | 2019-10-11 16:46:52 -0700 | [diff] [blame] | 290 | ) |
Siyamed Sinir | 472c316 | 2019-10-21 23:41:00 -0700 | [diff] [blame] | 291 | onSelectionChange(finalSelection) |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 292 | return dragDistance |
| 293 | } |
Qingqing Deng | 0cb86fe | 2019-07-16 15:36:27 -0700 | [diff] [blame] | 294 | |
| 295 | override fun onStop(velocity: PxPosition) { |
| 296 | super.onStop(velocity) |
| 297 | draggingHandle = false |
| 298 | } |
Qingqing Deng | 6f56a91 | 2019-05-13 10:10:37 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
Siyamed Sinir | 700df845 | 2019-10-22 20:23:58 -0700 | [diff] [blame] | 303 | private fun merge(lhs: Selection?, rhs: Selection?): Selection? { |
| 304 | return lhs?.merge(rhs) ?: rhs |
| 305 | } |
Qingqing Deng | 648e1bf | 2019-12-30 11:49:48 -0800 | [diff] [blame] | 306 | |
| 307 | private fun getCurrentSelectedText( |
| 308 | selectable: Selectable, |
| 309 | selection: Selection |
| 310 | ): AnnotatedString { |
| 311 | val currentText = selectable.getText() |
| 312 | |
| 313 | return if ( |
| 314 | selectable != selection.start.selectable && |
| 315 | selectable != selection.end.selectable |
| 316 | ) { |
| 317 | // Select the full text content if the current selectable is between the |
| 318 | // start and the end selectables. |
| 319 | currentText |
| 320 | } else if ( |
| 321 | selectable == selection.start.selectable && |
| 322 | selectable == selection.end.selectable |
| 323 | ) { |
| 324 | // Select partial text content if the current selectable is the start and |
| 325 | // the end selectable. |
| 326 | if (selection.handlesCrossed) { |
| 327 | currentText.subSequence(selection.end.offset, selection.start.offset) |
| 328 | } else { |
| 329 | currentText.subSequence(selection.start.offset, selection.end.offset) |
| 330 | } |
| 331 | } else if (selectable == selection.start.selectable) { |
| 332 | // Select partial text content if the current selectable is the start |
| 333 | // selectable. |
| 334 | if (selection.handlesCrossed) { |
| 335 | currentText.subSequence(0, selection.start.offset) |
| 336 | } else { |
| 337 | currentText.subSequence(selection.start.offset, currentText.length) |
| 338 | } |
| 339 | } else { |
| 340 | // Selectable partial text content if the current selectable is the end |
| 341 | // selectable. |
| 342 | if (selection.handlesCrossed) { |
| 343 | currentText.subSequence(selection.end.offset, currentText.length) |
| 344 | } else { |
| 345 | currentText.subSequence(0, selection.end.offset) |
| 346 | } |
| 347 | } |
| 348 | } |