1
0
mirror of https://github.com/hakimel/reveal.js.git synced 2025-08-08 15:46:50 +02:00

jump-to-slide is 1-indexed, falls back on word search

This commit is contained in:
hakimel
2023-01-17 09:49:49 +01:00
parent b648a56009
commit efcc86273b
8 changed files with 43 additions and 10 deletions

View File

@@ -66,10 +66,16 @@ export default class JumpToSlide {
clearTimeout( this.jumpTimeout );
delete this.jumpTimeout;
const value = this.jumpInput.value.trim( '' );
const indices = this.Reveal.location.getIndicesFromHash( value );
const query = this.jumpInput.value.trim( '' );
let indices = this.Reveal.location.getIndicesFromHash( query, { oneBasedIndex: true } );
if( indices && value !== '' ) {
// If no valid index was found and the input query is a
// string, fall back on a simple search
if( !indices && /\S+/i.test( query ) ) {
indices = this.search( query );
}
if( indices && query !== '' ) {
this.Reveal.slide( indices.h, indices.v, indices.f );
return true;
}
@@ -87,6 +93,27 @@ export default class JumpToSlide {
}
/**
* A lofi search that looks for the given query in all
* of our slides and returns the first match.
*/
search( query ) {
const regex = new RegExp( '\\b' + query.trim() + '\\b', 'i' );
const slide = this.Reveal.getSlides().find( ( slide ) => {
return regex.test( slide.innerText );
} );
if( slide ) {
return this.Reveal.getIndices( slide );
}
else {
return null;
}
}
/**
* Reverts back to the slide we were on when jump to slide was
* invoked.
@@ -100,6 +127,7 @@ export default class JumpToSlide {
confirm() {
this.jump();
this.hide();
}