Skip to content

Commit fe735f6

Browse files
author
david califf
committed
select mouse handler work, need cleaning
1 parent 8829438 commit fe735f6

File tree

3 files changed

+81
-11
lines changed

3 files changed

+81
-11
lines changed

Diff for: packages/selenium-ide/src/neo/components/TestRow/index.jsx

+46-4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class TestRow extends React.Component {
109109
static propTypes = {
110110
index: PropTypes.number,
111111
selected: PropTypes.bool,
112+
lastSelected: PropTypes.bool,
112113
className: PropTypes.string,
113114
status: PropTypes.string,
114115
readOnly: PropTypes.bool,
@@ -134,17 +135,23 @@ class TestRow extends React.Component {
134135
setContextMenu: PropTypes.func,
135136
level: PropTypes.number,
136137
scrollToLastPos: PropTypes.func,
138+
selectCommandByRange: PropTypes.func
137139
}
138140
componentDidMount() {
139141
if (this.props.selected) {
142+
console.log('focus')
143+
this.node.focus()
140144
this.props.scrollToLastPos()
141145
this.props.setSectionFocus('editor', () => {
146+
console.log('set section focus')
142147
this.node.focus()
143148
})
144149
}
145150
}
146151
componentDidUpdate(prevProps) {
147-
if (this.props.selected && !prevProps.selected) {
152+
console.log('should focus', this.props.selected, !prevProps.selected,this.props.lastSelected)
153+
if (this.props.selected && !prevProps.selected && this.props.lastSelected) {
154+
console.log('focus')
148155
this.scrollToRowIfNeeded(this.node)
149156
this.node.focus()
150157
this.props.setSectionFocus('editor', () => {
@@ -186,13 +193,19 @@ class TestRow extends React.Component {
186193
this.props.executeCommand(this.props.command)
187194
} else if (this.props.moveSelection && noModifiers && e.key === 'ArrowUp') {
188195
e.preventDefault()
196+
if(!e.shiftKey){
197+
this.props.clearAllSelectedCommands();
198+
}
189199
this.props.moveSelection(this.props.index - 1)
190200
} else if (
191201
this.props.moveSelection &&
192202
noModifiers &&
193203
e.key === 'ArrowDown'
194204
) {
195205
e.preventDefault()
206+
if(!e.shiftKey){
207+
this.props.clearAllSelectedCommands();
208+
}
196209
this.props.moveSelection(this.props.index + 1)
197210
} else if (!this.props.isPristine && onlyPrimary && key === 'X') {
198211
this.cut()
@@ -229,10 +242,38 @@ class TestRow extends React.Component {
229242
}
230243
}
231244
select(e) {
232-
if(e&& e.shiftKey===false){
245+
console.log('select event')
246+
if((e.type == 'contextmenu' || e.type == 'mousedown') && this.props.selected){
247+
return
248+
}
249+
if(e.type == 'click' && (e.shiftKey||this.props.lastSelected)){
250+
if(!e.shiftKey){
251+
this.props.clearAllSelectedCommands();
252+
this.props.select(this.props.command)
253+
}
254+
return;
255+
}
256+
if( e && e.shiftKey===false){
233257
this.props.clearAllSelectedCommands();
234258
}
235-
this.props.select(this.props.command)
259+
if(this.props.isPristine){
260+
this.props.clearAllSelectedCommands();
261+
}
262+
if(e && e.shiftKey){
263+
if(this.props.isPristine){
264+
this.props.clearAllSelectedCommands();
265+
this.props.select(this.props.command)
266+
}
267+
else{
268+
console.log('selectcommandbyrange')
269+
this.props.selectCommandByRange(this.props.command, this.props.index)
270+
this.props.select(this.props.command)
271+
}
272+
}
273+
else{
274+
console.log('select')
275+
this.props.select(this.props.command)
276+
}
236277
}
237278

238279
remove() {
@@ -368,13 +409,14 @@ class TestRow extends React.Component {
368409
: null
369410
}
370411
onClick={this.select}
412+
onFocus={this.select}
413+
onMouseDown={this.select}
371414
onDoubleClick={() => {
372415
this.props.executeCommand && this.props.singleCommandExecutionEnabled
373416
? this.props.executeCommand(this.props.command)
374417
: undefined
375418
}}
376419
onKeyDown={this.handleKeyDown.bind(this)}
377-
onFocus={this.select}
378420
style={{
379421
opacity: this.props.isDragging ? '0' : '1',
380422
}}

Diff for: packages/selenium-ide/src/neo/components/TestTable/index.jsx

+17
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default class TestTable extends React.Component {
4242
)
4343
this.commandLevels = []
4444
this.node = null
45+
this.selectCommandByRange = this.selectCommandByRange.bind(this);
4546
}
4647
static propTypes = {
4748
commands: MobxPropTypes.arrayOrObservableArray,
@@ -79,6 +80,19 @@ export default class TestTable extends React.Component {
7980
}
8081
}
8182
}
83+
selectCommandByRange(lastCommandSelected,index){
84+
if(this.props.selectedCommands.length > 0){
85+
let fromIndex = this.props.commands.indexOf(this.props.selectedCommands[0])
86+
fromIndex = fromIndex == -1 ? index : fromIndex
87+
const toIndex = index
88+
const from = fromIndex > toIndex ? toIndex : fromIndex;
89+
const to = fromIndex > toIndex ? fromIndex : toIndex;
90+
for(let i = from; i <= to; i++){
91+
console.log('adding')
92+
UiState.addToSelectedCommands(this.props.commands[i]);
93+
}
94+
}
95+
}
8296
handleScroll() {
8397
UiState.selectedTest.test.scrollY = this.node.scrollTop
8498
}
@@ -133,6 +147,7 @@ export default class TestTable extends React.Component {
133147
: ''
134148
)}
135149
selected= {this.props.selectedCommand === command.id || !!this.props.selectedCommands.find((cmd) => (cmd.id === command.id))}
150+
lastSelected = { this.props.selectedCommand === command.id }
136151
readOnly={PlaybackState.isPlaying}
137152
singleCommandExecutionEnabled={
138153
PlaybackState.isSingleCommandExecutionEnabled
@@ -147,6 +162,7 @@ export default class TestTable extends React.Component {
147162
scrollToLastPos={this.scrollToLastPos}
148163
isPristine={false}
149164
select={this.props.selectCommand}
165+
selectCommandByRange = {this.selectCommandByRange}
150166
startPlayingHere={PlaybackState.startPlaying}
151167
executeCommand={PlaybackState.playCommand}
152168
moveSelection={UiState.selectCommandByIndex}
@@ -177,6 +193,7 @@ export default class TestTable extends React.Component {
177193
moveSelection={UiState.selectCommandByIndex}
178194
pasteFromClipboard={UiState.pasteFromClipboard}
179195
setSectionFocus={UiState.setSectionFocus}
196+
clearAllSelectedCommands = {this.props.clearAllSelectedCommands}
180197
/>
181198
)
182199
: null}

Diff for: packages/selenium-ide/src/neo/stores/view/UiState.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,13 @@ class UiState {
202202
_test &&
203203
(_test !== this.displayedTest || suite !== this.selectedTest.suite)
204204
) {
205+
this.selectedCommands.clear()
205206
this.selectedTest = {
206207
test,
207208
suite,
208209
stack: stack >= 0 ? stack : undefined,
209210
}
211+
this.selectedCommands = this.selectedTest.test.selectedCommands;
210212
if (PlaybackState.isPlaying && !PlaybackState.paused) {
211213
this.selectCommand(undefined)
212214
} else if (_test && _test.commands.length) {
@@ -294,11 +296,11 @@ class UiState {
294296
PlaybackState.paused ||
295297
opts.isCommandTarget
296298
) {
299+
console.log('in selectCommand')
297300
if (this.selectedTest.test) {
298301
this.selectedTest.test.selectedCommand = command
299-
this.selectedTest.test.selectedCommands.push(command)
300-
this.selectedCommands.push(command);
301302
this.selectedCommand = command
303+
this.addToSelectedCommands(command)
302304
} else {
303305
this.selectedCommand = undefined
304306
}
@@ -311,6 +313,7 @@ class UiState {
311313
if (index >= 0 && index < test.commands.length) {
312314
this.selectCommand(test.commands[index], opts)
313315
} else if (index === test.commands.length) {
316+
this.clearAllSelectedCommands()
314317
this.selectCommand(this.pristineCommand, opts)
315318
}
316319
}
@@ -328,16 +331,24 @@ class UiState {
328331
}
329332
}
330333

331-
@action.bound addToSelectedCommands(command, index){
334+
@action.bound
335+
addToSelectedCommands(command, index){
336+
console.log('addToSelectedCommands');
332337
if (!PlaybackState.isPlaying || PlaybackState.paused) {
333338
if(command){
334-
command.index = index ? index : 0;
335-
if (!this.selectedCommands.find((c) => (c === command)))
336-
this.selectedCommands.push(command);
339+
//command.index = index ? index : 0;
340+
if(this.selectTest && this.selectedTest.test.commands.find((c) => (c === command))){
341+
if (this.selectedCommands.findIndex((c) => (c.id === command.id))=== -1){
342+
this.selectedCommands.push(command);
343+
}
344+
else{
345+
console.log('rejected')
346+
}
347+
}
337348
}
338349
}
350+
console.log(this.selectedCommands.length)
339351
}
340-
341352
@action.bound
342353
selectNextCommand(opts = { from: undefined, isCommandTarget: false }) {
343354
this.selectCommandByIndex(this.nextCommandIndex(opts.from), opts)

0 commit comments

Comments
 (0)