From 1fae53703cf4099d4f4855ef18dd14d60514c82f Mon Sep 17 00:00:00 2001
From: Marijn Haverbeke <marijnh@gmail.com>
Date: Wed, 25 Nov 2015 15:58:52 +0100
Subject: [PATCH] When skipping atomic marks, only use near side when on same
 line

Which is kind of arbitrary but seems to give less surprising
results.

Issue #3658
---
 lib/codemirror.js | 6 +++---
 test/test.js      | 2 --
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/codemirror.js b/lib/codemirror.js
index 5a3c3fde..1d8b8cc7 100644
--- a/lib/codemirror.js
+++ b/lib/codemirror.js
@@ -2251,13 +2251,13 @@
         if (oldPos) {
           var near = m.find(dir < 0 ? 1 : -1), diff;
           if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft) near = movePos(doc, near, -dir, line);
-          if (near && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
-            return skipAtomicInner(doc, near, oldPos, dir, mayClear);
+          if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
+            return skipAtomicInner(doc, near, pos, dir, mayClear);
         }
 
         var far = m.find(dir < 0 ? -1 : 1);
         if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight) far = movePos(doc, far, dir, line);
-        return far ? skipAtomicInner(doc, far, oldPos, dir, mayClear) : null;
+        return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null;
       }
     }
     return pos;
diff --git a/test/test.js b/test/test.js
index 92052245..01efbce8 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1637,8 +1637,6 @@ testCM("atomicMarker", function(cm) {
   m = atom(1, 1, 3, 8);
   cm.setCursor(Pos(0, 0));
   cm.setCursor(Pos(2, 0));
-  eqPos(cm.getCursor(), Pos(1, 1));
-  cm.execCommand("goCharRight");
   eqPos(cm.getCursor(), Pos(3, 8));
   cm.execCommand("goCharLeft");
   eqPos(cm.getCursor(), Pos(1, 1));
-- 
GitLab