File tree Expand file tree Collapse file tree 4 files changed +34
-11
lines changed
packages/app/src/app/overmind Expand file tree Collapse file tree 4 files changed +34
-11
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import { listen } from 'codesandbox-api';
2323import FontFaceObserver from 'fontfaceobserver' ;
2424import { debounce } from 'lodash-es' ;
2525import * as childProcess from 'node-services/lib/child_process' ;
26+ import { Selection , TextOperation } from 'ot' ;
2627import io from 'socket.io-client' ;
2728
2829import { EXTENSIONS_LOCATION , VIM_EXTENSION_ID } from './constants' ;
@@ -118,6 +119,20 @@ export class VSCodeEffect {
118119 cancel ( ) : void ;
119120 } ;
120121
122+ public getTextOperationFromSelection (
123+ selection : [ number , number ] ,
124+ code : string
125+ ) {
126+ return new TextOperation (
127+ selection [ 0 ] ,
128+ code . substr ( selection [ 0 ] , selection [ 1 ] - selection [ 0 ] )
129+ ) ;
130+ }
131+
132+ public getRangeFromSelection ( selection : [ number , number ] ) {
133+ return new Selection . Range ( selection [ 0 ] , selection [ 1 ] ) ;
134+ }
135+
121136 public initialize ( options : VsCodeOptions ) {
122137 this . options = options ;
123138 this . controller = {
Original file line number Diff line number Diff line change @@ -10,10 +10,10 @@ import {
1010} from '@codesandbox/common/lib/types' ;
1111import { getTextOperation } from '@codesandbox/common/lib/utils/diff' ;
1212import { COMMENTS } from '@codesandbox/common/lib/utils/feature-flags' ;
13- import { hasPermission } from '@codesandbox/common/lib/utils/permission' ;
1413import { convertTypeToStatus } from '@codesandbox/common/lib/utils/notifications' ;
15- import { NotificationStatus } from '@codesandbox/notifications ' ;
14+ import { hasPermission } from '@codesandbox/common/lib/utils/permission ' ;
1615import { signInPageUrl } from '@codesandbox/common/lib/utils/url-generator' ;
16+ import { NotificationStatus } from '@codesandbox/notifications' ;
1717import {
1818 Authorization ,
1919 CollaboratorFragment ,
@@ -1408,6 +1408,19 @@ export const addComment: AsyncAction<{
14081408 return ;
14091409 }
14101410
1411+ /*
1412+ KEEP THIS: This will be used when we start implementing the backend. It will allow us to
1413+ keep track of at what position the comment should be displayed and also we use a TextOperation
1414+ to do the diffing of changes
1415+
1416+ const selection = state.editor.currentSelection;
1417+ const range = effects.vscode.getRangeFromSelection(selection);
1418+ const operation = effects.vscode.getTextOperationFromSelection(
1419+ selection,
1420+ state.editor.currentModule.code
1421+ );
1422+ */
1423+
14111424 const id = `${ comment } -${ username } ` ;
14121425 const optimisticComment = {
14131426 id,
Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ type State = {
7575 shouldDirectoryBeOpen : Derive < State , ( directoryShortid : string ) => boolean > ;
7676 currentDevToolsPosition : DevToolsTabPosition ;
7777 sessionFrozen : boolean ;
78+ currentSelection : [ number , number ] | null ;
7879 comments : {
7980 [ sandboxId : string ] : {
8081 [ commentId : string ] : Comment ;
@@ -87,6 +88,7 @@ type State = {
8788} ;
8889
8990export const state : State = {
91+ currentSelection : null ,
9092 comments : { } ,
9193 currentCommentId : null , // '5e5961e0c277a40fef1e391b',
9294 currentComment : ( { comments, currentSandbox, currentCommentId } ) => {
Original file line number Diff line number Diff line change @@ -166,15 +166,8 @@ export const onSelectionChanged: Action<any> = (
166166 { state, effects } ,
167167 selection
168168) => {
169- // console.log(
170- // 'SELECTION',
171- // selection.primary.selection[0],
172- // state.editor.currentModule.code.substr(
173- // selection.primary.selection[0],
174- // selection.primary.selection[1] - selection.primary.selection[0]
175- // ),
176- // state.editor.currentModule.code.length - selection.primary.selection[1]
177- // );
169+ state . editor . currentSelection = selection . primary ;
170+
178171 if ( ! state . live . roomInfo ) {
179172 return ;
180173 }
You can’t perform that action at this time.
0 commit comments