@@ -30,9 +30,6 @@ import {reportErrorThroughHoneyBadger} from 'src/shared/utils/errors'
3030// Utils
3131import { event } from 'src/cloud/utils/reporting'
3232
33- const ICON_SYNC_CLASSNAME = 'composition-sync'
34- export const ICON_SYNC_ID = 'schema-composition-sync-icon'
35-
3633// hardcoded in LSP
3734const COMPOSITION_YIELD = '_editor_composition'
3835const COMPOSITION_INIT_LINE = 1
@@ -137,24 +134,6 @@ class LspConnectionManager {
137134 } )
138135 }
139136
140- _setEditorSyncToggle ( ) {
141- setTimeout ( ( ) => {
142- const clickableInvisibleDiv = document . getElementById ( ICON_SYNC_ID )
143- // add listeners
144- clickableInvisibleDiv . removeEventListener ( 'click' , ( ) =>
145- this . _setSessionSync ( ! this . _session . composition . synced )
146- ) // may have existing
147- clickableInvisibleDiv . addEventListener ( 'click' , ( ) => {
148- event ( 'Toggled Flux Sync in editor' , {
149- active : `${ ! this . _session . composition . synced } ` ,
150- } )
151- this . _setSessionSync ( ! this . _session . composition . synced )
152- } )
153-
154- this . _alignInvisibleDivToEditorBlock ( )
155- } , 1000 )
156- }
157-
158137 _editorChangeIsFromLsp ( change ) {
159138 return change . text ?. includes ( '|> yield(name: "_editor_composition")' )
160139 }
@@ -188,84 +167,49 @@ class LspConnectionManager {
188167 } )
189168 }
190169
191- _alignInvisibleDivToEditorBlock ( ) {
192- // elements in monaco-editor. positioned by editor.
193- const syncIcons = document . getElementsByClassName ( ICON_SYNC_CLASSNAME )
194-
195- // UI elements we control
196- const clickableInvisibleDiv = document . getElementById ( ICON_SYNC_ID )
197- if ( ! syncIcons . length || ! clickableInvisibleDiv ) {
198- return
170+ _compositionSyncStyle ( startLine : number , endLine : number , synced : boolean ) {
171+ const classNamePrefix = synced
172+ ? 'composition-sync--on'
173+ : 'composition-sync--off'
174+
175+ // Customize the full width of Monaco editor margin using API `marginClassName`
176+ // https://github.com/microsoft/monaco-editor/blob/35eb0ef/website/typedoc/monaco.d.ts#L1533
177+ const startLineStyle = {
178+ range : new MonacoTypes . Range ( startLine , 1 , startLine , 1 ) ,
179+ options : {
180+ marginClassName : `${ classNamePrefix } --first` ,
181+ } ,
199182 }
200-
201- const [ upperIcon ] = syncIcons
202- let [ , lowerIcon ] = syncIcons
203- if ( ! lowerIcon ) {
204- lowerIcon = upperIcon
183+ const middleLinesStyle = {
184+ range : new MonacoTypes . Range ( startLine , 1 , endLine , 1 ) ,
185+ options : {
186+ marginClassName : classNamePrefix ,
187+ } ,
205188 }
206- const compositionBlock = this . _getCompositionBlockLines ( )
207- if ( ! compositionBlock ) {
208- return
189+ const endLineStyle = {
190+ range : new MonacoTypes . Range ( endLine , 1 , endLine , 1 ) ,
191+ options : {
192+ marginClassName : `${ classNamePrefix } --last` ,
193+ } ,
209194 }
210- const { startLine, endLine} = compositionBlock
211-
212- // move div to match monaco-editor coordinates
213- clickableInvisibleDiv . style . top = ( ( upperIcon as any ) . offsetTop || 0 ) + 'px'
214- const height =
215- ( ( lowerIcon as any ) . offsetHeight || 0 ) * ( endLine - startLine + 1 ) +
216- ( ( upperIcon as any ) . offsetTop || 0 )
217- clickableInvisibleDiv . style . height = height + 'px'
218- // width size is always the same, defined in classname "sync-bar"
195+ return [ startLineStyle , middleLinesStyle , endLineStyle ]
219196 }
220197
221198 _setEditorBlockStyle ( schema : SchemaSelection = this . _session ) {
222199 const compositionBlock = this . _getCompositionBlockLines ( )
223200
224- const startLineStyle = [
225- {
226- range : new MonacoTypes . Range (
227- compositionBlock ?. startLine ,
228- 1 ,
229- compositionBlock ?. startLine ,
230- 1
231- ) ,
232- options : {
233- linesDecorationsClassName : ICON_SYNC_CLASSNAME ,
234- } ,
235- } ,
236- ]
237- const endLineStyle = [
238- {
239- range : new MonacoTypes . Range (
240- compositionBlock ?. endLine ,
241- 1 ,
242- compositionBlock ?. endLine ,
243- 1
244- ) ,
245- options : {
246- linesDecorationsClassName : ICON_SYNC_CLASSNAME ,
247- } ,
248- } ,
249- ]
250-
251201 const removeAllStyles = ! compositionBlock || schema . composition . diverged
252202
203+ const compositionSyncStyle = this . _compositionSyncStyle (
204+ compositionBlock ?. startLine ,
205+ compositionBlock ?. endLine ,
206+ schema . composition . synced
207+ )
208+
253209 this . _compositionStyle = this . _editor . deltaDecorations (
254210 this . _compositionStyle ,
255- removeAllStyles ? [ ] : startLineStyle . concat ( endLineStyle )
211+ removeAllStyles ? [ ] : compositionSyncStyle
256212 )
257-
258- this . _alignInvisibleDivToEditorBlock ( )
259- const clickableInvisibleDiv = document . getElementById ( ICON_SYNC_ID )
260- clickableInvisibleDiv . className = schema . composition . synced
261- ? 'sync-bar sync-bar--on'
262- : 'sync-bar sync-bar--off'
263-
264- if ( removeAllStyles ) {
265- clickableInvisibleDiv . style . display = 'none'
266- } else {
267- clickableInvisibleDiv . style . display = 'block'
268- }
269213 }
270214
271215 // XXX: wiedld (25 Aug 2022) - handling the absence of a middleware listener
@@ -409,7 +353,6 @@ class LspConnectionManager {
409353
410354 _initCompositionHandlers ( ) {
411355 // handlers to trigger end composition
412- this . _setEditorSyncToggle ( )
413356 this . _setEditorIrreversibleExit ( )
414357
415358 // XXX: wiedld (25 Aug 2022) - eventually, this should be from the LSP response.
0 commit comments