scoop:scoop.ui:0.1.0
src/text/editor/primary_selection.scoop
Selected production source · src/text/editor/primary_selection.scoop
1
package scoop.ui.text3
import scoop.graphics.Point4
import scoop.surface.FocusOrigin5
import scoop.window.Utf8Range7
internal fun editorPastePrimary(host: TextEditHost, local: Point?): Boolean {8
if (9
host.closed ||10
!host.options.enabled ||11
host.options.readOnly ||12
!host.area.scope.isInputAllowed ||13
!editorTouchReady(host)14
)15
return false16
val point = local ?: return false17
val frame = host.accepted ?: return false18
val state = host.current19
val revision = state.revision20
if (frame.display.source.text != state.text)21
return false22
val displayed = frame.layout.hitTest(point)23
val position = frame.display.documentPosition(frame.display.mapping.reverse(displayed))24
// Reading first preserves the old PRIMARY even when this click selects another position.25
val text = host.primarySelection.read(host.options.primarySelection) ?: return false26
val sameFrame =27
when (host.accepted) {28
case Some(val current) -> current === frame29
case None -> false30
}31
if (32
host.closed ||33
host.current !==34
state ||35
state.revision !=36
revision ||37
!sameFrame ||38
!host.options.enabled ||39
host.options.readOnly ||40
!host.area.scope.isInputAllowed41
)42
return false43
host.area.requestFocus(FocusOrigin.Pointer)44
if (45
host.closed ||46
host.current !==47
state ||48
state.revision !=49
revision ||50
!host.options.enabled ||51
host.options.readOnly ||52
!host.area.scope.isInputAllowed ||53
!editorTouchReady(host)54
)55
return true56
editorStopDrag(host, false)57
host.perform(58
{59
editorApplyEdit(60
host,61
Utf8Range(position.byteOffset, position.byteOffset),62
text,63
TextEditSource.Paste64
)65
},66
endComposition = true67
)68
return true69
}