From 12e50374c43dc356f9aa4db11a712ef61be3e2cd Mon Sep 17 00:00:00 2001 From: Vojtech Balik Date: Mon, 10 Aug 2026 17:09:33 +0200 Subject: [PATCH] IJPL-251582 IJPL-247496 [editor, markdown] add EditorCharacterGridSizeTest Partial cherry-pick of new tests for grid mode to resolve conflicts when cherry-picking tests for IJPL-247496 IJ-CR-217736 (cherry picked from commit 870d075ff879d5619e2c596784a4b726e354ce7a) GitOrigin-RevId: 5336f4aff35c14ed1aa77bc1f3c98ddb881724c3 --- .../impl/EditorCharacterGridSizeTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorCharacterGridSizeTest.java diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorCharacterGridSizeTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorCharacterGridSizeTest.java new file mode 100644 index 000000000000..161352614f91 --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorCharacterGridSizeTest.java @@ -0,0 +1,40 @@ +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.openapi.editor.impl; + +import com.intellij.openapi.editor.ex.EditorEx; + +public class EditorCharacterGridSizeTest extends AbstractEditorTest { + private static final String LONG_LINE = "x".repeat(200); + private static final int CONTENT_WIDTH = LONG_LINE.length() * TEST_CHAR_WIDTH; + + private void enableGridMode() { + getEditor().getSettings().setCharacterGridWidthMultiplier(1.0f); + ((EditorEx)getEditor()).reinitSettings(); + assertNotNull(((EditorImpl)getEditor()).getCharacterGrid()); + } + + private int preferredWidth() { + return getEditor().getContentComponent().getPreferredSize().width; + } + + // IJPL-247496: non-wrapping grid editors (Markdown) must expose the full line width, not the viewport. + public void testNonWrappingGridEditorIsScrollableToTheEndOfLongLines() { + initText(LONG_LINE); + getEditor().getSettings().setAdditionalColumnsCount(0); + setEditorVisibleSize(20, 10); + enableGridMode(); + + assertTrue(getEditor().getScrollingModel().getVisibleArea().width < CONTENT_WIDTH); + assertTrue("preferred=" + preferredWidth(), preferredWidth() >= CONTENT_WIDTH); + } + + // IJPL-180831: soft-wrapping grid editors (terminal) still clamp preferred width to the viewport. + public void testWrappingGridEditorStaysClampedToViewport() { + initText(LONG_LINE); + getEditor().getSettings().setAdditionalColumnsCount(0); + configureSoftWraps(20); + enableGridMode(); + + assertTrue("preferred=" + preferredWidth(), preferredWidth() < CONTENT_WIDTH); + } +}