From: NeilBrown Date: Mon, 12 Jun 2023 11:46:01 +0000 (+1000) Subject: mergeview: capture < and > on marker lines. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=4289fd3a1f8b645ade6a3a225ac3aa30c6123b5e;p=edlib.git mergeview: capture < and > on marker lines. 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 --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 69c02af7..3f90746a 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -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 diff --git a/python/lib-mergeview.py b/python/lib-mergeview.py index 507c3c46..75ab6f35 100644 --- a/python/lib-mergeview.py +++ b/python/lib-mergeview.py @@ -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-" + 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()