diff --git a/remote-fixtures/src/main/kotlin/com/intellij/remoterobot/fixtures/JListFixture.kt b/remote-fixtures/src/main/kotlin/com/intellij/remoterobot/fixtures/JListFixture.kt index b99110b0..a41c5db4 100644 --- a/remote-fixtures/src/main/kotlin/com/intellij/remoterobot/fixtures/JListFixture.kt +++ b/remote-fixtures/src/main/kotlin/com/intellij/remoterobot/fixtures/JListFixture.kt @@ -23,11 +23,18 @@ class JListFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : const fixture = new JListFixture(robot, component); const cellReader = new com.intellij.remoterobot.fixtures.dataExtractor.server.textCellRenderers.JListTextCellReader(); fixture.replaceCellReader(cellReader); + ctx.put("cellReader", cellReader) ctx.put("fixture", fixture) """ ) } + /* + Overrides cell width which will be used to parse text in it. JList::width is used as default, but sometimes you might need to make it bigger + https://github.com/JetBrains/intellij-ui-test-robot/issues/383 + */ + fun setCellReaderWidth(width: Int) = runJs("ctx.get('cellReader').setCellWidth($width)") + fun collectItems() = callJs>("ctx.get('fixture').contents()").toList() fun collectSelectedItems() = callJs>("ctx.get('fixture').selection()").toList() diff --git a/remote-robot/src/main/kotlin/com/intellij/remoterobot/fixtures/dataExtractor/server/textCellRenderers/JListTextCellReader.kt b/remote-robot/src/main/kotlin/com/intellij/remoterobot/fixtures/dataExtractor/server/textCellRenderers/JListTextCellReader.kt index f46db0e4..fcd677d9 100644 --- a/remote-robot/src/main/kotlin/com/intellij/remoterobot/fixtures/dataExtractor/server/textCellRenderers/JListTextCellReader.kt +++ b/remote-robot/src/main/kotlin/com/intellij/remoterobot/fixtures/dataExtractor/server/textCellRenderers/JListTextCellReader.kt @@ -7,12 +7,19 @@ import javax.swing.JList import javax.swing.ListCellRenderer class JListTextCellReader : JListCellReader { + + private var cellWidth: Int? = null + + fun setCellWidth(width: Int) { + cellWidth = width + } + override fun valueAt(list: JList<*>?, index: Int): String? { require(list != null) return computeOnEdt { @Suppress("UNCHECKED_CAST") val renderer = list.cellRenderer as ListCellRenderer val c = renderer.getListCellRendererComponent(JList(), list.model.getElementAt(index), index, true, true) - c.size = Dimension(list.width, 100) + c.size = Dimension(cellWidth ?: list.width, 100) TextParser.parseCellRenderer(c).joinToString(" ") { it.trim() } } }