From 2fcce279de70ed80f2c682f16ca1151f0e0e3886 Mon Sep 17 00:00:00 2001
From: Moshe Wajnberg <wajnberg@il.ibm.com>
Date: Sun, 6 Aug 2017 16:31:26 +0300
Subject: [PATCH] Fix(bidi): Fix for bug /codemirror/CodeMirror/issues/4897

Fix for bug https://github.com/codemirror/CodeMirror/issues/4897
---
 demo/bidi.html     | 12 ++++++++++++
 lib/codemirror.css |  1 +
 2 files changed, 13 insertions(+)

diff --git a/demo/bidi.html b/demo/bidi.html
index ceaffd32..645e648c 100644
--- a/demo/bidi.html
+++ b/demo/bidi.html
@@ -60,6 +60,11 @@
     <input type="radio" id="ltr" name="direction"/><label for="ltr">LTR</label>
     <input type="radio" id="rtl" name="direction"/><label for="rtl">RTL</label>
   </fieldset>
+  <fieldset>
+    HTML document direction:
+    <input type="radio" id="htmlltr" name="htmldirection"/><label for="htmlltr">LTR</label>
+    <input type="radio" id="htmlrtl" name="htmldirection"/><label for="htmlrtl">RTL</label>
+  </fieldset>
   <fieldset>
     <input type="checkbox" id="rtlMoveVisually"/><label for="rtlMoveVisually">Use visual order for arrow key movement.</label>
   </fieldset>
@@ -80,6 +85,13 @@ dirRadios["rtl"].onchange = dirRadios["ltr"].onchange = function() {
   editor.setOption("direction", dirRadios["rtl"].checked ? "rtl" : "ltr");
 };
 
+var HtmlDirRadios = {ltr: document.getElementById("htmlltr"),
+                 rtl: document.getElementById("htmlrtl")};
+HtmlDirRadios["ltr"].checked = true;
+HtmlDirRadios["rtl"].onchange = HtmlDirRadios["ltr"].onchange = function() {
+  document.dir = (HtmlDirRadios["rtl"].checked ? "rtl" : "ltr");
+};
+
 var moveCheckbox = document.getElementById("rtlMoveVisually");
 moveCheckbox.checked = editor.getOption("rtlMoveVisually");
 moveCheckbox.onchange = function() {
diff --git a/lib/codemirror.css b/lib/codemirror.css
index f4d3c5f4..9d8ff0ce 100644
--- a/lib/codemirror.css
+++ b/lib/codemirror.css
@@ -5,6 +5,7 @@
   font-family: monospace;
   height: 300px;
   color: black;
+  direction: ltr;
 }
 
 /* PADDING */
-- 
GitLab