Skip to content

Commit

Permalink
Revert "refactor(terminal): replace terminal text extraction method"
Browse files Browse the repository at this point in the history
This reverts commit bcd2145.
  • Loading branch information
phodal committed Jan 24, 2025
1 parent bcd2145 commit 065c149
Showing 1 changed file with 2 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.terminal.JBTerminalWidget
import com.intellij.ui.components.panels.HorizontalLayout
import com.intellij.util.ui.JBUI
import com.jediterm.core.compatibility.Point
import com.jediterm.terminal.model.SelectionUtil
import com.jediterm.terminal.model.TerminalSelection
import com.jediterm.terminal.ui.TerminalPanel
import com.jediterm.terminal.ui.TerminalWidgetListener
import org.jetbrains.plugins.terminal.LocalTerminalDirectRunner
import java.awt.BorderLayout
import java.awt.Dimension
Expand Down Expand Up @@ -73,7 +70,7 @@ class TerminalLangSketchProvider : LanguageSketchProvider {
val sendButton = JButton("Send to Sketch").apply {
addMouseListener(object : MouseAdapter() {
override fun mouseClicked(e: MouseEvent?) {
val output = getText(terminalWidget!!.terminalPanel)
val output = terminalWidget!!.text
sendToSketch(project, output)
}
})
Expand Down Expand Up @@ -150,22 +147,6 @@ class TerminalLangSketchProvider : LanguageSketchProvider {
}
}

/// in Intellij 223 this method is not exist, so we need to copy it.
fun getText(terminalPanel: TerminalPanel): String {
val buffer = terminalPanel.terminalTextBuffer
buffer.lock()
try {
val selection = TerminalSelection(
Point(0, -buffer.historyLinesCount),
Point(buffer.width, buffer.screenLinesCount - 1)
)
val points = selection.pointsForRun(buffer.width)
return SelectionUtil.getSelectionText(points.first!!, points.second!!, buffer)
} finally {
buffer.unlock()
}
}

private fun sendToSketch(project: Project, output: String) {
val contentManager = ToolWindowManager.getInstance(project).getToolWindow("AutoDev")?.contentManager
contentManager?.component?.components?.filterIsInstance<SketchToolWindow>()?.firstOrNull().let {
Expand Down

0 comments on commit 065c149

Please sign in to comment.