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

Fix null reference initialising output panel fonts #925

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions src/main/java/com/maddyhome/idea/vim/ex/ExOutputModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,8 @@ class ExOutputModel private constructor(private val myEditor: Editor) : VimExOut
}
return model
}

@JvmStatic
fun tryGetInstance(editor: Editor) = editor.vimExOutput
}
}
5 changes: 4 additions & 1 deletion src/main/java/com/maddyhome/idea/vim/group/EditorGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ public void propertyChange(PropertyChangeEvent evt) {
if (activeCommandLine != null) {
injector.getProcessGroup().cancelExEntry(new IjVimEditor(editor), false);
}
ExOutputModel.getInstance(editor).close();
ExOutputModel exOutputModel = ExOutputModel.tryGetInstance(editor);
if (exOutputModel != null) {
exOutputModel.close();
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/maddyhome/idea/vim/group/MotionGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ internal class MotionGroup : VimMotionGroupBase() {
}
is Mode.CMD_LINE -> {
injector.processGroup.cancelExEntry(vimEditor, false)
ExOutputModel.getInstance(editor).close()
ExOutputModel.tryGetInstance(editor)?.close()
}
else -> {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ internal object VimListenerManager {
injector.processGroup.cancelExEntry(editor.vim, false)
}

ExOutputModel.getInstance(editor).close()
ExOutputModel.tryGetInstance(editor)?.close()

val caretModel = editor.caretModel
if (editor.vim.mode.selectionType != null) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/maddyhome/idea/vim/ui/ExOutputPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ private void scrollOffset(int more) {
private void positionPanel() {
final JComponent contentComponent = myEditor.getContentComponent();
Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, contentComponent);
JRootPane rootPane = SwingUtilities.getRootPane(contentComponent);
if (scroll == null || rootPane == null) {
// These might be null if we're invoked during component initialisation and before it's been added to the tree
return;
}

setSize(scroll.getSize());

myLineHeight = myText.getFontMetrics(myText.getFont()).getHeight();
Expand All @@ -280,8 +286,7 @@ private void positionPanel() {
Rectangle bounds = scroll.getBounds();
bounds.translate(0, scroll.getHeight() - height);
bounds.height = height;
Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(),
SwingUtilities.getRootPane(contentComponent).getGlassPane());
Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), rootPane.getGlassPane());
bounds.setLocation(pos);
setBounds(bounds);

Expand Down
Loading