Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05e0aac

Browse files
committed
Undo 🎨 for mouse selection in FilePatchView
Complexities and edge cases around shift/cmd clicking make it not worth it
1 parent 48e901a commit 05e0aac

File tree

2 files changed

+41
-74
lines changed

2 files changed

+41
-74
lines changed

lib/views/file-patch-view.js

Lines changed: 33 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import {CompositeDisposable, Disposable} from 'atom';
55

66
import etch from 'etch';
7-
import cx from 'classnames';
87
import {autobind} from 'core-decorators';
98

109
import HunkView from './hunk-view';
@@ -15,7 +14,7 @@ export default class FilePatchView {
1514
this.props = props;
1615
this.selection = new FilePatchSelection(this.props.hunks);
1716
this.fontSize = atom.config.get('editor.fontSize');
18-
this.mouseSelection = {started: false, dragged: false, type: 'line'};
17+
this.mouseSelectionInProgress = false;
1918

2019
window.addEventListener('mouseup', this.mouseup);
2120
this.disposables = new CompositeDisposable();
@@ -63,10 +62,9 @@ export default class FilePatchView {
6362
const headHunk = this.selection.getHeadHunk();
6463
const headLine = this.selection.getHeadLine();
6564
const hunkSelectionMode = this.selection.getMode() === 'hunk';
66-
const unstaged = this.props.stagingStatus === 'unstaged';
67-
const stageButtonLabelPrefix = unstaged ? 'Stage' : 'Unstage';
65+
const stageButtonLabelPrefix = this.props.stagingStatus === 'unstaged' ? 'Stage' : 'Unstage';
6866
return (
69-
<div className={cx('github-FilePatchView', {'is-staged': !unstaged, 'is-unstaged': unstaged})} tabIndex="-1"
67+
<div className="github-FilePatchView" tabIndex="-1"
7068
onmouseup={this.mouseup}
7169
style={`font-size: ${this.fontSize}px`}>
7270
{this.props.hunks.map(hunk => {
@@ -87,10 +85,9 @@ export default class FilePatchView {
8785
selectedLines={selectedLines}
8886
headLine={headLine}
8987
headHunk={headHunk}
90-
dblclickOnItem={e => this.dblclickOnItem(e, hunk)}
91-
mousedownOnHunk={e => this.mousedownOnHunk(e, hunk)}
92-
mousedownOnItem={this.mousedownOnItem}
93-
mousemoveOnItem={this.mousemoveOnItem}
88+
mousedownOnHeader={() => this.mousedownOnHeader(hunk)}
89+
mousedownOnLine={this.mousedownOnLine}
90+
mousemoveOnLine={this.mousemoveOnLine}
9491
didClickStageButton={() => this.didClickStageButtonForHunk(hunk)}
9592
registerView={this.props.registerHunkView}
9693
/>
@@ -100,82 +97,51 @@ export default class FilePatchView {
10097
);
10198
}
10299

103-
@autobind
104-
async dblclickOnItem(event, hunk) {
105-
this.selection.selectHunk(hunk, false);
106-
this.mouseSelection.type = 'hunk';
107-
await etch.update(this);
108-
}
109-
110-
@autobind
111-
async mousedownOnHunk(event, hunk) {
112-
if (event.button === 0) {
113-
this.mouseSelection = {
114-
started: true,
115-
dragged: false,
116-
type: 'hunk',
117-
};
118-
this.selection.selectHunk(hunk, event.shiftKey);
119-
await etch.update(this);
120-
}
100+
mousedownOnHeader(hunk) {
101+
this.selection.selectHunk(hunk);
102+
this.mouseSelectionInProgress = true;
103+
return etch.update(this);
121104
}
122105

123106
@autobind
124-
async mousedownOnItem(event, hunk, line) {
125-
const type = event.shiftKey ? this.mouseSelection.type : 'line';
126-
if (event.button === 0) {
127-
this.mouseSelection = {
128-
started: true,
129-
dragged: false,
130-
type,
131-
};
132-
133-
if (event.ctrlKey || event.metaKey) {
134-
if (type === 'hunk') {
135-
this.selection.addOrSubtractHunkSelection(hunk);
136-
} else {
137-
this.selection.addOrSubtractLineSelection(line);
138-
}
139-
} else if (event.shiftKey) {
140-
if (type === 'hunk') {
141-
this.selection.selectHunk(hunk, true);
142-
} else {
143-
this.selection.selectLine(line, true);
144-
}
107+
mousedownOnLine(event, hunk, line) {
108+
if (event.ctrlKey || event.metaKey) {
109+
this.selection.addOrSubtractLineSelection(line);
110+
} else if (event.shiftKey) {
111+
if (this.selection.getMode() === 'hunk') {
112+
this.selection.selectHunk(hunk, true);
145113
} else {
146-
if (type === 'hunk') {
147-
this.selection.selectHunk(hunk, false);
148-
} else {
149-
this.selection.selectLine(line, false);
150-
}
114+
this.selection.selectLine(line, true);
115+
}
116+
} else {
117+
if (event.detail === 1) {
118+
this.selection.selectLine(line, false);
119+
} else {
120+
this.selection.selectHunk(hunk, false);
151121
}
152-
await etch.update(this);
153122
}
123+
this.mouseSelectionInProgress = true;
124+
return etch.update(this);
154125
}
155126

156127
@autobind
157-
async mousemoveOnItem(event, hunk, line) {
158-
if (this.mouseSelection.started) {
159-
this.mouseSelection.dragged = true;
160-
if (this.mouseSelection.type === 'hunk') {
128+
mousemoveOnLine(event, hunk, line) {
129+
if (this.mouseSelectionInProgress) {
130+
if (this.selection.getMode() === 'hunk') {
161131
this.selection.selectHunk(hunk, true);
162132
} else {
163133
this.selection.selectLine(line, true);
164134
}
165-
await etch.update(this);
135+
return etch.update(this);
136+
} else {
137+
return null;
166138
}
167139
}
168140

169141
@autobind
170142
mouseup() {
171-
if (this.mouseSelection.dragged) {
172-
this.selection.coalesce();
173-
}
174-
this.mouseSelection = {
175-
started: false,
176-
dragged: false,
177-
type: this.mouseSelection.type,
178-
};
143+
this.mouseSelectionInProgress = false;
144+
this.selection.coalesce();
179145
}
180146

181147
togglePatchSelectionMode() {

lib/views/hunk-view.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ export default class HunkView {
1818
return etch.destroy(this);
1919
}
2020

21+
@autobind
22+
mousedownOnLine(event, line) {
23+
this.props.mousedownOnLine(event, this.props.hunk, line);
24+
}
25+
2126
@autobind
2227
mousemoveOnLine(event, line) {
2328
if (line !== this.lastMousemoveLine) {
2429
this.lastMousemoveLine = line;
25-
return this.props.mousemoveOnItem(event, this.props.hunk, line);
26-
} else {
27-
return null;
30+
this.props.mousemoveOnLine(event, this.props.hunk, line);
2831
}
2932
}
3033

@@ -40,7 +43,7 @@ export default class HunkView {
4043
return (
4144
<div className={`github-HunkView ${hunkModeClass} ${hunkSelectedClass}`}>
4245
<div className="github-HunkView-header"
43-
onmousedown={e => this.props.mousedownOnHunk(e)}>
46+
onmousedown={() => this.props.mousedownOnHeader()}>
4447
<span ref="header" className="github-HunkView-title">
4548
{this.props.hunk.getHeader().trim()} {this.props.hunk.getSectionHeading().trim()}
4649
</span>
@@ -57,8 +60,7 @@ export default class HunkView {
5760
line={line}
5861
isSelected={this.props.selectedLines.has(line)}
5962
registerLineElement={this.registerLineElement}
60-
dblclickOnItem={this.props.dblclickOnItem}
61-
mousedown={e => this.props.mousedownOnItem(e, this.props.hunk, line)}
63+
mousedown={this.mousedownOnLine}
6264
mousemove={this.mousemoveOnLine}
6365
/>,
6466
)}
@@ -98,7 +100,6 @@ class LineView {
98100
const lineSelectedClass = this.props.isSelected ? 'is-selected' : '';
99101
return (
100102
<div className={`github-HunkView-line ${lineSelectedClass} is-${line.getStatus()}`}
101-
ondblclick={event => this.props.dblclickOnItem(event)}
102103
onmousedown={event => this.props.mousedown(event, line)}
103104
onmousemove={event => this.props.mousemove(event, line)}>
104105
<div className="github-HunkView-lineNumber is-old">{oldLineNumber}</div>

0 commit comments

Comments
 (0)