-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline result overhaul #127
Merged
Merged
Changes from 57 commits
Commits
Show all changes
121 commits
Select commit
Hold shift + click to select a range
ed8ccb8
initial improvements
pfitzseb 4a7db2e
fix result resizing
pfitzseb e11ab5b
style tweaks
pfitzseb 5d2e053
more tweaking
pfitzseb 26dff69
make result invalidation more robust
pfitzseb 5a4f447
better positioning
pfitzseb 6c16d90
reset width on collapse
pfitzseb f9c747e
fix undef `el`
pfitzseb 4993a8c
add default keybindings
pfitzseb 6679278
proper code font size
pfitzseb b51684e
make text in results selectable
pfitzseb 97bff4a
slight cleanup
pfitzseb 93bc956
fix keymap and resizing
pfitzseb 930c456
fix specs
pfitzseb a5b9b48
make console results selectable too
pfitzseb a75776f
fix mac keybinding
pfitzseb 11905d7
fix keybindings for real
pfitzseb 02c6c1f
fix
pfitzseb 7f4e173
pref improvements (BROKEN!)
pfitzseb 46a7671
perf "improvements" (kinda working)
pfitzseb 066980d
somewhat almost acceptable performance
pfitzseb b2ed763
update?
pfitzseb 9c1abe7
slight cleanup
pfitzseb 6f8f7ff
maybe better perf?
pfitzseb 2e4acb1
Use DisplayMarkerLayer for Results
pfitzseb 3bb3592
Fix Set usage
pfitzseb 8787b22
new result expanding strategy
pfitzseb ed1fa40
revert console changes, clean up css
pfitzseb a642f91
fix and generalize tooltips
pfitzseb aa29064
add result toolbar
pfitzseb a392df4
style tweaks
pfitzseb 72134c4
make tooltips more robust
pfitzseb d47fa90
nicer css
pfitzseb a2c84e4
add and document custom buttons for results
pfitzseb 3f4433a
line-height instead of padding
pfitzseb faa8cde
move result toolbar to the right
pfitzseb 0a12263
requestAnimationFrame goodness
pfitzseb 648dca1
Revert "requestAnimationFrame goodness"
pfitzseb 6125f4b
nicer code
pfitzseb 1afacc2
fix styling
pfitzseb 82289fd
perf improvements
pfitzseb 5fb5b87
be a bit smarter about what to update, improve perf
pfitzseb a425767
cleanup
pfitzseb 08db273
fix resizing
pfitzseb 53fc5e6
js-ify results
pfitzseb ad4c8e9
fix block results
pfitzseb 543dd32
fix styling
pfitzseb 2ff73a8
don't show toolbar for small results
pfitzseb 72e86ac
fix css
pfitzseb afb796c
better toolbar positioning
pfitzseb 521fa52
fix non-perf comments
pfitzseb d6f131f
extensible toolbar, destroy fix, better css
pfitzseb a2f522c
better styling
pfitzseb bd7701f
slightly nicer API
pfitzseb 77ee257
get rid of console border
pfitzseb 73423fd
simplify standard buttons
pfitzseb 696c1ab
smaller toolbar
pfitzseb 346f65c
some whitespace css fixes
pfitzseb d3dd910
get rid of fastdom
pfitzseb 37a7d51
fix travis for atom beta
pfitzseb 60b61ad
Merge remote-tracking branch 'origin/master'
pfitzseb 2860142
initial improvements
pfitzseb 8d3a41e
fix result resizing
pfitzseb 281add0
style tweaks
pfitzseb f35a2b0
more tweaking
pfitzseb 18f7d1a
make result invalidation more robust
pfitzseb 4e8684e
better positioning
pfitzseb d9f70a8
reset width on collapse
pfitzseb 0d3dadf
fix undef `el`
pfitzseb db0a279
add default keybindings
pfitzseb c628a81
proper code font size
pfitzseb ef610c7
make text in results selectable
pfitzseb a4e15ba
slight cleanup
pfitzseb aa233f5
fix keymap and resizing
pfitzseb 10e78d9
fix specs
pfitzseb 481924b
make console results selectable too
pfitzseb 8da4719
fix mac keybinding
pfitzseb eb04014
fix keybindings for real
pfitzseb 7371c13
fix
pfitzseb 716de34
pref improvements (BROKEN!)
pfitzseb c1f2e07
perf "improvements" (kinda working)
pfitzseb a40b030
somewhat almost acceptable performance
pfitzseb 40153b4
update?
pfitzseb 5e7c995
slight cleanup
pfitzseb ad5def1
maybe better perf?
pfitzseb 21bbaa7
Use DisplayMarkerLayer for Results
pfitzseb 2c6387b
Fix Set usage
pfitzseb dd24c53
new result expanding strategy
pfitzseb 2d21266
revert console changes, clean up css
pfitzseb de042d0
fix and generalize tooltips
pfitzseb 3d8ece2
add result toolbar
pfitzseb a86561b
style tweaks
pfitzseb 44c316e
make tooltips more robust
pfitzseb b6f629e
nicer css
pfitzseb b287cd1
add and document custom buttons for results
pfitzseb 34d198e
line-height instead of padding
pfitzseb 3783451
move result toolbar to the right
pfitzseb b7d9ade
requestAnimationFrame goodness
pfitzseb 289abd8
Revert "requestAnimationFrame goodness"
pfitzseb 7567bf1
nicer code
pfitzseb fd53dea
fix styling
pfitzseb fad2a52
perf improvements
pfitzseb 8f5b711
be a bit smarter about what to update, improve perf
pfitzseb 87e18d9
cleanup
pfitzseb 4b5a4bc
fix resizing
pfitzseb 8bde805
js-ify results
pfitzseb 2b353e5
fix block results
pfitzseb cf43f97
fix styling
pfitzseb c9ed22b
don't show toolbar for small results
pfitzseb 02ee9f8
fix css
pfitzseb 359b9c5
better toolbar positioning
pfitzseb 4678545
fix non-perf comments
pfitzseb 3965142
extensible toolbar, destroy fix, better css
pfitzseb 91ae5bd
better styling
pfitzseb 552275e
slightly nicer API
pfitzseb 6d85e11
get rid of console border
pfitzseb cc9fe84
simplify standard buttons
pfitzseb ca7bebd
smaller toolbar
pfitzseb ff9a012
some whitespace css fixes
pfitzseb 96e5015
get rid of fastdom
pfitzseb c354ee2
Merge remote-tracking branch 'origin/sp/newrsults' into sp/newrsults
pfitzseb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
'use babel' | ||
import {CompositeDisposable} from 'atom' | ||
let views = require('../util/views') | ||
let {span, div} = views.tags | ||
|
||
export default class ResultView { | ||
constructor (model, opts = {}) { | ||
this.model = model | ||
this.disposables = new CompositeDisposable() | ||
this.completeView(opts) | ||
|
||
this.model.onDidRemove(() => this.destroy()) | ||
this.model.onDidUpdate(() => this.modelUpdated = true) | ||
this.model.onDidInvalidate(() => this.view.classList.add('invalid')) | ||
this.model.onDidValidate(() => this.view.classList.remove('invalid')) | ||
this.model.onDidAttach(() => this.overlayElement = this.complete.parentElement) | ||
|
||
this.lastEdWidth = -1 | ||
|
||
return this | ||
} | ||
|
||
getView () { | ||
return this.model.type == 'inline' ? this.complete : this.view | ||
} | ||
|
||
getContent () { | ||
return this.view | ||
} | ||
|
||
getRawContent () { | ||
return this.rawContent | ||
} | ||
|
||
completeView (opts) { | ||
this.complete = document.createElement('div') | ||
this.complete.classList.add('ink-result-container') | ||
if (!opts.noTB && opts.type === 'inline') { | ||
this.toolbarView = this.toolbar(opts.buttons, opts.customButtons) | ||
this.complete.appendChild(this.toolbarView) | ||
} | ||
|
||
this.complete.appendChild(this.content(opts)) | ||
|
||
this.disposables.add(atom.config.observe('editor.lineHeight', (h) => { | ||
this.complete.style.top = -h + 'em' | ||
this.complete.style.minHeight = h + 'em' | ||
})) | ||
} | ||
|
||
content (opts) { | ||
let {content, fade, loading, type} = opts | ||
this.view = document.createElement('div') | ||
this.view.setAttribute('tabindex', '-1') | ||
this.view.classList.add('ink', 'result', opts.scope) | ||
if (type === 'inline') { | ||
this.view.classList.add('inline') | ||
} else if (type === 'block') { | ||
this.view.classList.add('under') | ||
} | ||
|
||
this.view.addEventListener('mousewheel', (e) => { | ||
if ((this.view.offsetHeight < this.view.scrollHeight || | ||
this.view.offsetWidth < this.view.scrollWidth) && | ||
((e.deltaY > 0 && this.view.scrollHeight - this.view.scrollTop > this.view.clientHeight) || | ||
(e.deltaY < 0 && this.view.scrollTop > 0) || | ||
(e.deltaX > 0 && this.view.scrollWidth - this.view.scrollLeft > this.view.clientWidth) || | ||
(e.deltaX < 0 && this.view.scrollLeft > 0))) { | ||
e.stopPropagation() | ||
} | ||
}) | ||
|
||
this.view.addEventListener('click', () => { | ||
if (this.overlayElement === null) return | ||
this.overlayElement.parentNode.appendChild(this.overlayElement) | ||
}) | ||
|
||
this.disposables.add(atom.commands.add(this.view, {'inline-results:clear': () => this.remove()})) | ||
|
||
if (fade) this.fadeIn() | ||
if (content != null) this.setContent(content, opts) | ||
if (loading) this.setContent(views.render(span('loading icon icon-gear')), opts) | ||
|
||
return this.view | ||
} | ||
|
||
fadeIn () { | ||
this.view.classList.add('ink-hide') | ||
setTimeout(() => this.view.classList.remove('ink-hide'), 20) | ||
} | ||
|
||
setContent (view, {error = false, loading = false}) { | ||
this.rawContent = [view, {error, loading}] | ||
while (this.view.firstChild != null) { | ||
this.view.removeChild(this.view.firstChild) | ||
} | ||
error ? this.view.classList.add('error') : this.view.classList.remove('error') | ||
loading ? this.view.classList.add('loading') : this.view.classList.remove('loading') | ||
this.view.appendChild(view) | ||
|
||
// HACK: don't display toolbar for "small" results | ||
if (this.model.type === 'inline' && this.toolbarView && view.innerHTML.length < 100 ) { | ||
this.toolbarView.classList.add('hide') | ||
} else { | ||
this.toolbarView.classList.remove('hide') | ||
} | ||
} | ||
|
||
toolbar (buttons, customButtons) { | ||
let tb = views.render(div('btn-group')) | ||
let addButtons = (buttons) => { | ||
for (let b of buttons(this.model)) { | ||
let v = document.createElement('button') | ||
v.classList.add('btn', b.icon) | ||
v.addEventListener('click', b.onclick) | ||
tb.appendChild(v) | ||
} | ||
} | ||
if (customButtons) addButtons(customButtons) | ||
addButtons(buttons) | ||
return views.render(div('ink-result-toolbar', tb)) | ||
} | ||
|
||
// only read from the DOM | ||
decideUpdateWidth (edRect) { | ||
this.isVisible = false | ||
this.left = 0 | ||
this.newEdWidth = false | ||
if (this.overlayElement) { | ||
let rect = this.view.getBoundingClientRect() | ||
this.isVisible = rect.top < edRect.bottom && rect.bottom > edRect.top | ||
this.left = parseInt(this.getView().parentElement.style.left) | ||
this.newEdWidth = edRect.width !== this.lastEdWidth | ||
} | ||
} | ||
|
||
// only write to the DOM | ||
updateWidth (edRect) { | ||
if ((this.isVisible && this.newEdWidth) || this.modelUpdated) { | ||
let w = edRect.width + edRect.left - 40 - this.left | ||
if (w < 100) w = 100 | ||
this.getView().style.maxWidth = w + 'px' | ||
this.lastEdWidth = edRect.width | ||
this.modelUpdated = false | ||
} | ||
} | ||
|
||
destroy () { | ||
this.view.classList.add('ink-hide') | ||
this.disposables.dispose() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This keybinding is quite generic – ideally I'd use a prefix – but maybe it's common enough to be worthwhile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C-i C-t
maybe? I kinda like an unprefixed keybinding for this, but don't have any super strong feelings about it.