-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: update select event (only for input and textarea)
- Loading branch information
Oleksandr Karpovich
committed
Jul 14, 2021
1 parent
1e17a5b
commit 969c97f
Showing
6 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/events/SyntheticSelectEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.jetbrains.compose.web.events | ||
|
||
import androidx.compose.web.events.SyntheticEvent | ||
import org.w3c.dom.events.Event | ||
import org.w3c.dom.events.EventTarget | ||
|
||
class SyntheticSelectEvent<Element : EventTarget>( | ||
nativeEvent: Event, | ||
) : SyntheticEvent<Element>(nativeEvent) { | ||
|
||
val selectionStart: Int = nativeEvent.target.asDynamic().selectionStart.unsafeCast<Int>() | ||
val selectionEnd: Int = nativeEvent.target.asDynamic().selectionEnd.unsafeCast<Int>() | ||
|
||
|
||
fun selection(): String { | ||
return nativeEvent.target.asDynamic().value.unsafeCast<String?>()?.substring( | ||
selectionStart, selectionEnd | ||
) ?: "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters