fix: ignore all out of bounds cursor errors, we don't need 100% accuracy on that

This commit is contained in:
zaaarf 2023-11-28 01:49:05 +01:00
parent e9527077e2
commit 70bd32a686
No known key found for this signature in database
GPG key ID: 6445A5CD15E5B40C
2 changed files with 20 additions and 13 deletions

View file

@ -1,6 +1,7 @@
package com.codemp.intellij.task; package com.codemp.intellij.task;
import com.codemp.intellij.CodeMP; import com.codemp.intellij.CodeMP;
import com.codemp.intellij.exceptions.lib.ChannelException;
import com.codemp.intellij.exceptions.lib.DeadlockedException; import com.codemp.intellij.exceptions.lib.DeadlockedException;
import com.codemp.intellij.jni.BufferHandler; import com.codemp.intellij.jni.BufferHandler;
import com.codemp.intellij.jni.CodeMPHandler; import com.codemp.intellij.jni.CodeMPHandler;
@ -94,7 +95,7 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
bufferEditor.getDocument() bufferEditor.getDocument()
))); )));
} }
} catch(Exception ex) { } catch(ChannelException ex) { //exited
TaskManager.nullBufferTask(); TaskManager.nullBufferTask();
Disposer.dispose(this); //stopped Disposer.dispose(this); //stopped
} }

View file

@ -1,6 +1,7 @@
package com.codemp.intellij.task; package com.codemp.intellij.task;
import com.codemp.intellij.CodeMP; import com.codemp.intellij.CodeMP;
import com.codemp.intellij.exceptions.lib.ChannelException;
import com.codemp.intellij.jni.CursorEventWrapper; import com.codemp.intellij.jni.CursorEventWrapper;
import com.codemp.intellij.jni.CursorHandler; import com.codemp.intellij.jni.CursorHandler;
import com.codemp.intellij.util.ColorUtil; import com.codemp.intellij.util.ColorUtil;
@ -42,7 +43,6 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo
try { try {
while(true) { while(true) {
CursorEventWrapper event = handler.recv(); CursorEventWrapper event = handler.recv();
Editor editor = CodeMP.ACTIVE_BUFFERS.get(event.getBuffer()); Editor editor = CodeMP.ACTIVE_BUFFERS.get(event.getBuffer());
if(editor == null) if(editor == null)
continue; continue;
@ -54,11 +54,21 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo
event.getEndRow(), event.getEndCol(), event.getEndRow(), event.getEndCol(),
event.getBuffer()); event.getBuffer());
int startOffset = editor.getDocument().getLineStartOffset(event.getStartRow()) + event.getStartCol(); try {
int endOffset = editor.getDocument().getLineStartOffset(event.getEndRow()) + event.getEndCol(); int startOffset = editor.getDocument()
.getLineStartOffset(event.getStartRow()) + event.getStartCol();
int endOffset = editor.getDocument()
.getLineStartOffset(event.getEndRow()) + event.getEndCol();
ApplicationManager.getApplication().invokeLater(() -> {
int documentLength = editor.getDocument().getTextLength();
if(startOffset > documentLength || endOffset > documentLength) {
CodeMP.LOGGER.debug(
"Out of bounds cursor: start was {}, end was {}, document length was {}!",
startOffset, endOffset, documentLength);
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
try {
RangeHighlighter highlighter = this.highlighterMap.get(event.getUser()); RangeHighlighter highlighter = this.highlighterMap.get(event.getUser());
if(highlighter != null) if(highlighter != null)
highlighter.dispose(); highlighter.dispose();
@ -77,14 +87,10 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo
Font.PLAIN Font.PLAIN
), HighlighterTargetArea.EXACT_RANGE ), HighlighterTargetArea.EXACT_RANGE
)); ));
} catch(IllegalArgumentException ex) { });
//suppress if the cursor only exceeds length by one, it's probably just him adding something at EOF } catch(IndexOutOfBoundsException ignored) {}
if(endOffset - editor.getDocument().getTextLength() != 1)
throw ex;
}
});
} }
} catch(Exception ex) { //exited } catch(ChannelException ex) { //exited
this.highlighterMap.forEach((s, r) -> r.dispose()); this.highlighterMap.forEach((s, r) -> r.dispose());
TaskManager.nullCursorTask(); TaskManager.nullCursorTask();
Disposer.dispose(this); Disposer.dispose(this);