@@ -320,33 +320,10 @@ window.editor = editor
320320var inlineAttach = inlineAttachment . editors . codemirror4 . attach ( editor )
321321defaultTextHeight = parseInt ( $ ( '.CodeMirror' ) . css ( 'line-height' ) )
322322
323- var selection = null
324-
325323function updateStatusBar ( ) {
326324 if ( ! editorInstance . statusBar ) return
327325 var cursor = editor . getCursor ( )
328326 var cursorText = 'Line ' + ( cursor . line + 1 ) + ', Columns ' + ( cursor . ch + 1 )
329- if ( selection ) {
330- var anchor = selection . anchor
331- var head = selection . head
332- var start = head . line <= anchor . line ? head : anchor
333- var end = head . line >= anchor . line ? head : anchor
334- var selectionText = ' — Selected '
335- var selectionCharCount = Math . abs ( head . ch - anchor . ch )
336- // borrow from brackets EditorStatusBar.js
337- if ( start . line !== end . line ) {
338- var lines = end . line - start . line + 1
339- if ( end . ch === 0 ) {
340- lines --
341- }
342- selectionText += lines + ' lines'
343- } else if ( selectionCharCount > 0 ) {
344- selectionText += selectionCharCount + ' columns'
345- }
346- if ( start . line !== end . line || selectionCharCount > 0 ) {
347- cursorText += selectionText
348- }
349- }
350327 editorInstance . statusCursor . text ( cursorText )
351328 var fileText = ' — ' + editor . lineCount ( ) + ' Lines'
352329 editorInstance . statusFile . text ( fileText )
@@ -2726,9 +2703,38 @@ editorInstance.on('cursorActivity', function (cm) {
27262703 updateStatusBar ( )
27272704 cursorActivity ( )
27282705} )
2706+
2707+ editorInstance . on ( 'beforeSelectionChange' , updateStatusBar )
27292708editorInstance . on ( 'beforeSelectionChange' , function ( doc , selections ) {
2730- if ( selections ) { selection = selections . ranges [ 0 ] } else { selection = null }
2731- updateStatusBar ( )
2709+ // check selection and whether the statusbar has added
2710+ if ( selections && editorInstance . statusSelection ) {
2711+ const selection = selections . ranges [ 0 ]
2712+
2713+ const anchor = selection . anchor
2714+ const head = selection . head
2715+ const start = head . line <= anchor . line ? head : anchor
2716+ const end = head . line >= anchor . line ? head : anchor
2717+ const selectionCharCount = Math . abs ( head . ch - anchor . ch )
2718+
2719+ let selectionText = ' — Selected '
2720+
2721+ // borrow from brackets EditorStatusBar.js
2722+ if ( start . line !== end . line ) {
2723+ var lines = end . line - start . line + 1
2724+ if ( end . ch === 0 ) {
2725+ lines --
2726+ }
2727+ selectionText += lines + ' lines'
2728+ } else if ( selectionCharCount > 0 ) {
2729+ selectionText += selectionCharCount + ' columns'
2730+ }
2731+
2732+ if ( start . line !== end . line || selectionCharCount > 0 ) {
2733+ editorInstance . statusSelection . text ( selectionText )
2734+ } else {
2735+ editorInstance . statusSelection . text ( '' )
2736+ }
2737+ }
27322738} )
27332739
27342740var cursorActivity = _ . debounce ( cursorActivityInner , cursorActivityDebounce )
0 commit comments