Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
673c85d1
Unverified
Commit
673c85d1
authored
Oct 31, 2022
by
dima.avdeev
Committed by
GitHub
Oct 31, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
iOS copy/paste text menu (#609)
parent
63bde1b2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
30 deletions
+82
-30
SkikoUIView.kt
skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkikoUIView.kt
+59
-30
TextActions.kt
skiko/src/iosMain/kotlin/org/jetbrains/skiko/TextActions.kt
+23
-0
No files found.
skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkikoUIView.kt
View file @
673c85d1
package
org.jetbrains.skiko
package
org.jetbrains.skiko
import
kotlinx.cinterop.*
import
kotlinx.cinterop.*
import
org.jetbrains.skia.Rect
import
platform.CoreGraphics.*
import
platform.CoreGraphics.*
import
platform.Foundation.*
import
platform.Foundation.*
import
platform.UIKit.*
import
platform.UIKit.*
...
@@ -10,7 +11,7 @@ import kotlin.math.min
...
@@ -10,7 +11,7 @@ import kotlin.math.min
@Suppress
(
"CONFLICTING_OVERLOADS"
)
@Suppress
(
"CONFLICTING_OVERLOADS"
)
@ExportObjCClass
@ExportObjCClass
class
SkikoUIView
:
UIView
,
UIKeyInputProtocol
,
UITextInputProtocol
,
UITextPasteConfigurationSupportingProtocol
{
class
SkikoUIView
:
UIView
,
UIKeyInputProtocol
,
UITextInputProtocol
{
@OverrideInit
@OverrideInit
constructor
(
frame
:
CValue
<
CGRect
>)
:
super
(
frame
)
constructor
(
frame
:
CValue
<
CGRect
>)
:
super
(
frame
)
...
@@ -19,15 +20,56 @@ class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol, UITextPaste
...
@@ -19,15 +20,56 @@ class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol, UITextPaste
private
var
skiaLayer
:
SkiaLayer
?
=
null
private
var
skiaLayer
:
SkiaLayer
?
=
null
private
var
_inputDelegate
:
UITextInputDelegateProtocol
?
=
null
private
var
_inputDelegate
:
UITextInputDelegateProtocol
?
=
null
private
var
_pasteConfiguration
:
UIPasteConfiguration
?
=
null
private
var
_currentTextMenuActions
:
TextActions
?
=
null
private
var
_pasteDelegate
:
UITextPasteDelegateProtocol
?
=
null
constructor
(
skiaLayer
:
SkiaLayer
,
frame
:
CValue
<
CGRect
>
=
CGRectNull
.
readValue
())
:
super
(
frame
)
{
constructor
(
skiaLayer
:
SkiaLayer
,
frame
:
CValue
<
CGRect
>
=
CGRectNull
.
readValue
())
:
super
(
frame
)
{
this
.
skiaLayer
=
skiaLayer
this
.
skiaLayer
=
skiaLayer
}
}
/**
* Show copy/paste text menu
* @param targetRect - rectangle of selected text area
* @param textActions - available (not null) actions in text menu
*/
fun
showTextMenu
(
targetRect
:
Rect
,
textActions
:
TextActions
)
{
_currentTextMenuActions
=
textActions
val
menu
:
UIMenuController
=
UIMenuController
.
sharedMenuController
()
if
(
menu
.
isMenuVisible
())
{
menu
.
hideMenu
()
}
val
cgRect
=
CGRectMake
(
x
=
targetRect
.
left
.
toDouble
(),
y
=
targetRect
.
top
.
toDouble
(),
width
=
targetRect
.
width
.
toDouble
(),
height
=
targetRect
.
height
.
toDouble
()
)
menu
.
showMenuFromView
(
this
,
cgRect
)
}
fun
hideTextMenu
()
{
_currentTextMenuActions
=
null
val
menu
:
UIMenuController
=
UIMenuController
.
sharedMenuController
()
menu
.
hideMenu
()
}
fun
isTextMenuShown
():
Boolean
{
return
_currentTextMenuActions
!=
null
}
override
fun
copy
(
sender
:
Any
?)
{
_currentTextMenuActions
?.
copy
?.
invoke
()
}
override
fun
paste
(
sender
:
Any
?)
{
_currentTextMenuActions
?.
paste
?.
invoke
()
}
override
fun
cut
(
sender
:
Any
?)
{
_currentTextMenuActions
?.
cut
?.
invoke
()
}
override
fun
selectAll
(
sender
:
Any
?)
{
override
fun
selectAll
(
sender
:
Any
?)
{
skiaLayer
?.
skikoView
?.
input
?.
selectAll
()
_currentTextMenuActions
?.
selectAll
?.
invoke
()
}
}
fun
detach
()
=
skiaLayer
?.
detach
()
fun
detach
()
=
skiaLayer
?.
detach
()
...
@@ -159,7 +201,7 @@ class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol, UITextPaste
...
@@ -159,7 +201,7 @@ class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol, UITextPaste
* Replaces the text in a document that is in the specified range.
* Replaces the text in a document that is in the specified range.
* https://developer.apple.com/documentation/uikit/uitextinput/1614558-replace
* https://developer.apple.com/documentation/uikit/uitextinput/1614558-replace
* @param range A range of text in a document.
* @param range A range of text in a document.
* @param
t
ext A string to replace the text in range.
* @param
withT
ext A string to replace the text in range.
*/
*/
override
fun
replaceRange
(
range
:
UITextRange
,
withText
:
String
)
{
override
fun
replaceRange
(
range
:
UITextRange
,
withText
:
String
)
{
skiaLayer
?.
skikoView
?.
input
?.
replaceRange
(
range
.
toIntRange
(),
withText
)
skiaLayer
?.
skikoView
?.
input
?.
replaceRange
(
range
.
toIntRange
(),
withText
)
...
@@ -353,30 +395,17 @@ class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol, UITextPaste
...
@@ -353,30 +395,17 @@ class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol, UITextPaste
return
this
return
this
}
}
override
fun
canPerformAction
(
action
:
COpaquePointer
?,
withSender
:
Any
?):
Boolean
{
override
fun
canPerformAction
(
action
:
COpaquePointer
?,
withSender
:
Any
?):
Boolean
=
//todo context menu with actions
when
(
action
)
{
return
true
NSSelectorFromString
(
UIResponderStandardEditActionsProtocol
::
copy
.
name
+
":"
)
->
}
_currentTextMenuActions
?.
copy
!=
null
NSSelectorFromString
(
UIResponderStandardEditActionsProtocol
::
cut
.
name
+
":"
)
->
override
fun
pasteConfiguration
():
UIPasteConfiguration
?
{
_currentTextMenuActions
?.
cut
!=
null
//https://developer.apple.com/documentation/uikit/uitextpasteconfigurationsupporting
NSSelectorFromString
(
UIResponderStandardEditActionsProtocol
::
paste
.
name
+
":"
)
->
//todo uikit copy/paste
_currentTextMenuActions
?.
paste
!=
null
return
_pasteConfiguration
NSSelectorFromString
(
UIResponderStandardEditActionsProtocol
::
selectAll
.
name
+
":"
)
->
}
_currentTextMenuActions
?.
selectAll
!=
null
else
->
false
override
fun
setPasteConfiguration
(
pasteConfiguration
:
UIPasteConfiguration
?)
{
//todo uikit copy/paste
_pasteConfiguration
=
pasteConfiguration
}
override
fun
pasteDelegate
():
UITextPasteDelegateProtocol
?
{
//todo uikit copy/paste
return
_pasteDelegate
}
override
fun
setPasteDelegate
(
pasteDelegate
:
UITextPasteDelegateProtocol
?)
{
//todo uikit copy/paste
_pasteDelegate
=
pasteDelegate
}
}
override
fun
keyboardType
():
UIKeyboardType
{
override
fun
keyboardType
():
UIKeyboardType
{
...
...
skiko/src/iosMain/kotlin/org/jetbrains/skiko/TextActions.kt
0 → 100644
View file @
673c85d1
package
org.jetbrains.skiko
interface
TextActions
{
/**
* Copy action. If null, then copy is not possible in current context
*/
val
copy
:
(()
->
Unit
)?
/**
* Paste action. If null, then paste is not possible in current context
*/
val
paste
:
(()
->
Unit
)?
/**
* Cut action. If null, then cut is not possible in current context
*/
val
cut
:
(()
->
Unit
)?
/**
* SelectAll action. If null, then select all is not possible in current context
*/
val
selectAll
:
(()
->
Unit
)?
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment