mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[ui] Preserve caret position after editing VM options
IJ-CR-140588 GitOrigin-RevId: 71e1e207624f2cb79e3034519acf72db31325d05
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2b3e137700
commit
432e4e1019
@@ -4,6 +4,8 @@ package com.intellij.execution.ui;
|
||||
import com.intellij.execution.ExecutionBundle;
|
||||
import com.intellij.execution.JavaRunConfigurationBase;
|
||||
import com.intellij.openapi.editor.SpellCheckingEditorCustomizationProvider;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
import com.intellij.openapi.editor.event.DocumentListener;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.ui.*;
|
||||
@@ -12,6 +14,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.intellij.execution.ui.CommandLinePanel.setMinimumWidth;
|
||||
@@ -21,6 +25,8 @@ public class VmOptionsEditor extends JPanel implements FragmentWrapper, Expandab
|
||||
private final LanguageTextField myEditor;
|
||||
private LanguageTextField myPopupEditor;
|
||||
private final ExpandableEditorSupport mySupport;
|
||||
private boolean myFocused = false;
|
||||
private boolean myEdited = false;
|
||||
|
||||
VmOptionsEditor(JavaRunConfigurationBase settings) {
|
||||
super(new BorderLayout());
|
||||
@@ -29,6 +35,7 @@ public class VmOptionsEditor extends JPanel implements FragmentWrapper, Expandab
|
||||
myEditor.getAccessibleContext().setAccessibleName(message);
|
||||
myEditor.setPlaceholder(message);
|
||||
setupEditor(myEditor, settings);
|
||||
trackUserEdits();
|
||||
add(myEditor, BorderLayout.CENTER);
|
||||
setMinimumWidth(this, 400);
|
||||
mySupport = new ExpandableEditorSupport(myEditor, ParametersListUtil.DEFAULT_LINE_PARSER, ParametersListUtil.DEFAULT_LINE_JOINER) {
|
||||
@@ -36,13 +43,30 @@ public class VmOptionsEditor extends JPanel implements FragmentWrapper, Expandab
|
||||
protected @NotNull EditorTextField createPopupEditor(@NotNull EditorTextField field, @NotNull String text) {
|
||||
LanguageTextField popupEditor = new LanguageTextField(FileTypes.PLAIN_TEXT.getLanguage(), settings.getProject(), text);
|
||||
setupEditor(popupEditor, settings);
|
||||
popupEditor.setCaretPosition(0);
|
||||
if (!myEdited) {
|
||||
popupEditor.setCaretPosition(0);
|
||||
}
|
||||
myPopupEditor = popupEditor;
|
||||
return popupEditor;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void trackUserEdits() {
|
||||
myEditor.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
myFocused = true;
|
||||
}
|
||||
});
|
||||
myEditor.addDocumentListener(new DocumentListener() {
|
||||
@Override
|
||||
public void documentChanged(@NotNull DocumentEvent event) {
|
||||
if (myFocused) myEdited = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setupEditor(LanguageTextField popupEditor, JavaRunConfigurationBase settings) {
|
||||
CommonParameterFragments.setMonospaced(popupEditor);
|
||||
EditorCustomization disableSpellChecking = SpellCheckingEditorCustomizationProvider.getInstance().getDisabledCustomization();
|
||||
|
||||
Reference in New Issue
Block a user