fix: null check before buffer active check

This commit is contained in:
əlemi 2024-10-02 02:27:58 +02:00
parent f815e60605
commit 96dde7a423
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -14,6 +14,9 @@ import com.intellij.openapi.editor.VisualPosition;
import com.intellij.openapi.editor.event.CaretEvent; import com.intellij.openapi.editor.event.CaretEvent;
import com.intellij.openapi.editor.event.CaretListener; import com.intellij.openapi.editor.event.CaretListener;
import mp.code.data.Cursor; import mp.code.data.Cursor;
import java.nio.file.Path;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CursorEventListener implements CaretListener { public class CursorEventListener implements CaretListener {
@ -21,14 +24,21 @@ public class CursorEventListener implements CaretListener {
@Override @Override
@SneakyThrows @SneakyThrows
public void caretPositionChanged(@NotNull CaretEvent event) { public void caretPositionChanged(@NotNull CaretEvent event) {
// TODO instead of returning, should un-set remote cursor position (once)
Caret caret = event.getCaret(); Caret caret = event.getCaret();
if(caret == null) if (caret == null) return;
return;
VirtualFile file = event.getEditor().getVirtualFile(); VirtualFile file = event.getEditor().getVirtualFile();
if(file == null) return; if (file == null) return;
if(CodeMP.getActiveWorkspace().getBuffer(CodeMP.BUFFER_MAPPER.get(file.toNioPath())).isEmpty()) return; Path nioPath = file.toNioPath();
if (nioPath == null) return;
String buffer_name = CodeMP.BUFFER_MAPPER.get(nioPath);
if (buffer_name == null) return;
if(CodeMP.getActiveWorkspace().getBuffer(buffer_name).isEmpty()) return;
VisualPosition startPos = caret.getSelectionStartPosition(); VisualPosition startPos = caret.getSelectionStartPosition();
VisualPosition endPos = caret.getSelectionEndPosition(); VisualPosition endPos = caret.getSelectionEndPosition();