Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fleet #897

Merged
merged 22 commits into from
Jun 5, 2024
Merged

Fleet #897

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/maddyhome/idea/vim/VimProjectService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.maddyhome.idea.vim.group.EditorHolderService
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel

@Service(Service.Level.PROJECT)
internal class VimProjectService(val project: Project) : Disposable {
override fun dispose() {
// Not sure if this is a best solution
EditorHolderService.getInstance().editor = null
ExEntryPanel.getInstance().editor = null
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.globalOptions
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.group.EditorHolderService
import com.maddyhome.idea.vim.group.IjOptionConstants
import com.maddyhome.idea.vim.group.IjOptions
import com.maddyhome.idea.vim.handler.enableOctopus
Expand All @@ -45,6 +44,7 @@ import com.maddyhome.idea.vim.listener.AceJumpService
import com.maddyhome.idea.vim.listener.AppCodeTemplates.appCodeTemplateCaptured
import com.maddyhome.idea.vim.newapi.globalIjOptions
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
import com.maddyhome.idea.vim.ui.ex.ExTextField
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
import java.awt.event.InputEvent
Expand Down Expand Up @@ -257,7 +257,7 @@ public class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible
private fun getEditor(e: AnActionEvent): Editor? {
return e.getData(PlatformDataKeys.EDITOR)
?: if (e.getData(PlatformDataKeys.CONTEXT_COMPONENT) is ExTextField) {
EditorHolderService.getInstance().editor
ExEntryPanel.getInstance().editor
} else {
null
}
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/com/maddyhome/idea/vim/group/EditorHolderService.kt

This file was deleted.

14 changes: 14 additions & 0 deletions src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.lang.ref.WeakReference;

import static com.maddyhome.idea.vim.api.VimInjectorKt.globalOptions;
import static com.maddyhome.idea.vim.api.VimInjectorKt.injector;
Expand All @@ -60,6 +61,7 @@ public class ExEntryPanel extends JPanel implements VimCommandLine {
public static ExEntryPanel instance;
public static ExEntryPanel instanceWithoutShortcuts;
private boolean isReplaceMode = false;
private WeakReference<Editor> weakEditor = null;

private ExEntryPanel(boolean enableShortcuts) {
label = new JLabel(" ");
Expand Down Expand Up @@ -126,6 +128,18 @@ public static void fullReset() {
}
}

public @Nullable Editor getEditor() {
return weakEditor.get();
}

public void setEditor(@Nullable Editor editor) {
if (editor == null) {
weakEditor = null;
} else {
weakEditor = new WeakReference<>(editor);
}
}

/**
* Turns on the ex entry field for the given editor
*
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/maddyhome/idea/vim/ui/ex/ExTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.api.VimCommandLine;
import com.maddyhome.idea.vim.api.VimCommandLineCaret;
import com.maddyhome.idea.vim.group.EditorHolderService;
import com.maddyhome.idea.vim.helper.UiHelper;
import com.maddyhome.idea.vim.history.HistoryConstants;
import com.maddyhome.idea.vim.history.HistoryEntry;
Expand All @@ -25,7 +24,6 @@
import com.maddyhome.idea.vim.options.helpers.GuiCursorMode;
import com.maddyhome.idea.vim.options.helpers.GuiCursorOptionHelper;
import com.maddyhome.idea.vim.options.helpers.GuiCursorType;
import kotlin.text.StringsKt;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -83,7 +81,7 @@ void reset() {

void deactivate() {
clearCurrentAction();
EditorHolderService.getInstance().setEditor(null);
ExEntryPanel.getInstance().setEditor(null);
context = null;
}

Expand Down Expand Up @@ -209,11 +207,11 @@ private void setFontToJField(String stringToDisplay) {

void setEditor(@NotNull Editor editor, DataContext context) {
this.context = context;
EditorHolderService.getInstance().setEditor(editor);
ExEntryPanel.getInstance().setEditor(editor);
}

public Editor getEditor() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires @Nullable on return type now

return EditorHolderService.getInstance().getEditor();
return ExEntryPanel.getInstance().getEditor();
}

public DataContext getContext() {
Expand Down Expand Up @@ -293,7 +291,7 @@ void escape() {
*/
void cancel() {
clearCurrentAction();
Editor editor = EditorHolderService.getInstance().getEditor();
Editor editor = ExEntryPanel.instance.getEditor();
if (editor != null) {
VimPlugin.getProcess().cancelExEntry(new IjVimEditor(editor), true);
}
Expand Down