Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ actual object ParamsProvider {
private const val DEFAULT_REPAINT_INTERVAL_MS = 333
private const val DEFAULT_IMAGE_CACHE_SIZE_CHARS = 5_000_000
private const val DEFAULT_BLOCK_CLOSING = true
private val DEFAULT_TYPING_CLEAR_STRATEGY = TypingClearStrategy.SERVER_VALIDATION
private const val DEFAULT_HIDE_MAIN_CANVAS_ON_SPECULATIVE_TYPING = false

val SYSTEM_SCALING_RATIO
get() = window.devicePixelRatio // get every time because it can be changed
Expand Down Expand Up @@ -100,6 +102,8 @@ actual object ParamsProvider {
actual val IMAGE_CACHE_SIZE_CHARS: Int
val BLOCK_CLOSING: Boolean
val LAYOUT_TYPE: LayoutType
val TYPING_CLEAR_STRATEGY: TypingClearStrategy
val HIDE_MAIN_CANVAS_ON_SPECULATIVE_TYPING: Boolean
val SCALING_RATIO: Double
get() = SYSTEM_SCALING_RATIO * USER_SCALING_RATIO

Expand Down Expand Up @@ -161,6 +165,14 @@ actual object ParamsProvider {
"frAzerty" -> LayoutType.FR_AZERTY
else -> LayoutType.JS_DEFAULT
}
TYPING_CLEAR_STRATEGY = when (searchParams.get("typingClearStrategy")) {
"server" -> TypingClearStrategy.SERVER_VALIDATION
"position" -> TypingClearStrategy.BY_POSITION
"naive" -> TypingClearStrategy.NAIVE
else -> DEFAULT_TYPING_CLEAR_STRATEGY
}
HIDE_MAIN_CANVAS_ON_SPECULATIVE_TYPING = searchParams.get("hideOnSpeculative")?.toBoolean()
?: DEFAULT_HIDE_MAIN_CANVAS_ON_SPECULATIVE_TYPING
}
}

Expand All @@ -181,4 +193,10 @@ actual object ParamsProvider {
JS_DEFAULT,
FR_AZERTY,
}

enum class TypingClearStrategy {
NAIVE,
BY_POSITION,
SERVER_VALIDATION,
}
}
2 changes: 2 additions & 0 deletions projector-client-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Name | Type | Default value | Description
`cacheSize` | Int | `5M` | Set size of cache for images in Chars.
`blockClosing` | Boolean | `true` | Enable blocking of accidental closing of the web page
`relayServerId` | String? | Not present | Identifier of Projector server to connect to for relay connection. Warning: Static files must be accessed via https when relay is used.
`typingClearStrategy` | String | `server` | Sets strategy of removing speculative symbols: <br/> `server` - symbol is removed when server sends back validation of its insertion in the text; <br/> `position` - symbols are removed when a new string is painted at the position of those symbols (faster, but may be inaccurate); <br/> `naive` - ALL symbols are removed when any new string is painted (legacy variant).
`hideOnSpeculative` | Boolean | `false` | Hide main window canvas when speculative symbols are typed and not removed yet.

## Shortcuts
- `Ctrl + F10` prints statistics to the browser console. Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package org.jetbrains.projector.client.web
import kotlinx.browser.window
import org.jetbrains.projector.client.common.SingleRenderingSurfaceProcessor.Companion.shrinkByPaintEvents
import org.jetbrains.projector.client.common.misc.ImageCacher
import org.jetbrains.projector.client.common.misc.ParamsProvider
import org.jetbrains.projector.client.web.component.MarkdownPanelManager
import org.jetbrains.projector.client.web.input.InputController
import org.jetbrains.projector.client.web.misc.PingStatistics
Expand All @@ -34,6 +35,7 @@ import org.jetbrains.projector.client.web.state.ProjectorUI
import org.jetbrains.projector.client.web.window.OnScreenMessenger
import org.jetbrains.projector.client.web.window.WindowDataEventsProcessor
import org.jetbrains.projector.common.misc.Do
import org.jetbrains.projector.common.protocol.data.Point
import org.jetbrains.projector.common.protocol.toClient.*
import org.jetbrains.projector.util.logging.Logger
import org.w3c.dom.url.URL
Expand Down Expand Up @@ -85,17 +87,41 @@ class ServerEventsProcessor(private val windowDataEventsProcessor: WindowDataEve
// todo: should WindowManager.lookAndFeelChanged() be called here?
OnScreenMessenger.lookAndFeelChanged()
}
is SpeculativeEvent -> when (command) {
is SpeculativeEvent.SpeculativeStringDrawnEvent -> {
if (ParamsProvider.TYPING_CLEAR_STRATEGY == ParamsProvider.TypingClearStrategy.SERVER_VALIDATION) {
typing.onSymbolValidated(command.operationId)
}

Unit
}
}
}
}

