typedb / typedb-studio

TypeDB Studio (IDE)
https://typedb.com
Mozilla Public License 2.0
194 stars 43 forks source link

TypeDB Studio crashes when you use the "comment" keyboard shortcut on an empty line #705

Open maxrothman opened 1 year ago

maxrothman commented 1 year ago

Description

The "comment" keyboard shortcut (cmd+/ on Mac) toggles the presence of a "#" comment character at the beginning of a line. When this keyboard shortcut is used on an empty line, TypeDB Studio crashes with the following error:

Title: offset(-1) is out of bounds [0, 0]
Trace: java.lang.IllegalArgumentException: offset(-1) is out of bounds [0, 0]
    at androidx.compose.ui.text.MultiParagraph.requireIndexInRangeInclusiveEnd(MultiParagraph.kt:593)
    at androidx.compose.ui.text.MultiParagraph.getCursorRect(MultiParagraph.kt:442)
    at androidx.compose.ui.text.TextLayoutResult.getCursorRect(TextLayoutResult.kt:390)
    at com.vaticle.typedb.studio.framework.common.Util.getCursorRectSafely(Util.kt:81)
    at com.vaticle.typedb.studio.framework.editor.InputTarget.mayScrollToCursor(InputTarget.kt:265)
    at com.vaticle.typedb.studio.framework.editor.InputTarget.updateCursor$framework_editor_editor(InputTarget.kt:240)
    at com.vaticle.typedb.studio.framework.editor.InputTarget.updateCursor$framework_editor_editor$default(InputTarget.kt:234)
    at com.vaticle.typedb.studio.framework.editor.InputTarget.updatePosition$lambda-1(InputTarget.kt:209)
    at com.vaticle.typedb.common.collection.Either.apply(Either.java:70)
    at com.vaticle.typedb.studio.framework.editor.InputTarget.updatePosition$framework_editor_editor(InputTarget.kt:208)
    at com.vaticle.typedb.studio.framework.editor.TextProcessor$Writable.toggleComment(TextProcessor.kt:223)
    at com.vaticle.typedb.studio.framework.editor.EventHandler.executeEditorCommand(EventHandler.kt:166)
    at com.vaticle.typedb.studio.framework.editor.EventHandler.handleEditorEvent-ZmokQxo$framework_editor_editor(EventHandler.kt:113)
    at com.vaticle.typedb.studio.framework.editor.TextEditor$Layout$3$2$4.invoke-ZmokQxo(TextEditor.kt:295)
    at com.vaticle.typedb.studio.framework.editor.TextEditor$Layout$3$2$4.invoke(TextEditor.kt:295)
    at androidx.compose.ui.node.ModifiedKeyInputNode.propagateKeyEvent-ZmokQxo(ModifiedKeyInputNode.kt:47)
    at androidx.compose.ui.input.key.KeyInputModifier.processKeyInput-ZmokQxo(KeyInputModifier.kt:78)
    at androidx.compose.ui.platform.DesktopOwner_desktopKt.sendKeyEvent-eyBIOjY(DesktopOwner.desktop.kt:42)
    at androidx.compose.ui.platform.SkiaBasedOwner.sendKeyEvent-ZmokQxo(SkiaBasedOwner.skiko.kt:209)
    at androidx.compose.ui.ComposeScene.sendKeyEvent-ZmokQxo(ComposeScene.skiko.kt:486)
    at androidx.compose.ui.awt.ComposeLayer$onKeyEvent$1.invoke(ComposeLayer.desktop.kt:359)
    at androidx.compose.ui.awt.ComposeLayer$onKeyEvent$1.invoke(ComposeLayer.desktop.kt:358)
    at androidx.compose.ui.awt.ComposeLayer.catchExceptions(ComposeLayer.desktop.kt:89)
    at androidx.compose.ui.awt.ComposeLayer.onKeyEvent(ComposeLayer.desktop.kt:358)
    at androidx.compose.ui.awt.ComposeLayer.access$onKeyEvent(ComposeLayer.desktop.kt:70)
    at androidx.compose.ui.awt.ComposeLayer$6.keyPressed(ComposeLayer.desktop.kt:268)
    at java.desktop/java.awt.Component.processKeyEvent(Unknown Source)
    at java.desktop/java.awt.Component.processEvent(Unknown Source)
    at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
    at java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
    at java.desktop/java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
    at java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
    at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Unknown Source)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
    at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Unknown Source)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

Environment

  1. TypeDB version: 2.14.2
  2. OS of TypeDB server: Official TypeDB docker image, tag "latest"
  3. Studio version: 2.14.2
  4. OS of Studio: Mac OS 10.15.7
  5. Other environment details:

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Open a file in TypeDB Studio
  2. Place the cursor on an empty line
  3. Press the "comment" keyboard shortcut (cmd+/ on mac)
  4. See that TypeDB Studio crashes

Expected Output

A "#" character is placed at the beginning of the line

Actual Output

TypeDB Studio crashes with the error included above

Additional information

N/A

jamesreprise commented 1 year ago

Nice catch. This has been present for a while but not caught until now. Apologies for the inconvenience. This will be fixed in our upcoming release. I'll drop a message here and close this issue when the release has taken place.

juskek commented 1 year ago

This bug was occurring for me in TypeDB Studio 2.14.0, but it seems to be fixed in 2.17.0