fun selectText()

in remote-fixtures/src/main/kotlin/com/intellij/remoterobot/fixtures/TextEditorFixture.kt [221:243]


    fun selectText(text: String) {
        val stringBeginOffset = this.text.indexOf(text)
        if (stringBeginOffset != -1) {
            val stringEndOffset = text.length + stringBeginOffset
            scrollToOffset(stringBeginOffset)

            runJs("""
            // import package with WriteCommandAction
            importPackage(com.intellij.openapi.command)

            const editor = local.get('editor')
            const project = editor.getProject()
            
            WriteCommandAction.runWriteCommandAction(project, new Runnable({
                run: function () {
                    editor.getSelectionModel().setSelection($stringBeginOffset, $stringEndOffset);
                }
            }))
        """)
        } else {
            throw StringIndexOutOfBoundsException("text: '$text' was not found")
        }
    }