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

@ -1816,6 +1816,11 @@ $notesWidthPercent: 25%;
color: currentColor; color: currentColor;
border: 0; border: 0;
} }
.reveal .jump-to-slide-input::placeholder {
color: currentColor;
opacity: 0.3;
}
.reveal.has-dark-background .jump-to-slide-input { .reveal.has-dark-background .jump-to-slide-input {
color: #fff; color: #fff;
} }

2
dist/reveal.css vendored

File diff suppressed because one or more lines are too long

2
dist/reveal.esm.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/reveal.js vendored

File diff suppressed because one or more lines are too long

2
dist/reveal.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -66,10 +66,16 @@ export default class JumpToSlide {
clearTimeout( this.jumpTimeout ); clearTimeout( this.jumpTimeout );
delete this.jumpTimeout; delete this.jumpTimeout;
const value = this.jumpInput.value.trim( '' ); const query = this.jumpInput.value.trim( '' );
const indices = this.Reveal.location.getIndicesFromHash( value ); 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 ); this.Reveal.slide( indices.h, indices.v, indices.f );
return true; 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 * Reverts back to the slide we were on when jump to slide was
* invoked. * invoked.
@ -100,6 +127,7 @@ export default class JumpToSlide {
confirm() { confirm() {
this.jump();
this.hide(); this.hide();
} }

View File

@ -40,7 +40,7 @@ export default class Location {
* *
* @returns slide indices or null * @returns slide indices or null
*/ */
getIndicesFromHash( hash=window.location.hash ) { getIndicesFromHash( hash=window.location.hash, options={} ) {
// Attempt to parse the hash as either an index or name // Attempt to parse the hash as either an index or name
let name = hash.replace( /^#\/?/, '' ); let name = hash.replace( /^#\/?/, '' );
@ -72,7 +72,7 @@ export default class Location {
} }
else { else {
const config = this.Reveal.getConfig(); const config = this.Reveal.getConfig();
let hashIndexBase = config.hashOneBasedIndex ? 1 : 0; let hashIndexBase = config.hashOneBasedIndex || options.oneBasedIndex ? 1 : 0;
// Read the index components of the hash // Read the index components of the hash
let h = ( parseInt( bits[0], 10 ) - hashIndexBase ) || 0, let h = ( parseInt( bits[0], 10 ) - hashIndexBase ) || 0,