@@ -141,7 +141,7 @@ module.exports = PhpDebug =
141141
142142 @GlobalContext .onStackChange (codepoint) =>
143143 @ doCodePoint (codepoint)
144-
144+
145145 @GlobalContext .onSocketError () =>
146146 @ toggleDebugging ()
147147
@@ -172,19 +172,19 @@ module.exports = PhpDebug =
172172 for breakpoint in event .removed
173173 if breakpoint .getMarker ()
174174 breakpoint .getMarker ().destroy ()
175-
175+
176176 atom .workspace .observeTextEditors (editor) =>
177177 if (atom .config .get (' php-debug.GutterBreakpointToggle' ))
178178 @ createGutter editor
179- else
179+ else
180180 for breakpoint in @GlobalContext .getBreakpoints ()
181181 if breakpoint .getPath () == editor .getPath ()
182182 marker = @ addBreakpointMarker (breakpoint .getLine (), editor)
183183 breakpoint .setMarker (marker)
184-
184+
185185 atom .config .observe " php-debug.GutterBreakpointToggle" , (newValue ) =>
186- @ createGutters newValue
187-
186+ @ createGutters newValue
187+
188188 atom .config .observe " php-debug.GutterPosition" , (newValue ) =>
189189 @ createGutters atom .config .get (' php-debug.GutterBreakpointToggle' ),true
190190
@@ -193,6 +193,8 @@ module.exports = PhpDebug =
193193 command : ' php-debug:addWatch'
194194 shouldDisplay : =>
195195 editor = atom .workspace .getActivePaneItem ()
196+ if (! editor || ! editor .getSelectedText )
197+ return false
196198 expression = editor ? .getSelectedText ()
197199 if !! expression then return true else return false
198200 },
@@ -202,6 +204,7 @@ module.exports = PhpDebug =
202204 shouldDisplay : =>
203205 editor = atom .workspace .getActivePaneItem ()
204206 return false if ! editor
207+ return false if ! editor .getSelectedBufferRange
205208 range = editor .getSelectedBufferRange ()
206209 path = editor .getPath ()
207210 line = range .getRows ()[0 ]+ 1
@@ -242,7 +245,7 @@ module.exports = PhpDebug =
242245 filepath = point .getPath ()
243246
244247 filepath = helpers .remotePathToLocal (filepath)
245-
248+
246249 atom .workspace .open (filepath,{searchAllPanes : true , activatePane : true }).then (editor) =>
247250 if @currentCodePointDecoration
248251 @currentCodePointDecoration .destroy ()
@@ -258,12 +261,12 @@ module.exports = PhpDebug =
258261 addBreakpointMarker : (line , editor ) ->
259262 gutter = editor .gutterWithName (" php-debug-gutter" )
260263 range = [[line- 1 , 0 ], [line- 1 , 0 ]]
261-
264+
262265 marker = new BreakpointMarker (editor,range,gutter)
263266 marker .decorate ()
264267
265268 return marker
266-
269+
267270
268271 breakpointSettings : ->
269272 BreakpointSettingsView = require ' ./breakpoint/breakpoint-settings-view'
@@ -278,54 +281,55 @@ module.exports = PhpDebug =
278281 break
279282 @settingsView = new BreakpointSettingsView ({breakpoint : breakpoint,context : @GlobalContext })
280283 @settingsView .attach ()
281-
284+
282285 createGutters : (create ,recreate ) ->
283286 editors = atom .workspace .getTextEditors ()
284287 for editor in editors
285- if editor
286- if create == false
288+ if (! editor || ! editor .gutterWithName )
289+ return
290+ if create == false
291+ if (editor ? .gutterWithName (' php-debug-gutter' ) != null )
292+ gutter = editor ? .gutterWithName (' php-debug-gutter' )
293+ gutter ? .destroy ()
294+ else
295+ if recreate
287296 if (editor ? .gutterWithName (' php-debug-gutter' ) != null )
288297 gutter = editor ? .gutterWithName (' php-debug-gutter' )
289298 gutter ? .destroy ()
290- else
291- if recreate
292- if (editor ? .gutterWithName (' php-debug-gutter' ) != null )
293- gutter = editor ? .gutterWithName (' php-debug-gutter' )
294- gutter ? .destroy ()
295- if (editor ? .gutterWithName (' php-debug-gutter' ) == null )
296- @ createGutter (editor)
297-
299+ if (editor ? .gutterWithName (' php-debug-gutter' ) == null )
300+ @ createGutter (editor)
301+
298302 createGutter : (editor ) ->
299303 if (! editor)
300304 editor = atom .workspace .getActivePaneItem ()
301305
302306 if (! editor || ! editor .gutterWithName )
303307 return
304-
308+
305309 gutterEnabled = atom .config .get (' php-debug.GutterBreakpointToggle' )
306310 if (! gutterEnabled)
307311 return
308-
312+
309313 gutterPosition = atom .config .get (' php-debug.GutterPosition' )
310314 if gutterPosition == " Left"
311315 priority = - 200
312316 else
313317 priority = 200
314-
318+
315319 if (editor .gutterWithName (' php-debug-gutter' ) != null )
316320 @gutter = editor .gutterWithName (' php-debug-gutter' )
317321 return
318322 else
319323 @gutter = editor ? .gutterContainer .addGutter {name : ' php-debug-gutter' , priority : priority}
320-
324+
321325 view = atom .views .getView editor
322326 domNode = atom .views .getView @gutter
323327 $ (domNode).unbind ' click.phpDebug'
324328 $ (domNode).bind ' click.phpDebug' , (event ) =>
325329 clickedScreenRow = view .component .screenPositionForMouseEvent (event).row
326330 clickedBufferRow = editor .bufferRowForScreenRow (clickedScreenRow)+ 1
327331 @ toggleBreakpoint clickedBufferRow
328-
332+
329333 if @gutter
330334 for breakpoint in @GlobalContext .getBreakpoints ()
331335 if breakpoint .getPath () == editor .getPath ()
@@ -350,9 +354,9 @@ module.exports = PhpDebug =
350354 @ getUnifiedView ().setVisible (false )
351355 @statusView ? .setActive (false )
352356 return
353-
357+
354358 @ createGutter ()
355-
359+
356360 else
357361 @ getUnifiedView ().setVisible (false )
358362 @statusView ? .setActive (false )
0 commit comments