mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-11-23 23:54:48 +01:00
fix: ignore all out of bounds cursor errors, we don't need 100% accuracy on that
This commit is contained in:
parent
e9527077e2
commit
70bd32a686
2 changed files with 20 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
|||
package com.codemp.intellij.task;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.exceptions.lib.ChannelException;
|
||||
import com.codemp.intellij.exceptions.lib.DeadlockedException;
|
||||
import com.codemp.intellij.jni.BufferHandler;
|
||||
import com.codemp.intellij.jni.CodeMPHandler;
|
||||
|
@ -94,7 +95,7 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
|
|||
bufferEditor.getDocument()
|
||||
)));
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
} catch(ChannelException ex) { //exited
|
||||
TaskManager.nullBufferTask();
|
||||
Disposer.dispose(this); //stopped
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.codemp.intellij.task;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.exceptions.lib.ChannelException;
|
||||
import com.codemp.intellij.jni.CursorEventWrapper;
|
||||
import com.codemp.intellij.jni.CursorHandler;
|
||||
import com.codemp.intellij.util.ColorUtil;
|
||||
|
@ -42,7 +43,6 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo
|
|||
try {
|
||||
while(true) {
|
||||
CursorEventWrapper event = handler.recv();
|
||||
|
||||
Editor editor = CodeMP.ACTIVE_BUFFERS.get(event.getBuffer());
|
||||
if(editor == null)
|
||||
continue;
|
||||
|
@ -54,11 +54,21 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo
|
|||
event.getEndRow(), event.getEndCol(),
|
||||
event.getBuffer());
|
||||
|
||||
int startOffset = editor.getDocument().getLineStartOffset(event.getStartRow()) + event.getStartCol();
|
||||
int endOffset = editor.getDocument().getLineStartOffset(event.getEndRow()) + event.getEndCol();
|
||||
try {
|
||||
int startOffset = editor.getDocument()
|
||||
.getLineStartOffset(event.getStartRow()) + event.getStartCol();
|
||||
int endOffset = editor.getDocument()
|
||||
.getLineStartOffset(event.getEndRow()) + event.getEndCol();
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
try {
|
||||
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;
|
||||
}
|
||||
|
||||
RangeHighlighter highlighter = this.highlighterMap.get(event.getUser());
|
||||
if(highlighter != null)
|
||||
highlighter.dispose();
|
||||
|
@ -77,14 +87,10 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo
|
|||
Font.PLAIN
|
||||
), HighlighterTargetArea.EXACT_RANGE
|
||||
));
|
||||
} catch(IllegalArgumentException ex) {
|
||||
//suppress if the cursor only exceeds length by one, it's probably just him adding something at EOF
|
||||
if(endOffset - editor.getDocument().getTextLength() != 1)
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
} catch(IndexOutOfBoundsException ignored) {}
|
||||
}
|
||||
} catch(Exception ex) { //exited
|
||||
} catch(ChannelException ex) { //exited
|
||||
this.highlighterMap.forEach((s, r) -> r.dispose());
|
||||
TaskManager.nullCursorTask();
|
||||
Disposer.dispose(this);
|
||||
|
|
Loading…
Reference in a new issue