Forráskód Böngészése

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

hakimel 2 éve
szülő
commit
efcc86273b

+ 5 - 0
css/reveal.scss

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

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/reveal.css


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/reveal.esm.js


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/reveal.esm.js.map


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/reveal.js


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/reveal.js.map


+ 31 - 3
js/controllers/jumptoslide.js

@@ -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();
 
 	}

+ 2 - 2
js/controllers/location.js

@@ -40,7 +40,7 @@ export default class Location {
 	 *
 	 * @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
 		let name = hash.replace( /^#\/?/, '' );
@@ -72,7 +72,7 @@ export default class Location {
 		}
 		else {
 			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
 			let h = ( parseInt( bits[0], 10 ) - hashIndexBase ) || 0,

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott