@@ -29,39 +29,26 @@ export default class SelectionCountView {
2929
3030 destroy ( ) {
3131 this . activeItemSubscription . dispose ( ) ;
32- if ( this . selectionSubscription ) {
33- this . selectionSubscription . dispose ( ) ;
34- }
35- if ( this . configSubscription ) {
36- this . configSubscription . dispose ( ) ;
37- }
32+ this . selectionSubscription ?. dispose ( ) ;
33+ this . configSubscription ?. dispose ( ) ;
3834 this . tooltipDisposable . dispose ( ) ;
3935 }
4036
4137 subscribeToConfig ( ) {
42- if ( this . configSubscription ) {
43- this . configSubscription . dispose ( ) ;
44- }
45- this . configSubscription = atom . config . observe (
46- 'status-bar.selectionCountFormat' ,
47- value => {
48- this . formatString = value ? value : '(%L, %C)' ;
49- this . scheduleUpdateCount ( ) ;
50- }
38+ this . configSubscription ?. dispose ( ) ;
39+ this . configSubscription = atom . config . observe ( 'status-bar.selectionCountFormat' ,
40+ value => {
41+ this . formatString = value ? value : '(%L, %C)' ;
42+ this . scheduleUpdateCount ( ) ;
43+ }
5144 ) ;
5245 }
5346
5447 subscribeToActiveTextEditor ( ) {
55- if ( this . selectionSubscription ) {
56- this . selectionSubscription . dispose ( ) ;
57- }
48+ this . selectionSubscription ?. dispose ( ) ;
5849 const activeEditor = this . getActiveTextEditor ( ) ;
59- const selectionsMarkerLayer = activeEditor
60- ? activeEditor . selectionsMarkerLayer
61- : undefined ;
62- this . selectionSubscription = selectionsMarkerLayer
63- ? selectionsMarkerLayer . onDidUpdate ( this . scheduleUpdateCount . bind ( this ) )
64- : undefined ;
50+ const selectionsMarkerLayer = activeEditor ?. selectionsMarkerLayer ;
51+ this . selectionSubscription = selectionsMarkerLayer ?. onDidUpdate ( this . scheduleUpdateCount . bind ( this ) ) ;
6552 this . scheduleUpdateCount ( ) ;
6653 }
6754
@@ -80,22 +67,11 @@ export default class SelectionCountView {
8067 }
8168
8269 updateCount ( ) {
83- // optional chaining rewritten:
84- let count , range ;
8570 const editor = atom . workspace . getActiveTextEditor ( ) ;
86- if ( editor ) {
87- count = editor . getSelectedText ( ) . length ;
88- range = editor . getSelectedBufferRange ( ) ;
89- }
90-
91- let lineCount , rangeEndColumn ;
92- if ( range ) {
93- lineCount = range . getRowCount ( ) ;
94- rangeEndColumn = range . end . column ;
95- }
96- if ( rangeEndColumn === 0 ) {
97- lineCount -= 1 ;
98- }
71+ const count = editor ?. getSelectedText ( ) . length ;
72+ const range = editor ?. getSelectedBufferRange ( ) ;
73+ let lineCount = range ?. getRowCount ( ) ;
74+ if ( range ?. end . column === 0 ) { lineCount -= 1 ; }
9975 if ( count > 0 ) {
10076 this . element . textContent = this . formatString
10177 . replace ( '%L' , lineCount )
0 commit comments