// todo: determine the moment better
if (drawCommandsEvents.any { it.drawEvents.any { drawEvent -> drawEvent is ServerDrawStringEvent } }) {
typing.removeSpeculativeImage()
if (ParamsProvider.TYPING_CLEAR_STRATEGY == ParamsProvider.TypingClearStrategy.NAIVE) {
if (drawCommandsEvents.any { it.drawEvents.any { drawEvent -> drawEvent is ServerDrawStringEvent } }) {
typing.removeSpeculativeImage()
}
}

drawCommandsEvents.sortWith(drawingOrderComparator)

drawCommandsEvents.forEach { event ->

if (ParamsProvider.TYPING_CLEAR_STRATEGY == ParamsProvider.TypingClearStrategy.BY_POSITION) {

var verticalOffset = 0.0

event.drawEvents.forEach { drawEvent ->
when (drawEvent) {
is ServerSetTransformEvent -> verticalOffset = drawEvent.tx[5]
is ServerDrawStringEvent -> typing.onDrawString(drawEvent, Point(0.0, verticalOffset))
else -> {}
}
}
}

Do exhaustive when (val target = event.target) {
is ServerDrawCommandsEvent.Target.Onscreen -> windowDataEventsProcessor.draw(target.windowId, event.drawEvents)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.jetbrains.projector.common.protocol.data.*
import org.jetbrains.projector.common.protocol.handshake.ProtocolType
import org.jetbrains.projector.common.protocol.toClient.*
import org.jetbrains.projector.common.protocol.toClient.data.idea.CaretInfo
import org.jetbrains.projector.common.protocol.toClient.data.idea.SelectionInfo
import kotlin.js.Json
import kotlin.math.roundToLong

Expand Down Expand Up @@ -67,6 +68,7 @@ object ManualJsonToClientMessageDecoder : ToClientMessageDecoder {
"n" -> ServerMarkdownEvent.ServerMarkdownScrollEvent(content["a"] as Int, content["b"] as Int)
"o" -> ServerMarkdownEvent.ServerMarkdownBrowseUriEvent(content["a"] as String)
"p" -> ServerWindowColorsEvent(content["a"].unsafeCast<Json>().toColorsStorage())
"q" -> SpeculativeEvent.SpeculativeStringDrawnEvent(content["a"] as Int)
else -> throw IllegalArgumentException("Unsupported event type: ${JSON.stringify(this)}")
}
}
Expand Down Expand Up @@ -98,13 +100,29 @@ object ManualJsonToClientMessageDecoder : ToClientMessageDecoder {
content["g"] as Int,
content["h"] as Int,
content["i"] as Int,
content["j"] as Int,
content["k"].unsafeCast<Json>().toPoint(),
content["l"] as Int,
)
else -> throw IllegalArgumentException("Unsupported caret info type: ${JSON.stringify(this)}")
}
}

private fun Json.toCaretInfo(): CaretInfo {
return CaretInfo(this["a"].unsafeCast<Json>().toPoint())
return CaretInfo(
this["a"].unsafeCast<Json>().toPoint(),
this["b"] as Int,
this["c"]?.let { it.unsafeCast<Json>().toSelectionInfo() },
)
}

private fun Json.toSelectionInfo(): SelectionInfo {
return SelectionInfo(
this["a"].unsafeCast<Json>().toPoint(),
this["b"] as Int,
this["c"].unsafeCast<Json>().toPoint(),
this["d"] as Int,
)
}

private fun Array<Any>.toTarget(): ServerDrawCommandsEvent.Target {
Expand Down
Loading