Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/styleguide-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export default class StyleguideView {
this.uri = props.uri
this.collapsedSections = props.collapsedSections ? new Set(props.collapsedSections) : new Set()
this.sections = []
this.mainSections = null
this.keyCodeToScrollStep = {
'33': -200, // pageup
'34': 200, // pagedown
'38': -100, // up
'40': 100, // down
'36': Number.MIN_SAFE_INTEGER, // home
'35': Number.MAX_SAFE_INTEGER // end
}
etch.initialize(this)
for (const section of this.sections) {
if (this.collapsedSections.has(section.name)) {
Expand All @@ -24,6 +33,7 @@ export default class StyleguideView {

destroy () {
this.sections = null
this.mainSections = null
}

serialize () {
Expand Down Expand Up @@ -62,6 +72,16 @@ export default class StyleguideView {
}
}

onKeyDownScroll (keyCode) {
if (!this.keyCodeToScrollStep[keyCode]) return
if (!this.mainSections) {
this.mainSections = document.querySelector('.styleguide main.styleguide-sections')
}
if (this.mainSections) {
this.mainSections.scrollTop += this.keyCodeToScrollStep[keyCode]
}
}

render () {
return (
<div className='styleguide pane-item native-key-bindings' tabIndex='-1'>
Expand Down
14 changes: 11 additions & 3 deletions lib/styleguide.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {CompositeDisposable} = require('atom')
const DOMListener = require('dom-listener')
let StyleguideView = null

const STYLEGUIDE_URI = 'atom://styleguide'
Expand All @@ -9,8 +10,14 @@ module.exports = {
this.subscriptions.add(atom.workspace.addOpener(filePath => {
if (filePath === STYLEGUIDE_URI) return this.createStyleguideView({uri: STYLEGUIDE_URI})
}))
this.subscriptions.add(atom.commands.add('atom-workspace', 'styleguide:show', () => atom.workspace.open(STYLEGUIDE_URI))
)
this.subscriptions.add(atom.commands.add('atom-workspace', 'styleguide:show',
() => atom.workspace.open(STYLEGUIDE_URI).then(() => {
this.domListener = new DOMListener(document.querySelector('atom-workspace'))
return this.domListener.add('.styleguide', 'keydown', event => {
return this.styleguideView.onKeyDownScroll(event.keyCode)
})
})
))
},

deactivate () {
Expand All @@ -19,6 +26,7 @@ module.exports = {

createStyleguideView (state) {
if (StyleguideView == null) StyleguideView = require('./styleguide-view')
return new StyleguideView(state)
this.styleguideView = new StyleguideView(state)
return this.styleguideView
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"atom-select-list": "^0.7.0",
"dedent": "^0.7.0",
"dom-listener": "^0.1.2",
"etch": "0.9.0",
"highlights": "^3.1.1"
},
Expand Down