💄 improve small interactions
This commit is contained in:
parent
6acee710d7
commit
0c2d8880dc
3 changed files with 37 additions and 11 deletions
|
|
@ -8,6 +8,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent
|
|||
import com.intellij.openapi.actionSystem.PlatformDataKeys
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.ui.DialogWrapper
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.wm.ToolWindowManager
|
||||
|
|
@ -38,7 +39,8 @@ class AcceptDiffAction : AnAction() {
|
|||
}
|
||||
|
||||
private fun acceptVerticalDiff(e: AnActionEvent) {
|
||||
val editor = e.getData(PlatformDataKeys.EDITOR) ?: return
|
||||
val project = e.project ?: return
|
||||
val editor = e.getData(PlatformDataKeys.EDITOR) ?: FileEditorManager.getInstance(project).selectedTextEditor ?: return
|
||||
val diffStreamService = service<DiffStreamService>()
|
||||
diffStreamService.accept(editor)
|
||||
}
|
||||
|
|
@ -56,7 +58,8 @@ class RejectDiffAction : AnAction() {
|
|||
}
|
||||
|
||||
private fun rejectVerticalDiff(e: AnActionEvent) {
|
||||
val editor = e.getData(PlatformDataKeys.EDITOR) ?: return
|
||||
val project = e.project ?: return
|
||||
val editor = e.getData(PlatformDataKeys.EDITOR) ?: FileEditorManager.getInstance(project).selectedTextEditor ?: return
|
||||
val diffStreamService = service<DiffStreamService>()
|
||||
diffStreamService.reject(editor)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class DiffStreamHandler(
|
|||
|
||||
private val currentLineKey = run {
|
||||
val attributes = TextAttributes().apply {
|
||||
backgroundColor = JBColor(0x20888888.toInt(), 0x20888888.toInt())
|
||||
backgroundColor = JBColor(0x40888888.toInt(), 0x40888888.toInt())
|
||||
}
|
||||
val key = TextAttributesKey.createTextAttributesKey("CONTINUE_DIFF_CURRENT_LINE")
|
||||
key.let { editor.colorsScheme.setAttributes(it, attributes) }
|
||||
|
|
@ -53,7 +53,7 @@ class DiffStreamHandler(
|
|||
|
||||
private val unfinishedKey = run {
|
||||
val attributes = TextAttributes().apply {
|
||||
backgroundColor = JBColor(0x10888888.toInt(), 0x10888888.toInt())
|
||||
backgroundColor = JBColor(0x20888888.toInt(), 0x20888888.toInt())
|
||||
}
|
||||
val key = TextAttributesKey.createTextAttributesKey("CONTINUE_DIFF_UNFINISHED_LINE")
|
||||
key.let { editor.colorsScheme.setAttributes(it, attributes) }
|
||||
|
|
@ -64,6 +64,17 @@ class DiffStreamHandler(
|
|||
private var currentLineHighlighter: RangeHighlighter? = null
|
||||
private val unfinishedHighlighters: MutableList<RangeHighlighter> = mutableListOf()
|
||||
private var changeCount: Int = 0
|
||||
private var running: Boolean = false
|
||||
|
||||
init {
|
||||
// Highlight the range with unfinished color
|
||||
for (i in startLine..endLine) {
|
||||
val highlighter = editor.markupModel.addLineHighlighter(unfinishedKey, min(
|
||||
i, editor.document.lineCount - 1
|
||||
), HighlighterLayer.FIRST)
|
||||
unfinishedHighlighters.add(highlighter)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleDiffLine(type: DiffLineType, line: String) {
|
||||
println("DiffStreamHandler: handleDiffLine: $currentLine, $type, $line")
|
||||
|
|
@ -136,18 +147,23 @@ class DiffStreamHandler(
|
|||
fun accept() {
|
||||
// Accept the changes
|
||||
editor.markupModel.removeAllHighlighters()
|
||||
onClose()
|
||||
running = false
|
||||
}
|
||||
|
||||
fun reject() {
|
||||
// Reject the changes
|
||||
resetState()
|
||||
onClose()
|
||||
running = false
|
||||
}
|
||||
|
||||
fun run(input : String, prefix : String, highlighted : String, suffix : String) {
|
||||
// Undo changes
|
||||
resetState()
|
||||
|
||||
running = true
|
||||
|
||||
// Highlight the range with unfinished color
|
||||
for (i in startLine..endLine) {
|
||||
val highlighter = editor.markupModel.addLineHighlighter(unfinishedKey, min(
|
||||
|
|
@ -169,6 +185,10 @@ class DiffStreamHandler(
|
|||
"suffix" to suffix,
|
||||
"language" to virtualFile?.fileType?.name,
|
||||
), null) { response ->
|
||||
if (!running) {
|
||||
return@request
|
||||
}
|
||||
|
||||
val parsed = Gson().fromJson(response, Map::class.java)
|
||||
val done = parsed["done"] as? Boolean
|
||||
if (done == true) {
|
||||
|
|
|
|||
|
|
@ -94,7 +94,8 @@ class InlineEditAction : AnAction(), DumbAware {
|
|||
}
|
||||
|
||||
val panel = makePanel(customPanelRef, textArea, inlayRef, leftInset, {onEnter()}, {
|
||||
inlayRef.get().dispose()
|
||||
diffStreamHandler.reject()
|
||||
selectionModel.setSelection(start, end)
|
||||
}, {
|
||||
diffStreamService.accept(editor)
|
||||
inlayRef.get().dispose()
|
||||
|
|
@ -112,7 +113,10 @@ class InlineEditAction : AnAction(), DumbAware {
|
|||
textArea.addKeyListener(object : KeyAdapter() {
|
||||
override fun keyPressed(e: KeyEvent) {
|
||||
if (e.keyCode == KeyEvent.VK_ESCAPE) {
|
||||
inlayRef.get().dispose()
|
||||
diffStreamHandler.reject()
|
||||
|
||||
// Re-highlight the selected text
|
||||
selectionModel.setSelection(start, end)
|
||||
} else if (e.keyCode == KeyEvent.VK_ENTER) {
|
||||
if (e.modifiersEx == KeyEvent.SHIFT_DOWN_MASK) {
|
||||
textArea.document.insertString(textArea.caretPosition, "\n", null)
|
||||
|
|
@ -186,7 +190,7 @@ class InlineEditAction : AnAction(), DumbAware {
|
|||
setup()
|
||||
|
||||
val shadow = DropShadowBorder()
|
||||
shadow.shadowColor = JBColor(0xb0b0b0, 0x808080)
|
||||
shadow.shadowColor = JBColor(0xb0b0b0, 0x505050)
|
||||
shadow.isShowRightShadow = true
|
||||
shadow.isShowBottomShadow = true
|
||||
shadow.shadowSize = SHADOW_SIZE
|
||||
|
|
@ -216,7 +220,7 @@ class CustomPanel(layout: MigLayout, onEnter: () -> Unit, onCancel: () -> Unit,
|
|||
foreground = Color(128, 128, 128, 200)
|
||||
background = defaultBackground
|
||||
}
|
||||
val rightButton = CustomButton("⏎ Submit", {onEnter()}).apply {
|
||||
val rightButton = CustomButton("Submit", {onEnter()}).apply {
|
||||
background = GetTheme().getHighlight()
|
||||
foreground = JBColor.WHITE
|
||||
}
|
||||
|
|
@ -236,11 +240,11 @@ class CustomPanel(layout: MigLayout, onEnter: () -> Unit, onCancel: () -> Unit,
|
|||
font = Font("Arial", Font.PLAIN, 11)
|
||||
}
|
||||
|
||||
val leftButton = CustomButton("${getAltKeyLabel()}⇧Y", {onReject()}).apply {
|
||||
val leftButton = CustomButton("${getAltKeyLabel()}⇧N", {onReject()}).apply {
|
||||
background = Color(255, 0, 0, 64)
|
||||
}
|
||||
|
||||
val rightButton = CustomButton("${getAltKeyLabel()}⇧N", {onAccept()}).apply {
|
||||
val rightButton = CustomButton("${getAltKeyLabel()}⇧Y", {onAccept()}).apply {
|
||||
background = Color(0, 255, 0, 64)
|
||||
}
|
||||
|
||||
|
|
@ -262,7 +266,6 @@ class CustomPanel(layout: MigLayout, onEnter: () -> Unit, onCancel: () -> Unit,
|
|||
}
|
||||
|
||||
fun enter() {
|
||||
// Switch to subPanelB
|
||||
remove(subPanelA)
|
||||
add(subPanelB, "grow, gap 0!")
|
||||
revalidate()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue