Skip to content
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

Only show copy button if there is text to copy #943

Merged
merged 2 commits into from
Aug 14, 2017
Merged
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
43 changes: 31 additions & 12 deletions lib/components/result-view/result-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ResultViewComponent extends React.Component {
el: ?HTMLElement;
containerTooltip = new CompositeDisposable();
buttonTooltip = new CompositeDisposable();
closeTooltip = new CompositeDisposable();
expanded: IObservableValue<boolean> = observable(false);

getAllText = () => {
Expand Down Expand Up @@ -55,16 +56,24 @@ class ResultViewComponent extends React.Component {
if (!element || !comp.disposables || comp.disposables.size > 0) return;
comp.add(
atom.tooltips.add(element, {
title: () => {
const ctrlOrCmdMessage = `Click to copy,
title: `Click to copy,
${process.platform === "darwin"
? "Cmd"
: "Ctrl"}+Click to open in editor`;
: "Ctrl"}+Click to open in editor`
})
);
};

return this.props.store.executionCount
? `${ctrlOrCmdMessage} (Out[${this.props.store.executionCount}])`
: ctrlOrCmdMessage;
}
addCloseButtonTooltip = (
element: ?HTMLElement,
comp: atom$CompositeDisposable
) => {
if (!element || !comp.disposables || comp.disposables.size > 0) return;
comp.add(
atom.tooltips.add(element, {
title: this.props.store.executionCount
? `Close (Out[${this.props.store.executionCount}])`
: "Close result"
})
);
};
Expand Down Expand Up @@ -153,13 +162,22 @@ class ResultViewComponent extends React.Component {
{isPlain
? null
: <div className="toolbar">
<div className="icon icon-x" onClick={this.props.destroy} />
<div style={{ flex: 1, minHeight: "0.25em" }} />
<div
className="icon icon-clippy"
onClick={this.handleClick}
ref={this.addCopyButtonTooltip}
className="icon icon-x"
onClick={this.props.destroy}
ref={ref => this.addCloseButtonTooltip(ref, this.closeTooltip)}
/>

<div style={{ flex: 1, minHeight: "0.25em" }} />

{this.getAllText().length > 0
? <div
className="icon icon-clippy"
onClick={this.handleClick}
ref={this.addCopyButtonTooltip}
/>
: null}

{this.el && this.el.scrollHeight > DEFAULT_SCROLL_HEIGHT
? <div
className={`icon icon-${this.expanded.get()
Expand Down Expand Up @@ -198,6 +216,7 @@ class ResultViewComponent extends React.Component {
componentWillUnmount() {
this.containerTooltip.dispose();
this.buttonTooltip.dispose();
this.closeTooltip.dispose();
}
}

Expand Down