@@ -2,10 +2,11 @@ package ui
2
2
3
3
import (
4
4
"context"
5
- "github.com/darylhjd/mangadesk/app/ui/utils"
6
5
"log"
7
6
"math"
8
7
8
+ "github.com/darylhjd/mangadesk/app/ui/utils"
9
+
9
10
"github.com/darylhjd/mangodex"
10
11
"github.com/gdamore/tcell/v2"
11
12
"github.com/rivo/tview"
@@ -188,6 +189,12 @@ func (p *MangaPage) setHandlers(cancel context.CancelFunc) {
188
189
return event
189
190
})
190
191
192
+ p .Table .SetSelectionChangedFunc (func (row , _column int ) {
193
+ if p .sWrap .IsInVisualMode () {
194
+ p .selectRange (min (row , p .sWrap .VisualStart ), max (row , p .sWrap .VisualStart ))
195
+ }
196
+ })
197
+
191
198
// Set table selected function.
192
199
p .Table .SetSelectedFunc (func (row , _ int ) {
193
200
log .Println ("Creating and showing confirm download modal..." )
@@ -202,16 +209,26 @@ func (p *MangaPage) setHandlers(cancel context.CancelFunc) {
202
209
203
210
// Set table input captures.
204
211
p .Table .SetInputCapture (func (event * tcell.EventKey ) * tcell.EventKey {
212
+
205
213
switch event .Key () {
206
214
case tcell .KeyCtrlE : // User selects this manga row.
207
215
p .ctrlEInput ()
216
+ return event
208
217
case tcell .KeyCtrlA : // User wants to toggle select All.
209
218
p .ctrlAInput ()
219
+ return event
210
220
case tcell .KeyCtrlR : // User wants to toggle read status for Selection.
211
221
p .ctrlRInput ()
222
+ return event
212
223
case tcell .KeyCtrlQ :
213
224
p .ctrlQInput ()
225
+ return event
214
226
}
227
+
228
+ if event .Rune () == 'v' || event .Rune () == 'V' {
229
+ p .shiftVInput ()
230
+ }
231
+
215
232
return event
216
233
})
217
234
}
@@ -233,6 +250,51 @@ func (p *MangaPage) ctrlAInput() {
233
250
p .markAll ()
234
251
}
235
252
253
+ func (p * MangaPage ) selectRange (from , to int ) {
254
+ start := min (from , to )
255
+ end := max (from , to )
256
+
257
+ for row := 1 ; row < p .Table .GetRowCount (); row ++ {
258
+ if row < start || row > end {
259
+ if p .sWrap .HasSelection (row ) {
260
+ p .markUnselected (row )
261
+ }
262
+ } else {
263
+ if ! p .sWrap .HasSelection (row ) {
264
+ p .markSelected (row )
265
+ }
266
+ }
267
+ }
268
+ }
269
+
270
+ func min (a , b int ) int {
271
+ if a < b {
272
+ return a
273
+ }
274
+ return b
275
+ }
276
+
277
+ func max (a , b int ) int {
278
+ if a > b {
279
+ return a
280
+ }
281
+ return b
282
+ }
283
+
284
+ func (p * MangaPage ) shiftVInput () {
285
+ if p .sWrap .IsInVisualMode () {
286
+ p .sWrap .StopVisualSelection ()
287
+ for row := 1 ; row < p .Table .GetRowCount (); row ++ {
288
+ if p .sWrap .HasSelection (row ) {
289
+ p .markUnselected (row )
290
+ }
291
+ }
292
+ } else {
293
+ row , _ := p .Table .GetSelection ()
294
+ p .sWrap .StartVisualSelection (row )
295
+ }
296
+ }
297
+
236
298
// ctrlRInput : Allows user to toggle read status for a chapter.
237
299
func (p * MangaPage ) ctrlRInput () {
238
300
modal := confirmModal (utils .ToggleReadChapterModalID ,
0 commit comments