@@ -146,39 +146,29 @@ define(function (require, exports, module) {
146146
147147 /**
148148 * To move the cursor to the color text and display the color quick edit
149- * @param {CodeMirror } codeMirror the codemirror instance
149+ * @param {Editor } editor the codemirror instance
150150 * @param {Number } lineNumber the line number that is clicked
151- * @param {String } gutter the gutter name
151+ * @param {string } colorValue the color value clicked
152+ * @param {boolean } dontEdit if set to true,color editor won't be opened
152153 */
153- function colorIconClicked ( codeMirror , lineNumber , gutter ) {
154- const editor = EditorManager . getActiveEditor ( ) ;
155-
156- if ( gutter === GUTTER_NAME ) {
157-
158- let colorValue ;
159-
160- for ( let i of codeMirror . colorGutters ) {
161- if ( i . lineNumber === lineNumber ) {
162- colorValue = i . colorValues [ 0 ] ;
163- }
164- }
165-
166- const lineText = editor . getLine ( lineNumber ) ;
167- const colorIndex = lineText . indexOf ( colorValue ) ;
168-
169- if ( colorIndex !== - 1 ) {
170- // Place cursor at the start of the color text
171- if ( editor ) {
172- editor . setCursorPos ( lineNumber , colorIndex ) ;
154+ function _colorIconClicked ( editor , lineNumber , colorValue , dontEdit ) {
155+ const lineText = editor . getLine ( lineNumber ) ;
156+ const colorIndex = lineText . indexOf ( colorValue ) ;
157+ const currentPos = editor . getCursorPos ( false , "start" ) ;
158+ if ( ! ( currentPos . line === lineNumber && currentPos . ch === colorIndex ) ) {
159+ editor . setCursorPos ( lineNumber , colorIndex ) ;
160+ editor . focus ( ) ;
161+ }
173162
174- // Added a 50ms delay with setTimeout to make sure the quick edit menu toggles correctly.
175- // Without it, closing the menu trigger text selection, reopening the menu.
176- setTimeout ( ( ) => {
177- CommandManager . execute ( Commands . TOGGLE_QUICK_EDIT ) ;
178- } , 50 ) ;
179- }
180- }
163+ if ( dontEdit ) {
164+ return ;
181165 }
166+
167+ // Added a 50ms delay with setTimeout to make sure the quick edit menu toggles correctly.
168+ // Without it, closing the menu trigger text selection, reopening the menu.
169+ setTimeout ( ( ) => {
170+ CommandManager . execute ( Commands . TOGGLE_QUICK_EDIT ) ;
171+ } , 50 ) ;
182172 }
183173
184174 /**
@@ -194,24 +184,24 @@ define(function (require, exports, module) {
194184 editor . clearGutter ( GUTTER_NAME ) ; // clear color markers
195185 _addDummyGutterMarkerIfNotExist ( editor , editor . getCursorPos ( ) . line ) ;
196186
197- cm . on ( "gutterClick" , ( codeMirror , lineNumber , gutter ) => {
198- colorIconClicked ( codeMirror , lineNumber , gutter ) ;
199- } ) ;
200-
201187 // Only add markers if enabled
202188 if ( enabled ) {
203189 cm . colorGutters = _ . sortBy ( _results , "lineNumber" ) ;
204190
205191 cm . colorGutters . forEach ( function ( obj ) {
206192 let $marker ;
207-
208193 if ( obj . colorValues . length === 1 ) {
209194 // Single color preview
210195 $marker = $ ( "<i>" )
211196 . addClass ( "ico-cssColorPreview" )
212197 . css ( 'background-color' , obj . colorValues [ 0 ] ) ;
213198
214199 editor . setGutterMarker ( obj . lineNumber , GUTTER_NAME , $marker [ 0 ] ) ;
200+ $marker . click ( ( event ) => {
201+ event . preventDefault ( ) ;
202+ event . stopPropagation ( ) ;
203+ _colorIconClicked ( editor , obj . lineNumber , obj . colorValues [ 0 ] , false ) ;
204+ } ) ;
215205 } else {
216206 // Multiple colors preview
217207 $marker = $ ( "<div>" ) . addClass ( "ico-multiple-cssColorPreview" ) ;
@@ -232,6 +222,11 @@ define(function (require, exports, module) {
232222 'background-color' : color ,
233223 ...positions [ index ]
234224 } ) ;
225+ $colorBox . click ( ( event ) => {
226+ event . preventDefault ( ) ;
227+ event . stopPropagation ( ) ;
228+ _colorIconClicked ( editor , obj . lineNumber , color , false ) ;
229+ } ) ;
235230 $marker . append ( $colorBox ) ;
236231 }
237232 } ) ;
0 commit comments