Skip to content

Commit efe5c65

Browse files
Sahar MehrpourSahar Mehrpour
authored andcommitted
open file and move caret is fixed
1 parent 3f88d4f commit efe5c65

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/FileChangeManager.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import com.google.gson.JsonObject;
33
import com.intellij.openapi.application.ApplicationManager;
44
import com.intellij.openapi.components.ProjectComponent;
5+
import com.intellij.openapi.vfs.LocalFileSystem;
56
import com.intellij.util.messages.MessageBusConnection;
67
import com.intellij.openapi.vfs.VirtualFileManager;
78
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
@@ -246,16 +247,16 @@ void processReceivedMessages(JsonObject messageAsJson) {
246247
//System.out.println(SRCMLHandler.findLineNumber(projectPath + "/tempResultXmlFile.xml"));
247248

248249
EventQueue.invokeLater(() -> {
249-
String[] filePath = messageAsJson.get("data").getAsJsonObject().get("fileName").getAsString().split("/");
250-
String fileToFocusOn = filePath[filePath.length - 1];
251-
int indexToFocusOn = SRCMLHandler.findLineNumber(projectPath + "/tempResultXmlFile.xml");
252-
// Project currentProject = ProjectManager.getInstance().getOpenProjects()[0];
253-
VirtualFile theVFile = FilenameIndex.getVirtualFilesByName(currentProject, fileToFocusOn, GlobalSearchScope.projectScope(currentProject)).iterator().next();
254-
FileEditorManager.getInstance(currentProject).openFile(theVFile, true);
250+
String fileRelativePath = messageAsJson.get("data").getAsJsonObject().get("fileName").getAsString();
251+
String relativePath = fileRelativePath.startsWith("/") ? fileRelativePath : "/" + fileRelativePath;
252+
VirtualFile fileByPath = LocalFileSystem.getInstance().findFileByPath(relativePath);
253+
FileEditorManager.getInstance(currentProject).openFile(fileByPath, true);
255254
Editor theEditor = FileEditorManager.getInstance(currentProject).getSelectedTextEditor();
255+
int indexToFocusOn = SRCMLHandler.findLineNumber(projectPath + "/tempResultXmlFile.xml");
256256
theEditor.getCaretModel().moveToOffset(indexToFocusOn);
257257
theEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
258258
});
259+
259260
break;
260261

261262
case "MODIFIED_RULE":

0 commit comments

Comments
 (0)