-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Webview - Add event message passing from the Webview to the IDE (#370)
- Loading branch information
Showing
17 changed files
with
502 additions
and
165 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
src/main/java/com/jfrog/ide/idea/inspections/JumpToCode.java
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.jfrog.ide.idea.inspections; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.editor.Document; | ||
import com.intellij.openapi.editor.Editor; | ||
import com.intellij.openapi.editor.ScrollType; | ||
import com.intellij.openapi.editor.SelectionModel; | ||
import com.intellij.openapi.editor.markup.HighlighterTargetArea; | ||
import com.intellij.openapi.fileEditor.FileEditorManager; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.util.text.StringUtil; | ||
import com.intellij.openapi.vfs.LocalFileSystem; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.util.PsiUtilBase; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* The JumpToCode class is responsible for navigating to a specific location in a code file | ||
* and highlighting the corresponding code. | ||
*/ | ||
public class JumpToCode { | ||
Project project; | ||
FileEditorManager fileEditorManager; | ||
|
||
/** | ||
* Constructs a new {@code JumpToCode} with the provided project. | ||
* | ||
* @param project The current project. | ||
*/ | ||
private JumpToCode(@NotNull Project project) { | ||
this.project = project; | ||
fileEditorManager = FileEditorManager.getInstance(project); | ||
} | ||
|
||
public static JumpToCode getInstance(@NotNull Project project) { | ||
return project.getService(JumpToCode.class); | ||
} | ||
|
||
/** | ||
* Executes the jump to code operation by opening the file in the editor and highlighting the specified code range. | ||
* | ||
* @param filePath The path of the file to navigate to. | ||
* @param startRow The starting row of the code range. | ||
* @param endRow The ending row of the code range. | ||
* @param startColumn The starting column of the code range. | ||
* @param endColumn The ending column of the code range. | ||
*/ | ||
public void execute(String filePath, int startRow, int endRow, int startColumn, int endColumn) { | ||
if (this.project == null || this.fileEditorManager == null) return; | ||
VirtualFile file = getVirtualFile(filePath); | ||
if (file == null) return; | ||
ApplicationManager.getApplication().invokeLater(() -> { | ||
openFileInEditor(file); | ||
highlightCode(startRow, endRow, startColumn, endColumn); | ||
}); | ||
} | ||
|
||
private void openFileInEditor(VirtualFile file) { | ||
fileEditorManager.openFile(file, true); | ||
} | ||
|
||
private void highlightCode(int startRow, int endRow, int startColumn, int endColumn) { | ||
Editor editor = fileEditorManager.getSelectedTextEditor(); | ||
if (editor == null) return; | ||
Document document = getDocument(editor); | ||
if (document == null) return; | ||
int startOffset = getOffset(document, startRow - 1, startColumn - 1); | ||
int endOffset = getOffset(document, endRow - 1, endColumn - 1); | ||
highlightCode(editor, startOffset, endOffset); | ||
scrollToHighlightedCode(editor, startOffset); | ||
} | ||
|
||
private VirtualFile getVirtualFile(String path) { | ||
return LocalFileSystem.getInstance().findFileByPath(path); | ||
} | ||
|
||
private Document getDocument(Editor editor) { | ||
PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project); | ||
if (psiFile == null) return null; | ||
return psiFile.getViewProvider().getDocument(); | ||
} | ||
|
||
private int getOffset(Document document, int row, int column) { | ||
return StringUtil.lineColToOffset(document.getText(), row, column); | ||
} | ||
|
||
private void highlightCode(Editor editor, int startOffset, int endOffset) { | ||
SelectionModel selectionModel = editor.getSelectionModel(); | ||
selectionModel.setSelection(startOffset, endOffset); | ||
editor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, 0, null, HighlighterTargetArea.EXACT_RANGE); | ||
} | ||
|
||
private void scrollToHighlightedCode(Editor editor, int startOffset) { | ||
editor.getCaretModel().moveToOffset(startOffset); | ||
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER); | ||
} | ||
} |
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
29 changes: 0 additions & 29 deletions
29
src/main/java/com/jfrog/ide/idea/ui/jcef/message/MessagePacker.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/main/java/com/jfrog/ide/idea/ui/jcef/message/MessagePipe.java
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
src/main/java/com/jfrog/ide/idea/ui/jcef/message/MessagePipeSupport.java
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
src/main/java/com/jfrog/ide/idea/ui/jcef/message/MessageType.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
src/main/java/com/jfrog/ide/idea/ui/jcef/message/PackedMessage.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.