Skip to content

Commit cfe1fd5

Browse files
authored
Fix double clicking or clicking in output (#10819)
1 parent 5d0f58a commit cfe1fd5

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎news/2 Fixes/10749.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clicking or double clicking in output of a cell selects or gives focus to a cell. It should only affect the controls in the output.

‎src/datascience-ui/native-editor/nativeCell.tsx‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { actionCreators } from './redux/actions';
3030

3131
namespace CssConstants {
3232
export const CellOutputWrapper = 'cell-output-wrapper';
33+
export const CellOutputWrapperClass = `.${CellOutputWrapper}`;
34+
export const ImageButtonClass = '.image-button';
3335
}
3436

3537
interface INativeCellBaseProps {
@@ -180,8 +182,8 @@ export class NativeCell extends React.Component<INativeCellProps> {
180182
private onMouseClick = (ev: React.MouseEvent<HTMLDivElement>) => {
181183
if (ev.nativeEvent.target) {
182184
const elem = ev.nativeEvent.target as HTMLElement;
183-
if (!elem.className.includes || !elem.className.includes('image-button')) {
184-
// Not a click on an button in a toolbar, select the cell.
185+
if (!elem.closest(CssConstants.ImageButtonClass) && !elem.closest(CssConstants.CellOutputWrapperClass)) {
186+
// Not a click on an button in a toolbar or in output, select the cell.
185187
ev.stopPropagation();
186188
this.lastKeyPressed = undefined;
187189
this.props.selectCell(this.cellId);
@@ -190,9 +192,12 @@ export class NativeCell extends React.Component<INativeCellProps> {
190192
};
191193

192194
private onMouseDoubleClick = (ev: React.MouseEvent<HTMLDivElement>) => {
193-
// When we receive double click, propagate upwards. Might change our state
194-
ev.stopPropagation();
195-
this.props.focusCell(this.cellId, CursorPos.Current);
195+
const elem = ev.nativeEvent.target as HTMLElement;
196+
if (!elem.closest(CssConstants.ImageButtonClass) && !elem.closest(CssConstants.CellOutputWrapperClass)) {
197+
// When we receive double click, propagate upwards. Might change our state
198+
ev.stopPropagation();
199+
this.props.focusCell(this.cellId, CursorPos.Current);
200+
}
196201
};
197202

198203
private shouldRenderCodeEditor = (): boolean => {
@@ -707,7 +712,7 @@ export class NativeCell extends React.Component<INativeCellProps> {
707712
private focusInOutput(): boolean {
708713
const focusedElement = document.activeElement as HTMLElement;
709714
if (focusedElement) {
710-
return focusedElement.closest(`.${CssConstants.CellOutputWrapper}`) !== null;
715+
return focusedElement.closest(CssConstants.CellOutputWrapperClass) !== null;
711716
}
712717
return false;
713718
}

0 commit comments

Comments
 (0)