]> git.neil.brown.name Git - edlib.git/commitdiff
mergeview: capture < and > on marker lines.
authorNeilBrown <neil@brown.name>
Mon, 12 Jun 2023 11:46:01 +0000 (21:46 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 07:51:41 +0000 (17:51 +1000)
When cursor is on a marker line, capture < and > for manipulating the
merge.

On the first marker: lines are moved between top of orig and preceding
content.
On the second marker: lines are moved between bottom of orig and
following content.

I don't know what I want on other marker lines.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
python/lib-mergeview.py

index 69c02af71e6aa63148d1a5ac8ad1b1db979c67b4..3f90746a33a7b49e80ff54c230c18aef2b20495d 100644 (file)
@@ -237,8 +237,9 @@ Module features
           space-conflicts: bold blue
           conflicts: red
           in text, space conflicts get underline, no inverse
-- [ ] Capture '-<' and '->' on the marker lines to move the orig section
+- [X] Capture '-<' and '->' on the marker lines to move the orig section
       w.r.t surrounding text, or to prune the before and after sections.
+- [ ] Consider what else can be done with < and > on other markers.
 - [ ] Capture :CX:C-x command to cycle through matching places in the
       three branches.
 - [ ] merge-mode automatic detect, enable, goto-first
index 507c3c465fae8351b639135d90c750bc98aacca8..75ab6f358eb7d7fccae28ff4d871046f4b071529 100644 (file)
@@ -213,6 +213,87 @@ class MergePane(edlib.Pane):
             mark.to_mark(m3)
         return 1
 
+    def handle_shift(self, key, focus, num, mark, **a):
+        "handle-list/K-</K->"
+        if not self.marks:
+            return edlib.Efallthrough
+        m = mark.dup()
+        focus.call("doc:EOL", m, -1)
+        if m == self.marks[0]:
+            if key[-1] == '<':
+                # Move one line from before the header to after.
+                m2 = m.dup()
+                focus.call("doc:EOL", m2, -2)
+                if m2 == m:
+                    # Nothing to move
+                    return 1
+                txt = focus.call("doc:get-str", m2, m, ret='str')
+                if txt.startswith(">>>>>>>"):
+                    # We've run into another chunk - stop
+                    return 1
+                m3 = mark.dup()
+                focus.call("doc:EOL", m3, 1, 1)
+                focus.call("doc:replace", m3, m3, txt)
+                focus.call("doc:replace", m2, m, 0, 1)
+                return 1
+            else:
+                # Move one line from after the header to before
+                m2 = mark.dup()
+                focus.call("doc:EOL", m2, 1, 1)
+                m3 = m2.dup()
+                focus.call("doc:EOL", m3, 1, 1)
+                if m3 == m2:
+                    return 1
+                txt = focus.call("doc:get-str", m2, m3, ret='str')
+                if txt.startswith("|||||||"):
+                    # Nothing here
+                    return 1
+                m.step(0)
+                focus.call("doc:replace", m, m, txt)
+                focus.call("doc:replace", m2, m3, 0, 1)
+                return 1
+            return 1;
+        if m == self.marks[1]:
+            if key[-1] == '<':
+                # Move one line from before marker to after end
+                m2 = m.dup()
+                focus.call("doc:EOL", m2, -2)
+                if m2 == m:
+                    # Nothing to move
+                    return 1
+                txt = focus.call("doc:get-str", m2, m, ret='str')
+                if txt.startswith("<<<<<<<"):
+                    # We've run out of orig
+                    return 1
+                m3 = self.marks[3].dup()
+                focus.call("doc:EOL", m3, 1, 1)
+                focus.call("doc:replace", m3, m3, txt)
+                focus.call("doc:replace", m2, m, 0, 1)
+                return 1
+            else:
+                # Move one line from after end marker to before
+                m2 = self.marks[3].dup()
+                focus.call("doc:EOL", m2, 1, 1)
+                m3 = m2.dup()
+                focus.call("doc:EOL", m3, 1, 1)
+                if m3 == m2:
+                    return 1
+                txt = focus.call("doc:get-str", m2, m3, ret='str')
+                if txt.startswith("<<<<<<<"):
+                    # Run into next chunk
+                    return 1
+                m.step(0)
+                focus.call("doc:replace", m, m, txt)
+                focus.call("doc:replace", m2, m3, 0, 1)
+                return 1
+            return 1;
+        if m == self.marks[2]:
+            # I don't know what, if anything, I want here.
+            return 1;
+        if m == self.marks[3]:
+            return 1;
+        return edlib.Efallthrough
+
     def remark(self, key, **a):
         if self.marks:
             m = self.marks[3].dup()