@@ -145,8 +145,8 @@ angular.module("korpApp").component("kwic", {
145145 page-change ="$ctrl.pageEvent(page) "
146146 hits-per-page ="$ctrl.hitsPerPage "
147147 > </ kwic-pager >
148- < div class ="table_scrollarea " dir =" {{ dir }} " >
149- < table class ="results_table kwic " ng-if ="!$ctrl.useContext " cellspacing ="0 ">
148+ < div class ="table_scrollarea ">
149+ < table class ="results_table kwic " ng-if ="!$ctrl.useContext " cellspacing ="0 " dir =" {{ dir }} " >
150150 < tr
151151 class ="sentence "
152152 ng-repeat ="sentence in $ctrl.kwic "
@@ -197,7 +197,7 @@ angular.module("korpApp").component("kwic", {
197197 </ td >
198198 </ tr >
199199 </ table >
200- < div class ="results_table reading " ng-if ="$ctrl.useContext ">
200+ < div class ="results_table reading " ng-if ="$ctrl.useContext " dir =" {{ dir }} " >
201201 < p
202202 class ="sentence "
203203 ng-repeat ="sentence in $ctrl.kwic "
@@ -301,8 +301,8 @@ angular.module("korpApp").component("kwic", {
301301 $ctrl . useContext = $ctrl . context || ! store . in_order
302302 if ( ! $ctrl . context ) {
303303 $timeout ( ( ) => {
304+ $element . find ( ".match .word" ) . first ( ) . trigger ( "click" )
304305 centerScrollbar ( )
305- $element . find ( ".match" ) . children ( ) . first ( ) . click ( )
306306 } )
307307 }
308308
@@ -552,9 +552,16 @@ angular.module("korpApp").component("kwic", {
552552
553553 /** Scroll KWIC container to center the match column. */
554554 function centerScrollbar ( ) {
555- // Type assertion needed because `container` is non-standard.
556- const options = { block : "nearest" , inline : "center" , container : "nearest" } as ScrollIntoViewOptions
557- $element . find ( ".match" ) . get ( 0 ) ?. scrollIntoView ( options )
555+ const area = $element . get ( 0 ) ?. querySelector ( ".table_scrollarea" )
556+ const match = area ?. querySelector ( ".match" )
557+ if ( ! area || ! match ) return
558+ const matchBox = match . getBoundingClientRect ( )
559+ const areaBox = area . getBoundingClientRect ( )
560+ const scrollLeft = area . scrollLeft + matchBox . left + matchBox . width / 2 - areaBox . width / 2
561+ // After setting `.scrollLeft`, it corrects itself to a value within range,
562+ // so this works also with RTL where `scrollLeft` is negative in some browsers.
563+ area . scrollLeft = - 1e10
564+ area . scrollLeft += scrollLeft
558565 }
559566
560567 /** Add offsets to align each linked sentence with its main one */
0 commit comments