@@ -111,6 +111,19 @@ void UIAbstractTableView::selectAll() {
111111 }
112112}
113113
114+ std::vector<ModelIndex> UIAbstractTableView::getSelectionRange ( const ModelIndex& start,
115+ const ModelIndex& end ) const {
116+ std::vector<ModelIndex> range;
117+ if ( !getModel () )
118+ return range;
119+ int minRow = eemin ( start.row (), end.row () );
120+ int maxRow = eemax ( start.row (), end.row () );
121+ for ( int i = minRow; i <= maxRow; ++i ) {
122+ range.push_back ( getModel ()->index ( i, start.column () ) );
123+ }
124+ return range;
125+ }
126+
114127size_t UIAbstractTableView::getItemCount () const {
115128 if ( !getModel () )
116129 return 0 ;
@@ -507,17 +520,34 @@ UITableRow* UIAbstractTableView::createRow() {
507520 return ;
508521 auto index = event->getNode ()->asType <UITableRow>()->getCurIndex ();
509522 if ( mSelectionKind == SelectionKind::Single &&
510- getInput ()->getSanitizedModState () & KeyMod::getDefaultModifier () ) {
523+ ( getInput ()->getSanitizedModState () & KeyMod::getDefaultModifier () ) ) {
511524 getSelection ().remove ( index );
512525 } else {
513526 if ( mSelectionKind == SelectionKind::Multiple &&
514- getInput ()->getSanitizedModState () & KeyMod::getDefaultModifier () ) {
527+ ( getInput ()->getSanitizedModState () & KeyMod::getDefaultModifier () ) ) {
515528 getSelection ().toggle ( index );
529+ } else if ( mSelectionKind == SelectionKind::Multiple &&
530+ ( getInput ()->getSanitizedModState () & KEYMOD_SHIFT ) &&
531+ !getSelection ().isEmpty () ) {
532+ getSelection ().set ( getSelectionRange ( getSelection ().first (), index ) );
533+ } else if ( mSelectionKind == SelectionKind::Multiple ) {
534+ if ( !getSelection ().contains ( index ) )
535+ getSelection ().set ( index );
516536 } else {
517537 getSelection ().set ( index );
518538 }
519539 }
520540 } );
541+ rowWidget->on ( Event::MouseClick, [this ]( const Event* event ) {
542+ if ( !( event->asMouseEvent ()->getFlags () & ( EE_BUTTON_LMASK | EE_BUTTON_RMASK ) ) ||
543+ !isRowSelection () )
544+ return ;
545+
546+ auto index = event->getNode ()->asType <UITableRow>()->getCurIndex ();
547+ if ( 0 == getInput ()->getSanitizedModState () ) {
548+ getSelection ().set ( index );
549+ }
550+ } );
521551 onRowCreated ( rowWidget );
522552 return rowWidget;
523553}
0 commit comments