Skip to content

Commit ab4e8c6

Browse files
committed
Change how we update the user seelection on model change code
1 parent a8d8282 commit ab4e8c6

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

packages/app/src/app/overmind/effects/vscode/ModelsHandler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
EditorSelection,
44
Module,
55
Sandbox,
6+
UserSelection,
67
} from '@codesandbox/common/lib/types';
78
import { indexToLineAndColumn } from 'app/overmind/utils/common';
89
import { actions, dispatch } from 'codesandbox-api';
@@ -33,6 +34,8 @@ export type OnFileChangeData = {
3334
model: any;
3435
};
3536

37+
export type onSelectionChangeData = UserSelection;
38+
3639
export type OnOperationAppliedData = {
3740
moduleShortid: string;
3841
title: string;
@@ -413,7 +416,10 @@ export class ModelsHandler {
413416
if (this.nameTagTimeouts[decorationId]) {
414417
clearTimeout(this.nameTagTimeouts[decorationId]);
415418
}
416-
if (showNameTag) {
419+
// We don't want to show the nametag when the cursor changed, because
420+
// another user changed the code on top of it. Otherwise it would get
421+
// messy very fast.
422+
if (showNameTag && selection.source !== 'modelChange') {
417423
const decoration = model.deltaDecorations(
418424
[],
419425
[

packages/app/src/app/overmind/effects/vscode/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
ModelsHandler,
3636
OnFileChangeData,
3737
OnOperationAppliedData,
38+
onSelectionChangeData,
3839
} from './ModelsHandler';
3940
import SandboxFsSync from './SandboxFsSync';
4041
import { getSelection } from './utils';
@@ -47,7 +48,7 @@ export type VsCodeOptions = {
4748
getSandboxFs: () => SandboxFs;
4849
onCodeChange: (data: OnFileChangeData) => void;
4950
onOperationApplied: (data: OnOperationAppliedData) => void;
50-
onSelectionChange: (selection: any) => void;
51+
onSelectionChange: (selection: onSelectionChangeData) => void;
5152
reaction: Reaction;
5253
// These two should be removed
5354
getSignal: any;
@@ -869,20 +870,14 @@ export class VSCodeEffect {
869870
this.modelSelectionListener = activeEditor.onDidChangeCursorSelection(
870871
selectionChange => {
871872
const lines = activeEditor.getModel().getLinesContent() || [];
872-
const data = {
873+
const data: onSelectionChangeData = {
873874
primary: getSelection(lines, selectionChange.selection),
874875
secondary: selectionChange.secondarySelections.map(s =>
875876
getSelection(lines, s)
876877
),
878+
source: selectionChange.source,
877879
};
878880

879-
if (selectionChange.source === 'modelChange') {
880-
// Don't update the cursor pos on model change, as it will
881-
// be updated automatically by vscode (they handle cursor
882-
// location changes really well)
883-
return;
884-
}
885-
886881
if (
887882
selectionChange.reason === 3 ||
888883
/* alt + shift + arrow keys */ selectionChange.source ===

packages/common/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ export type Selection = {
466466
export type UserSelection = {
467467
primary: Selection;
468468
secondary: Selection[];
469+
source: string;
469470
};
470471

471472
export type EditorSelection = {

0 commit comments

Comments
 (0)