-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: CopilotUndoManager service for tracking actions on save (#124)
* CopilotUndoManager service for tracking actions on save * unit test and fixes * project metadata * spotless * run tests on gh actions * Update validation.yml use gradel wrapper from project * use test logger
- Loading branch information
1 parent
86ddfe2
commit fa60159
Showing
12 changed files
with
454 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 17 additions & 27 deletions
44
src/main/kotlin/com/vaadin/plugin/copilot/handler/RedoHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,26 @@ | ||
package com.vaadin.plugin.copilot.handler | ||
|
||
import com.intellij.openapi.application.runInEdt | ||
import com.intellij.openapi.application.runWriteAction | ||
import com.intellij.openapi.command.impl.UndoManagerImpl | ||
import com.intellij.openapi.command.undo.UndoManager | ||
import com.intellij.openapi.fileEditor.FileEditor | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.findDocument | ||
import com.vaadin.plugin.actions.VaadinCompileOnSaveAction | ||
import com.intellij.openapi.vfs.VirtualFile | ||
|
||
class RedoHandler(project: Project, data: Map<String, Any>) : UndoHandler(project, data) { | ||
|
||
private val copilotActionPrefix = "_Redo Vaadin Copilot" | ||
override fun getOpsCount(vfsFile: VirtualFile): Int { | ||
return getCopilotUndoManager().getRedoCount(vfsFile) | ||
} | ||
|
||
override fun before(vfsFile: VirtualFile) { | ||
getCopilotUndoManager().redoStart(vfsFile) | ||
} | ||
|
||
override fun runManagerAction(undoManager: UndoManager, editor: FileEditor) { | ||
undoManager.redo(editor) | ||
} | ||
|
||
override fun run(): HandlerResponse { | ||
for (vfsFile in vfsFiles) { | ||
runInEdt { | ||
getEditorWrapper(vfsFile).use { wrapper -> | ||
val editor = wrapper.getFileEditor() | ||
val undoManager = UndoManagerImpl.getInstance(project) | ||
runWriteAction { | ||
if (undoManager.isRedoAvailable(editor)) { | ||
val redo = undoManager.getRedoActionNameAndDescription(editor).first | ||
if (redo.startsWith(copilotActionPrefix)) { | ||
undoManager.redo(editor) | ||
commitAndFlush(vfsFile.findDocument()) | ||
LOG.info("$redo performed on ${vfsFile.path}") | ||
VaadinCompileOnSaveAction().compile(project, vfsFile) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return RESPONSE_OK | ||
override fun after(vfsFile: VirtualFile) { | ||
getCopilotUndoManager().redoDone(vfsFile) | ||
LOG.info("$vfsFile redo performed") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.