mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-12-22 20:44:53 +01:00
feat: updated actions
This commit is contained in:
parent
7c5c851f6f
commit
5a42577a1f
17 changed files with 106 additions and 328 deletions
|
@ -10,7 +10,6 @@ import org.jetbrains.annotations.NotNull;
|
|||
public class ConnectAction extends AnAction {
|
||||
public static void connect(AnActionEvent e, String url, boolean silent) {
|
||||
CodeMP.connect(url);
|
||||
|
||||
if(!silent) ActionUtil.notify(e,
|
||||
"Success", String.format("Connected to %s!", url));
|
||||
CodeMP.LOGGER.debug("Connected to {}!", url);
|
||||
|
|
|
@ -9,9 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
public class DisconnectAction extends AnAction {
|
||||
public static void disconnect(AnActionEvent e, boolean silent) {
|
||||
String url = CodeMP.getClient("disconnect").getUrl();
|
||||
|
||||
CodeMP.disconnect();
|
||||
|
||||
if(!silent) ActionUtil.notify(e,
|
||||
"Success", String.format("Disconnected from %s!", url));
|
||||
CodeMP.LOGGER.debug("Connected to {}!", url);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.codemp.intellij.actions;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.actions.buffer.BufferAttachAction;
|
||||
import com.codemp.intellij.actions.workspace.WorkspaceJoinAction;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
|
@ -15,7 +14,6 @@ public class FastForwardAction extends AnAction {
|
|||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
ConnectAction.connect(e, "http://alemi.dev:50052", true);
|
||||
WorkspaceJoinAction.join(e, "default", true);
|
||||
BufferAttachAction.attach(e, "fucl", true);
|
||||
CodeMP.LOGGER.debug("Completed quick startup for testing!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package com.codemp.intellij.actions.buffer;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.jni.BufferHandler;
|
||||
import com.codemp.intellij.util.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BufferAttachAction extends AnAction {
|
||||
public static void attach(AnActionEvent e, String buffer, boolean silent) {
|
||||
BufferHandler bufferHandler = CodeMPHandler.attach(buffer);
|
||||
if(!silent) ActionUtil.notify(e, "Success",
|
||||
String.format("Successfully attached to buffer to buffer to %s!", buffer));
|
||||
CodeMP.LOGGER.debug("Attached to buffer to {}!", buffer);
|
||||
|
||||
//TODO "get" the Editor corresponding to buffer, for now use the current one
|
||||
Editor editor = ActionUtil.getCurrentEditor(e);
|
||||
|
||||
WorkspaceManager
|
||||
.getOrCreateBufferTask(ActionUtil.getCurrentProject(e))
|
||||
.registerListener(bufferHandler, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
String buffer = Messages.showInputDialog(
|
||||
"Buffer name:",
|
||||
"Attach to CodeMP Buffer",
|
||||
Messages.getQuestionIcon());
|
||||
try {
|
||||
attach(e, buffer, false);
|
||||
} catch(Exception ex) {
|
||||
ActionUtil.notifyError(e, String.format(
|
||||
"Failed to attach to buffer %s!",
|
||||
buffer), ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.codemp.intellij.actions.buffer;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.util.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BufferCreateAction extends AnAction {
|
||||
public static void create(AnActionEvent e, String buffer, boolean silent) {
|
||||
CodeMPHandler.create(buffer);
|
||||
if(!silent) ActionUtil.notify(e, "Success",
|
||||
String.format("Created buffer %s!", buffer)
|
||||
);
|
||||
CodeMP.LOGGER.debug("Created buffer {}!", buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
String buffer = Messages.showInputDialog(
|
||||
"Buffer name:",
|
||||
"Create CodeMP Buffer",
|
||||
Messages.getQuestionIcon());
|
||||
|
||||
try {
|
||||
create(e, buffer, false);
|
||||
} catch(Exception ex) {
|
||||
ActionUtil.notifyError(e, String.format(
|
||||
"Failed to create buffer with name %s!",
|
||||
buffer), ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.codemp.intellij.actions.buffer;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.util.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BufferCreateWithContentAction extends AnAction {
|
||||
|
||||
public static void createWithContent(AnActionEvent event, String buffer, boolean silent) {
|
||||
String content = ActionUtil.getCurrentEditor(event).getDocument().getText();
|
||||
CodeMPHandler.createWithContent(buffer, content);
|
||||
|
||||
if(!silent) ActionUtil.notify(event, "Success", String.format(
|
||||
"Created buffer %s with content %s!", buffer, content));
|
||||
CodeMP.LOGGER.debug("Created buffer {} with content {}!", buffer, content);
|
||||
}
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
String buffer = Messages.showInputDialog(
|
||||
"Buffer name:",
|
||||
"Create CodeMP Buffer with Content",
|
||||
Messages.getQuestionIcon());
|
||||
|
||||
try {
|
||||
createWithContent(e, buffer, false);
|
||||
} catch(Exception ex) {
|
||||
ActionUtil.notifyError(e, String.format(
|
||||
"Failed to create buffer with name %s!",
|
||||
buffer), ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package com.codemp.intellij.actions.buffer;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.exceptions.ide.BufferDetachException;
|
||||
import com.codemp.intellij.task.BufferEventAwaiterTask;
|
||||
import com.codemp.intellij.util.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BufferDetachAction extends AnAction {
|
||||
public static void detach(AnActionEvent e, String buffer, boolean silent) {
|
||||
boolean res = CodeMPHandler.detach(buffer);
|
||||
if(!res) throw new BufferDetachException(buffer);
|
||||
|
||||
CodeMP.ACTIVE_BUFFERS.remove(buffer);
|
||||
if(task != null) {
|
||||
task.unregisterListener(buffer);
|
||||
if(!silent) ActionUtil.notify(e, "Success",
|
||||
String.format("Detached from buffer %s!", buffer)
|
||||
);
|
||||
CodeMP.LOGGER.debug("Detached from buffer {}!", buffer);
|
||||
} else {
|
||||
if(!silent) ActionUtil.notifyError(e, String.format("Failed to detach from %s", buffer),
|
||||
"Buffer event task was dead!");
|
||||
CodeMP.LOGGER.debug("Failed to detach from {}: buffer event task was dead!", buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
String buffer = Messages.showInputDialog(
|
||||
"Buffer name:",
|
||||
"Detach from CodeMP Buffer",
|
||||
Messages.getQuestionIcon());
|
||||
|
||||
try {
|
||||
detach(e, buffer, false);
|
||||
} catch(Exception ex) {
|
||||
ActionUtil.notifyError(e, String.format(
|
||||
"Failed to detach from buffer with name %s!",
|
||||
buffer), ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.codemp.intellij.actions.buffer;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.util.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BufferSyncAction extends AnAction {
|
||||
public static void sync(AnActionEvent e, String bufferName, boolean silent) {
|
||||
Editor editor = ActionUtil.getCurrentEditor(e);
|
||||
ApplicationManager.getApplication().runWriteAction(() ->
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
editor.getProject(),
|
||||
() -> editor.getDocument().setText(CodeMPHandler.getBuffer(bufferName).getContent()),
|
||||
"CodeMPBufferSync",
|
||||
"codemp-buffer-sync",
|
||||
editor.getDocument()
|
||||
));
|
||||
|
||||
if(!silent) ActionUtil.notify(e,
|
||||
String.format("Synced buffer %s", bufferName),
|
||||
"The buffer was synced successfully.");
|
||||
CodeMP.LOGGER.debug("The buffer {} was synced successfully.", bufferName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
Editor editor = ActionUtil.getCurrentEditor(e);
|
||||
String bufferName = CodeMP.ACTIVE_BUFFERS_REVERSE.get(editor);
|
||||
try {
|
||||
sync(e, bufferName, false);
|
||||
} catch(Exception ex) {
|
||||
ActionUtil.notifyError(e, String.format(
|
||||
"Failed to attach to buffer %s!",
|
||||
bufferName), ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,6 @@ public class WorkspaceJoinAction extends AnAction {
|
|||
if(!silent) ActionUtil.notify(e,
|
||||
"Success", String.format("Joined workspace %s!", workspaceId));
|
||||
CodeMP.LOGGER.debug("Joined workspace {}!", workspaceId);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.codemp.intellij.actions.workspace;
|
|||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.util.ActionUtil;
|
||||
import com.codemp.intellij.workspace.Workspace;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
|
|
|
@ -2,15 +2,12 @@ package com.codemp.intellij.listeners;
|
|||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.jni.CursorHandler;
|
||||
import com.codemp.intellij.task.CursorEventAwaiterTask;
|
||||
import com.codemp.intellij.util.FileUtil;
|
||||
import com.codemp.intellij.workspace.Workspace;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.VisualPosition;
|
||||
import com.intellij.openapi.editor.event.CaretEvent;
|
||||
import com.intellij.openapi.editor.event.CaretListener;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CursorEventListener implements CaretListener {
|
||||
|
|
|
@ -3,14 +3,9 @@ package com.codemp.intellij.listeners;
|
|||
import com.codemp.intellij.jni.WorkspaceHandler;
|
||||
import com.codemp.intellij.task.BufferEventAwaiterTask;
|
||||
import com.codemp.intellij.util.FileUtil;
|
||||
import com.codemp.intellij.workspace.Workspace;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
|
||||
import com.intellij.openapi.fileEditor.TextEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.codemp.intellij.listeners;
|
||||
|
||||
import com.codemp.intellij.exceptions.lib.TransportException;
|
||||
import com.codemp.intellij.jni.BufferHandler;
|
||||
import com.codemp.intellij.jni.WorkspaceHandler;
|
||||
import com.codemp.intellij.task.BufferEventAwaiterTask;
|
||||
|
@ -39,7 +40,7 @@ public class WorkspaceFileOpenedListener implements FileOpenedSyncListener {
|
|||
String path = FileUtil.getRelativePath(editor.getProject(), file);
|
||||
if(path == null) return;
|
||||
|
||||
BufferHandler bufferHandler = this.handler.attachToBuffer(path);
|
||||
BufferHandler bufferHandler = this.getBufferForPath(path);
|
||||
Disposable disp = Disposer.newDisposable(String.format("codemp-buffer-%s", path));
|
||||
editor.getDocument().addDocumentListener(new BufferEventListener(bufferHandler), disp);
|
||||
|
||||
|
@ -47,4 +48,17 @@ public class WorkspaceFileOpenedListener implements FileOpenedSyncListener {
|
|||
this.task.activeBuffers.put(path, disp);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach to a buffer or, if it does not exist, implicitly create it.
|
||||
* @param path the buffer's name (which is the path relative to project root)
|
||||
* @return the {@link BufferHandler} for it
|
||||
*/
|
||||
private BufferHandler getBufferForPath(String path) {
|
||||
try {
|
||||
return this.handler.attachToBuffer(path);
|
||||
} catch (TransportException ignored) {
|
||||
return this.handler.createBuffer(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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.StringVec;
|
||||
|
@ -15,10 +14,12 @@ import com.intellij.openapi.editor.Editor;
|
|||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class BufferEventAwaiterTask extends Task.Backgroundable implements Disposable {
|
||||
|
@ -33,51 +34,47 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
|
|||
@Override
|
||||
@SuppressWarnings("InfiniteLoopStatement")
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
try {
|
||||
while(true) {
|
||||
StringVec buffers = new StringVec(); //jni moment
|
||||
this.activeBuffers.keySet().forEach(buffers::push);
|
||||
|
||||
Optional<BufferHandler> bufferOptional = this.handler.selectBuffer(buffers, 100L);
|
||||
if(bufferOptional.isEmpty())
|
||||
continue;
|
||||
BufferHandler buffer = bufferOptional.get();
|
||||
|
||||
List<TextChangeWrapper> changeList = new ArrayList<>();
|
||||
while(true) {
|
||||
StringVec buffers = new StringVec(); //jni moment
|
||||
this.activeBuffers.keySet().forEach(buffers::push);
|
||||
|
||||
Optional<BufferHandler> bufferOptional = this.handler.selectBuffer(buffers, 100L);
|
||||
if(bufferOptional.isEmpty())
|
||||
Optional<TextChangeWrapper> changeOptional;
|
||||
try {
|
||||
changeOptional = buffer.tryRecv();
|
||||
} catch(DeadlockedException e) {
|
||||
CodeMP.LOGGER.error(e.getMessage());
|
||||
continue;
|
||||
BufferHandler buffer = bufferOptional.get();
|
||||
|
||||
List<TextChangeWrapper> changeList = new ArrayList<>();
|
||||
while(true) {
|
||||
Optional<TextChangeWrapper> changeOptional;
|
||||
try {
|
||||
changeOptional = buffer.tryRecv();
|
||||
} catch(DeadlockedException e) {
|
||||
CodeMP.LOGGER.error(e.getMessage());
|
||||
continue;
|
||||
}
|
||||
if(changeOptional.isEmpty())
|
||||
break;
|
||||
TextChangeWrapper change = changeOptional.get();
|
||||
CodeMP.LOGGER.debug("Received text change {} from offset {} to {}!",
|
||||
change.getContent(), change.getStart(), change.getEnd());
|
||||
changeList.add(change);
|
||||
}
|
||||
|
||||
Editor bufferEditor = FileUtil.getActiveEditorByPath(this.myProject, buffer.getName());
|
||||
ApplicationManager.getApplication().invokeLaterOnWriteThread(() ->
|
||||
ApplicationManager.getApplication().runWriteAction(() ->
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
this.myProject,
|
||||
() -> changeList.forEach((change) ->
|
||||
bufferEditor.getDocument().replaceString(
|
||||
(int) change.getStart(), (int) change.getEnd(), change.getContent())
|
||||
),
|
||||
"CodeMPBufferReceive",
|
||||
"codemp-buffer-receive", //TODO: mark this with the name
|
||||
bufferEditor.getDocument()
|
||||
)));
|
||||
if(changeOptional.isEmpty())
|
||||
break;
|
||||
TextChangeWrapper change = changeOptional.get();
|
||||
CodeMP.LOGGER.debug("Received text change {} from offset {} to {}!",
|
||||
change.getContent(), change.getStart(), change.getEnd());
|
||||
changeList.add(change);
|
||||
}
|
||||
|
||||
Editor bufferEditor = FileUtil.getActiveEditorByPath(this.myProject, buffer.getName());
|
||||
ApplicationManager.getApplication().invokeLaterOnWriteThread(() ->
|
||||
ApplicationManager.getApplication().runWriteAction(() ->
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
this.myProject,
|
||||
() -> changeList.forEach((change) ->
|
||||
bufferEditor.getDocument().replaceString(
|
||||
(int) change.getStart(), (int) change.getEnd(), change.getContent())
|
||||
),
|
||||
"CodeMPBufferReceive",
|
||||
"codemp-buffer-receive", //TODO: mark this with the name
|
||||
bufferEditor.getDocument()
|
||||
)));
|
||||
}
|
||||
} catch(ChannelException ex) { //exited
|
||||
//TODO handle stop
|
||||
Disposer.dispose(this); //stopped
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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;
|
||||
|
@ -9,6 +8,7 @@ import com.codemp.intellij.util.FileUtil;
|
|||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.markup.HighlighterLayer;
|
||||
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
|
@ -36,62 +36,58 @@ public class CursorEventAwaiterTask extends Task.Backgroundable implements Dispo
|
|||
@Override
|
||||
@SuppressWarnings("InfiniteLoopStatement")
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
try {
|
||||
while(true) {
|
||||
CursorEventWrapper event = this.handler.recv();
|
||||
Editor editor = FileUtil.getActiveEditorByPath(this.myProject, event.getBuffer());
|
||||
if(editor == null)
|
||||
continue;
|
||||
while(true) {
|
||||
CursorEventWrapper event = this.handler.recv();
|
||||
Editor editor = FileUtil.getActiveEditorByPath(this.myProject, event.getBuffer());
|
||||
if(editor == null)
|
||||
continue;
|
||||
|
||||
CodeMP.LOGGER.debug(
|
||||
"Cursor moved by user {}! Start pos: {}x {}y; end pos: {}x {}y in buffer {}!",
|
||||
event.getUser(),
|
||||
event.getStartCol(), event.getStartCol(),
|
||||
event.getEndRow(), event.getEndCol(),
|
||||
event.getBuffer());
|
||||
CodeMP.LOGGER.debug(
|
||||
"Cursor moved by user {}! Start pos: {}x {}y; end pos: {}x {}y in buffer {}!",
|
||||
event.getUser(),
|
||||
event.getStartCol(), event.getStartCol(),
|
||||
event.getEndRow(), event.getEndCol(),
|
||||
event.getBuffer());
|
||||
|
||||
try {
|
||||
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(() -> {
|
||||
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(() -> {
|
||||
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 previous = this.highlighterMap.put(event.getUser(), editor
|
||||
.getMarkupModel()
|
||||
.addRangeHighlighter(
|
||||
startOffset,
|
||||
endOffset,
|
||||
HighlighterLayer.SELECTION,
|
||||
new TextAttributes(
|
||||
null,
|
||||
ColorUtil.hashColor(event.getUser()),
|
||||
null,
|
||||
null,
|
||||
Font.PLAIN
|
||||
), HighlighterTargetArea.EXACT_RANGE
|
||||
));
|
||||
RangeHighlighter previous = this.highlighterMap.put(event.getUser(), editor
|
||||
.getMarkupModel()
|
||||
.addRangeHighlighter(
|
||||
startOffset,
|
||||
endOffset,
|
||||
HighlighterLayer.SELECTION,
|
||||
new TextAttributes(
|
||||
null,
|
||||
ColorUtil.hashColor(event.getUser()),
|
||||
null,
|
||||
null,
|
||||
Font.PLAIN
|
||||
), HighlighterTargetArea.EXACT_RANGE
|
||||
));
|
||||
|
||||
if(previous != null)
|
||||
previous.dispose();
|
||||
});
|
||||
} catch(IndexOutOfBoundsException ignored) {}
|
||||
}
|
||||
} catch(ChannelException ex) { //exited
|
||||
this.run(indicator);
|
||||
if(previous != null)
|
||||
previous.dispose();
|
||||
});
|
||||
} catch(IndexOutOfBoundsException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
this.highlighterMap.forEach((s, r) -> r.dispose());
|
||||
this.highlighterMap.values().forEach(RangeMarker::dispose);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,26 +13,10 @@
|
|||
<action id="codemp.fast-forward" class="com.codemp.intellij.actions.FastForwardAction" text="Just Hurry"/>
|
||||
<action id="codemp.connect" class="com.codemp.intellij.actions.ConnectAction" text="Connect..."/>
|
||||
<action id="codemp.connect" class="com.codemp.intellij.actions.DisconnectAction" text="Disconnect"/>
|
||||
|
||||
<group id="codemp.workspace" text="Workspace" popup="true">
|
||||
<action id="codemp.workspace.join" class="com.codemp.intellij.actions.workspace.WorkspaceJoinAction"
|
||||
text="Join Workspace"/>
|
||||
<action id="codemp.workspace.leave" class="com.codemp.intellij.actions.workspace.WorkspaceLeaveAction"
|
||||
text="Leave Workspace"/>
|
||||
</group>
|
||||
<group id="codemp.buffer" text="Buffer" popup="true">
|
||||
<action id="codemp.buffer.create" class="com.codemp.intellij.actions.buffer.BufferCreateAction"
|
||||
text="Create Buffer"/>
|
||||
<action id="codemp.buffer.create-with-content"
|
||||
class="com.codemp.intellij.actions.buffer.BufferCreateWithContentAction"
|
||||
text="Create Buffer with Content"/>
|
||||
<action id="codemp.buffer.attach" class="com.codemp.intellij.actions.buffer.BufferAttachAction"
|
||||
text="Attach to Buffer"/>
|
||||
<action id="codemp.buffer.sync" class="com.codemp.intellij.actions.buffer.BufferSyncAction"
|
||||
text="Force Sync Buffer"/>
|
||||
<action id="codemp.buffer.detach" class="com.codemp.intellij.actions.buffer.BufferDetachAction"
|
||||
text="Detach from Buffer"/>
|
||||
</group>
|
||||
<action id="codemp.workspace.join" class="com.codemp.intellij.actions.workspace.WorkspaceJoinAction"
|
||||
text="Join Workspace"/>
|
||||
<action id="codemp.workspace.leave" class="com.codemp.intellij.actions.workspace.WorkspaceLeaveAction"
|
||||
text="Leave Workspace"/>
|
||||
</group>
|
||||
</actions>
|
||||
|
||||
|
|
|
@ -76,9 +76,9 @@ impl WorkspaceHandler {
|
|||
|
||||
#[generate_interface]
|
||||
/// create a new buffer in current workspace
|
||||
fn create_buffer(&mut self, path: &str) -> CodempResult<Option<BufferHandler>> {
|
||||
fn create_buffer(&mut self, path: &str) -> CodempResult<BufferHandler> {
|
||||
RT.block_on(RT.block_on(self.workspace.write()).create(path))?;
|
||||
Ok(self.get_buffer(path))
|
||||
Ok(self.get_buffer(path).unwrap())
|
||||
}
|
||||
|
||||
#[generate_interface]
|
||||
|
@ -144,7 +144,7 @@ impl WorkspaceHandler {
|
|||
/// get a [crate::BufferHandler] for one of the workspace's buffers
|
||||
fn get_buffer(&self, path: &str) -> Option<BufferHandler> {
|
||||
RT.block_on(self.workspace.read()).buffer_by_name(path)
|
||||
.map(|b| BufferHandler { buffer: b })
|
||||
.map(|buffer| BufferHandler { buffer })
|
||||
}
|
||||
|
||||
#[generate_interface]
|
||||
|
|
Loading…
Reference in a new issue