Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 360bf48

Browse files
committed
🎨 scroll on key press (pageup/pagedown/up/down/home/end)
- use dom-listener to handle keydown event - add styleguideView, domListener in styleguide.coffee - add onKeyDownScroll() to change scrollTop property in styleguide-view.js
1 parent 86325df commit 360bf48

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

lib/styleguide-view.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ export default class StyleguideView {
1212
constructor (props) {
1313
this.uri = props.uri
1414
this.collapsedSections = props.collapsedSections ? new Set(props.collapsedSections) : new Set()
15+
this.mainSections = null
1516
this.sections = []
17+
this.keyCodeToScrollStep = {
18+
'33': -200, // pageup
19+
'34': 200, // pagedown
20+
'38': -100, // up
21+
'40': 100, // down
22+
'36': Number.MIN_SAFE_INTEGER, // home
23+
'35': Number.MAX_SAFE_INTEGER, // end
24+
}
1625
etch.initialize(this)
1726
for (const section of this.sections) {
1827
if (this.collapsedSections.has(section.name)) {
@@ -25,6 +34,7 @@ export default class StyleguideView {
2534

2635
destroy () {
2736
this.sections = null
37+
this.mainSections = null
2838
}
2939

3040
serialize () {
@@ -59,6 +69,16 @@ export default class StyleguideView {
5969
}
6070
}
6171

72+
onKeyDownScroll(keyCode) {
73+
if (!this.keyCodeToScrollStep[keyCode]) return
74+
if (!this.mainSections) {
75+
this.mainSections = document.querySelector('.styleguide main.styleguide-sections')
76+
}
77+
if (this.mainSections) {
78+
this.mainSections.scrollTop += this.keyCodeToScrollStep[keyCode]
79+
}
80+
}
81+
6282
render () {
6383
return (
6484
<div className='styleguide pane-item native-key-bindings' tabIndex='-1'>

lib/styleguide.coffee

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
{CompositeDisposable} = require 'atom'
2+
DOMListener = require 'dom-listener'
23
StyleguideUri = 'atom://styleguide'
34

45
module.exports =
56
activate: ->
67
@subscriptions = new CompositeDisposable
78
@subscriptions.add atom.workspace.addOpener (filePath) =>
89
@createStyleguideView(uri: StyleguideUri) if filePath is StyleguideUri
9-
@subscriptions.add atom.commands.add 'atom-workspace', 'styleguide:show', ->
10-
atom.workspace.open(StyleguideUri)
10+
@subscriptions.add atom.commands.add 'atom-workspace', 'styleguide:show', =>
11+
atom.workspace.open(StyleguideUri).then =>
12+
@domListener = new DOMListener(document.querySelector('atom-workspace'))
13+
@domListener.add '.styleguide', 'keydown', (event) =>
14+
@styleguideView.onKeyDownScroll(event.keyCode)
1115

1216
deactivate: ->
1317
@subscriptions.dispose()
1418

1519
createStyleguideView: (state) ->
1620
StyleguideView = require './styleguide-view'
17-
new StyleguideView(state)
21+
@styleguideView = new StyleguideView(state)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"atom-select-list": "0.0.12",
1010
"coffee-script": "~1.8.0",
1111
"dedent": "^0.6.0",
12+
"dom-listener": "^0.1.2",
1213
"highlights": "2.1.1",
1314
"js-beautify": "^1.4.0",
1415
"underscore-plus": "^1.0.0"

0 commit comments

Comments
 (0)