scoop:scoop.ui:0.1.0
src/text/editor/blink.scoop
Selected production source · src/text/editor/blink.scoop
1
package scoop.ui.text3
import scoop.platform.time.MonotonicTimeSource4
import scoop.window.WindowActivity6
internal fun editorWindowActivity(host: TextEditHost, activity: WindowActivity) {7
if (host.closed)8
return9
if (!activity.focused || !activity.visible || activity.occluded) {10
host.blink.cancel()11
host.caretVisible = true12
editorStopDrag(host, false)13
} else14
if (host.area.isFocusActive) {15
host.blink.cancel()16
host.caretVisible = true17
host.scope.requestFrame()18
}19
}21
private fun editorCanBlink(host: TextEditHost): Boolean {22
if (23
host.closed ||24
!host.scope.isMounted ||25
!host.area.isFocusActive ||26
host.current.isComposing ||27
host.current.selection.anchor !=28
host.current.selection.cursor ||29
!host.window.isVisible ||30
host.window.isOccluded ||31
host.area.visibleCaretBounds ==32
None33
)34
return false35
val interval = editorBlinkInterval(host)36
return interval.floorSeconds > 0L || interval.nanosecondsOfSecond > 037
}39
internal fun editorScheduleBlink(host: TextEditHost) {40
if (!editorCanBlink(host)) {41
host.blink.cancel()42
return43
}44
if (!host.blink.isScheduled)45
host.blink.schedule(MonotonicTimeSource.now() + editorBlinkInterval(host))46
}48
internal fun editorBlink(host: TextEditHost) {49
if (!editorCanBlink(host))50
return51
host.caretVisible = !host.caretVisible52
host.scope.requestFrame()53
// The next successful frame decides whether another tick is still useful.54
}