@@ -75,9 +75,9 @@ class MultilineView {
7575
7676 #matchInfo;
7777
78- #ignoreCaseCb ;
78+ #ignoreCaseBtn ;
7979
80- #regexCb ;
80+ #regexBtn ;
8181
8282 /**
8383 * @param {object } opts
@@ -362,32 +362,32 @@ class MultilineView {
362362 const prevButton = ( this . #prevButton = document . createElement ( "button" ) ) ;
363363 prevButton . className = "mlc-nav-button" ;
364364 prevButton . textContent = "↑" ;
365- prevButton . ariaLabel = "Previous match" ;
365+ prevButton . title = "Previous match" ;
366366 prevButton . disabled = true ;
367367
368368 const nextButton = ( this . #nextButton = document . createElement ( "button" ) ) ;
369369 nextButton . className = "mlc-nav-button" ;
370370 nextButton . textContent = "↓" ;
371- nextButton . ariaLabel = "Next match" ;
371+ nextButton . title = "Next match" ;
372372 nextButton . disabled = true ;
373373
374374 const matchInfo = ( this . #matchInfo = document . createElement ( "span" ) ) ;
375375 matchInfo . className = "mlc-match-info" ;
376376
377- const { label : ignoreCaseLabel , cb : ignoreCaseCb } =
378- this . #makeCheckboxLabel ( "Ignore case" ) ;
379- const { label : regexLabel , cb : regexCb } = this . #makeCheckboxLabel ( "Regex" ) ;
380- this . #ignoreCaseCb = ignoreCaseCb ;
381- this . #regexCb = regexCb ;
377+ const ignoreCaseBtn = ( this . #ignoreCaseBtn = this . #makeToggleButton (
378+ "Aa" ,
379+ "Ignore case"
380+ ) ) ;
381+ const regexBtn = ( this . #regexBtn = this . #makeToggleButton ( ".*" , "Regex" ) ) ;
382382
383383 searchGroup . append (
384384 searchInput ,
385385 searchError ,
386386 prevButton ,
387387 nextButton ,
388- matchInfo ,
389- ignoreCaseLabel ,
390- regexLabel
388+ ignoreCaseBtn ,
389+ regexBtn ,
390+ matchInfo
391391 ) ;
392392
393393 const gotoInput = document . createElement ( "input" ) ;
@@ -412,8 +412,16 @@ class MultilineView {
412412 } ) ;
413413 prevButton . addEventListener ( "click" , ( ) => this . #navigateMatch( - 1 ) ) ;
414414 nextButton . addEventListener ( "click" , ( ) => this . #navigateMatch( 1 ) ) ;
415- this . #ignoreCaseCb. addEventListener ( "change" , ( ) => this . #runSearch( ) ) ;
416- this . #regexCb. addEventListener ( "change" , ( ) => this . #runSearch( ) ) ;
415+ this . #ignoreCaseBtn. addEventListener ( "click" , ( ) => {
416+ this . #ignoreCaseBtn. ariaPressed =
417+ this . #ignoreCaseBtn. ariaPressed === "true" ? "false" : "true" ;
418+ this . #runSearch( ) ;
419+ } ) ;
420+ this . #regexBtn. addEventListener ( "click" , ( ) => {
421+ this . #regexBtn. ariaPressed =
422+ this . #regexBtn. ariaPressed === "true" ? "false" : "true" ;
423+ this . #runSearch( ) ;
424+ } ) ;
417425
418426 gotoInput . addEventListener ( "keydown" , ( { key } ) => {
419427 if ( key !== "Enter" ) {
@@ -432,13 +440,13 @@ class MultilineView {
432440 return bar ;
433441 }
434442
435- #makeCheckboxLabel ( text ) {
436- const label = document . createElement ( "label " ) ;
437- label . className = "mlc-check-label " ;
438- const cb = document . createElement ( "input" ) ;
439- cb . type = "checkbox" ;
440- label . append ( cb , ` ${ text } ` ) ;
441- return { label , cb } ;
443+ #makeToggleButton ( text , title ) {
444+ const btn = document . createElement ( "button " ) ;
445+ btn . className = "mlc-nav-button " ;
446+ btn . textContent = text ;
447+ btn . title = title ;
448+ btn . ariaPressed = "false" ;
449+ return btn ;
442450 }
443451
444452 #updateMatchInfo( ) {
@@ -466,9 +474,12 @@ class MultilineView {
466474 }
467475
468476 let test ;
469- if ( this . #regexCb . checked ) {
477+ if ( this . #regexBtn . ariaPressed === "true" ) {
470478 try {
471- const re = new RegExp ( query , this . #ignoreCaseCb. checked ? "i" : "" ) ;
479+ const re = new RegExp (
480+ query ,
481+ this . #ignoreCaseBtn. ariaPressed === "true" ? "i" : ""
482+ ) ;
472483 test = str => re . test ( str ) ;
473484 this . #searchInput. removeAttribute ( "aria-invalid" ) ;
474485 this . #searchError. textContent = "" ;
@@ -479,7 +490,7 @@ class MultilineView {
479490 return false ;
480491 }
481492 } else {
482- const ignoreCase = this . #ignoreCaseCb . checked ;
493+ const ignoreCase = this . #ignoreCaseBtn . ariaPressed === "true" ;
483494 const needle = ignoreCase ? query . toLowerCase ( ) : query ;
484495 test = str => ( ignoreCase ? str . toLowerCase ( ) : str ) . includes ( needle ) ;
485496 }
0 commit comments