diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-08-08 22:21:44 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-08-22 09:30:37 +0200 |
commit | b12dd9f9263f7c2cf2f91bc3f6f5549ee0165cb1 (patch) | |
tree | 4282bcf41ee7ecbaa96aaa4c03a438e5f00e97da /lib/marker | |
parent | 16dbb9422120a2f229524f1cbee55f09e455b1d7 (diff) | |
download | aerc-b12dd9f9263f7c2cf2f91bc3f6f5549ee0165cb1.tar.gz |
mark: allow multiple visual selections
When entering visual selection mode, the current selection is deleted.
This patch extends the visual mode behavior to select multiple blocks of
messages.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/marker')
-rw-r--r-- | lib/marker/marker.go | 18 | ||||
-rw-r--r-- | lib/marker/marker_test.go | 2 |
2 files changed, 15 insertions, 5 deletions
diff --git a/lib/marker/marker.go b/lib/marker/marker.go index 46400f1a..21c151f3 100644 --- a/lib/marker/marker.go +++ b/lib/marker/marker.go @@ -8,7 +8,7 @@ type Marker interface { Remark() Marked() []uint32 IsMarked(uint32) bool - ToggleVisualMark() + ToggleVisualMark(bool) UpdateVisualMark() ClearVisualMark() } @@ -25,6 +25,7 @@ type controller struct { lastMarked map[uint32]struct{} visualStartUID uint32 visualMarkMode bool + visualBase map[uint32]struct{} } // New returns a new Marker @@ -114,15 +115,21 @@ func (mc *controller) Marked() []uint32 { } // ToggleVisualMark enters or leaves the visual marking mode -func (mc *controller) ToggleVisualMark() { +func (mc *controller) ToggleVisualMark(clear bool) { mc.visualMarkMode = !mc.visualMarkMode if mc.visualMarkMode { // just entered visual mode, reset whatever marking was already done - mc.resetMark() + if clear { + mc.resetMark() + } uids := mc.uidProvider.Uids() if idx := mc.uidProvider.SelectedIndex(); idx >= 0 && idx < len(uids) { mc.visualStartUID = uids[idx] mc.marked[mc.visualStartUID] = struct{}{} + mc.visualBase = make(map[uint32]struct{}) + for key, value := range mc.marked { + mc.visualBase[key] = value + } } } } @@ -160,7 +167,10 @@ func (mc *controller) UpdateVisualMark() { } else { visUids = uids[selectedIdx : startIdx+1] } - mc.resetMark() + mc.marked = make(map[uint32]struct{}) + for uid := range mc.visualBase { + mc.marked[uid] = struct{}{} + } for _, uid := range visUids { mc.marked[uid] = struct{}{} } diff --git a/lib/marker/marker_test.go b/lib/marker/marker_test.go index 1611623e..df9eb2a3 100644 --- a/lib/marker/marker_test.go +++ b/lib/marker/marker_test.go @@ -90,7 +90,7 @@ func TestMarker_VisualMode(t *testing.T) { m, up := createMarker() // activate visual mode - m.ToggleVisualMark() + m.ToggleVisualMark(false) // marking should now fail silently because we're in visual mode m.Mark(1) |