mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	feat: j and k hotkeys in topic to navigate through it quickly
This commit is contained in:
		| @@ -73,19 +73,39 @@ define('forum/topic', [ | |||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	function handleTopicSearch() { | 	function handleTopicSearch() { | ||||||
| 		if (config.topicSearchEnabled) { | 		require(['mousetrap'], (mousetrap) => { | ||||||
| 			require(['mousetrap', 'search'], function (mousetrap, search) { | 			if (config.topicSearchEnabled) { | ||||||
| 				mousetrap.bind(['command+f', 'ctrl+f'], function (e) { | 				require(['search'], function (search) { | ||||||
| 					e.preventDefault(); | 					mousetrap.bind(['command+f', 'ctrl+f'], function (e) { | ||||||
| 					$('#search-fields input').val('in:topic-' + ajaxify.data.tid + ' '); | 						e.preventDefault(); | ||||||
| 					search.showAndFocusInput(); | 						$('#search-fields input').val('in:topic-' + ajaxify.data.tid + ' '); | ||||||
| 				}); | 						search.showAndFocusInput(); | ||||||
|  | 					}); | ||||||
|  |  | ||||||
| 				hooks.onPage('action:ajaxify.cleanup', () => { | 					hooks.onPage('action:ajaxify.cleanup', () => { | ||||||
| 					mousetrap.unbind(['command+f', 'ctrl+f']); | 						mousetrap.unbind(['command+f', 'ctrl+f']); | ||||||
|  | 					}); | ||||||
| 				}); | 				}); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			mousetrap.bind('j', () => { | ||||||
|  | 				const index = navigator.getIndex(); | ||||||
|  | 				const count = navigator.getCount(); | ||||||
|  | 				if (index === count) { | ||||||
|  | 					return; | ||||||
|  | 				} | ||||||
|  |  | ||||||
|  | 				navigator.scrollToIndex(index, true, 0); | ||||||
| 			}); | 			}); | ||||||
| 		} |  | ||||||
|  | 			mousetrap.bind('k', () => { | ||||||
|  | 				const index = navigator.getIndex(); | ||||||
|  | 				if (index === 1) { | ||||||
|  | 					return; | ||||||
|  | 				} | ||||||
|  | 				navigator.scrollToIndex(index - 2, true, 0); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	Topic.toTop = function () { | 	Topic.toTop = function () { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user