Pluto.jl icon indicating copy to clipboard operation
Pluto.jl copied to clipboard

Keyboard shortcut for toggling cell visibility

Open CarloLucibello opened this issue 2 years ago • 1 comments

It would be a convenient addition, especially for markdown cells.

CarloLucibello avatar Apr 26 '22 04:04 CarloLucibello

If you want to hack a solution while waiting for feedback here, you can add the following cell to enable that functionality with Ctrl+H (taken from https://github.com/disberd/PlutoUtilities.jl/blob/273e080b03074d181371a2066636571bfb06f08a/src/kbd_shortcuts.jl)

You can change the shortcut by modifying the if (e.key == "h" && e.ctrlKey) part

html"""
Script to toggle cell visibility with Ctrl+H loaded.<br>When last mouse click was on a pluto-cell, default Ctrl+H behavior is prevented
<script>
let last_cell
const onClick = e => {
	last_cell = document.elementFromPoint(e.clientX,e.clientY).closest('pluto-cell')
}
document.addEventListener('click',onClick)
const func = e => {
	// Check if the target is a cell
	const t = e.target
	const this_cell = t.closest('pluto-cell')
	let cell = this_cell === null ? last_cell : this_cell
	if (cell === null) return
	const key = e.key
	
	if (key == "h" && e.ctrlKey) {
		e.preventDefault()
		const hide_but = cell.querySelector('.foldcode')
		hide_but.click()
		last_cell = cell
		return
	}
	
}
document.addEventListener('keydown',func)
invalidation.then(() => {
	document.removeEventListener('keydown',func)
	document.removeEventListener('click',onClick)
})
</script>
"""

disberd avatar Jun 03 '22 16:06 disberd

It would be pretty nice to have the option to hide/unhide all cells as well for cases where you want to share the notebook as a GUI for some code

Vaibhavdixit02 avatar Mar 13 '23 14:03 Vaibhavdixit02