From a47b893dcaefab4f8fa3405e51a935b95f93d64b Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Tue, 15 Sep 2015 19:20:52 +0300 Subject: [PATCH] don't always use LTR base direction for bidirectional text layout, autodetect direction as per Unicode standard (following bug report at https://code.google.com/p/android/issues/detail?id=182739#c13) --- .../openapi/editor/impl/view/LineLayout.java | 2 +- .../openapi/editor/impl/EditorRtlTest.java | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/LineLayout.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/LineLayout.java index 78138c956ef0..021963c1599b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/LineLayout.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/LineLayout.java @@ -150,7 +150,7 @@ class LineLayout { private static void addRuns(List runs, char[] text, int start, int end) { if (start >= end) return; - Bidi bidi = new Bidi(text, start, null, 0, end - start, Bidi.DIRECTION_LEFT_TO_RIGHT); + Bidi bidi = new Bidi(text, start, null, 0, end - start, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); int runCount = bidi.getRunCount(); for (int i = 0; i < runCount; i++) { addOrMergeRun(runs, new BidiRun((byte)bidi.getRunLevel(i), start + bidi.getRunStart(i), start + bidi.getRunLimit(i))); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java index bbe2de51f912..d55f36c1e9a6 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java @@ -40,8 +40,12 @@ public class EditorRtlTest extends AbstractEditorTest { @Override protected void tearDown() throws Exception { - super.tearDown(); - Registry.get("editor.new.rendering").setValue(false); + try { + Registry.get("editor.new.rendering").setValue(false); + } + finally { + super.tearDown(); + } } public void testPositionCalculations() throws IOException { @@ -499,12 +503,12 @@ public class EditorRtlTest extends AbstractEditorTest { } public void testJavadocTokensAreMergedForBidiLayoutPurposes() throws Exception { - prepare("/** R R */ class Foo {}", TestFileType.JAVA); - for (int i = 0; i < 5; i++) { + prepare("/**R R*/ class Foo {}", TestFileType.JAVA); + for (int i = 0; i < 4; i++) { right(); } - checkResult("/** R R */ class Foo {}"); + checkResult("/**R R*/ class Foo {}"); } public void testXmlTextIsLaidOutCorrectly() throws Exception { @@ -553,6 +557,12 @@ public class EditorRtlTest extends AbstractEditorTest { assertVisualCaretLocation(1, 3, true); } + public void testLineGeneralDirectionAutodetection() throws Exception { + prepareText("RLR"); + right(); + checkResult("RLR"); + } + private void prepareText(String text) throws IOException { prepare(text, TestFileType.TEXT); }