4
4
import { CompositeDisposable , Disposable } from 'atom' ;
5
5
6
6
import etch from 'etch' ;
7
- import cx from 'classnames' ;
8
7
import { autobind } from 'core-decorators' ;
9
8
10
9
import HunkView from './hunk-view' ;
@@ -15,7 +14,7 @@ export default class FilePatchView {
15
14
this . props = props ;
16
15
this . selection = new FilePatchSelection ( this . props . hunks ) ;
17
16
this . fontSize = atom . config . get ( 'editor.fontSize' ) ;
18
- this . mouseSelection = { started : false , dragged : false , type : 'line' } ;
17
+ this . mouseSelectionInProgress = false ;
19
18
20
19
window . addEventListener ( 'mouseup' , this . mouseup ) ;
21
20
this . disposables = new CompositeDisposable ( ) ;
@@ -63,10 +62,9 @@ export default class FilePatchView {
63
62
const headHunk = this . selection . getHeadHunk ( ) ;
64
63
const headLine = this . selection . getHeadLine ( ) ;
65
64
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' ;
68
66
return (
69
- < div className = { cx ( ' github-FilePatchView' , { 'is-staged' : ! unstaged , 'is-unstaged' : unstaged } ) } tabIndex = "-1"
67
+ < div className = " github-FilePatchView" tabIndex = "-1"
70
68
onmouseup = { this . mouseup }
71
69
style = { `font-size: ${ this . fontSize } px` } >
72
70
{ this . props . hunks . map ( hunk => {
@@ -87,10 +85,9 @@ export default class FilePatchView {
87
85
selectedLines = { selectedLines }
88
86
headLine = { headLine }
89
87
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 }
94
91
didClickStageButton = { ( ) => this . didClickStageButtonForHunk ( hunk ) }
95
92
registerView = { this . props . registerHunkView }
96
93
/>
@@ -100,82 +97,51 @@ export default class FilePatchView {
100
97
) ;
101
98
}
102
99
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 ) ;
121
104
}
122
105
123
106
@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 ) ;
145
113
} 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 ) ;
151
121
}
152
- await etch . update ( this ) ;
153
122
}
123
+ this . mouseSelectionInProgress = true ;
124
+ return etch . update ( this ) ;
154
125
}
155
126
156
127
@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' ) {
161
131
this . selection . selectHunk ( hunk , true ) ;
162
132
} else {
163
133
this . selection . selectLine ( line , true ) ;
164
134
}
165
- await etch . update ( this ) ;
135
+ return etch . update ( this ) ;
136
+ } else {
137
+ return null ;
166
138
}
167
139
}
168
140
169
141
@autobind
170
142
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 ( ) ;
179
145
}
180
146
181
147
togglePatchSelectionMode ( ) {
0 commit comments