@@ -119,7 +119,7 @@ export class CursorController implements UiLifeCycles, Printable {
119119
120120 public readonly focus = new ValueSyncStore < boolean > ( false ) ;
121121
122- private readonly onFocus = ( ) : void => {
122+ private readonly onFocus = ( event : Event ) : void => {
123123 this . focus . next ( true ) ;
124124 } ;
125125
@@ -129,15 +129,16 @@ export class CursorController implements UiLifeCycles, Printable {
129129
130130 private x = 0 ;
131131 private y = 0 ;
132- private mouseDown : boolean = false ;
132+ public readonly mouseDown = new ValueSyncStore < boolean > ( false ) ;
133133
134134 private readonly onMouseDown = ( ev : MouseEvent ) : void => {
135+ if ( ! this . focus . value && this . opts . txt . editor . hasCursor ( ) ) return ;
135136 const { clientX, clientY} = ev ;
136137 this . x = clientX ;
137138 this . y = clientY ;
138139 switch ( ev . detail ) {
139140 case 1 : {
140- this . mouseDown = false ;
141+ this . mouseDown . next ( false ) ;
141142 const at = this . posAtPoint ( clientX , clientY ) ;
142143 if ( at === - 1 ) return ;
143144 this . selAnchor = at ;
@@ -150,32 +151,32 @@ export class CursorController implements UiLifeCycles, Printable {
150151 ev . preventDefault ( ) ;
151152 et . cursor ( { at, edge : 'new' } ) ;
152153 } else {
153- this . mouseDown = true ;
154+ this . mouseDown . next ( true ) ;
154155 ev . preventDefault ( ) ;
155156 et . cursor ( { at} ) ;
156157 }
157158 break ;
158159 }
159160 case 2 :
160- this . mouseDown = false ;
161+ this . mouseDown . next ( false ) ;
161162 ev . preventDefault ( ) ;
162163 this . opts . et . cursor ( { unit : 'word' } ) ;
163164 break ;
164165 case 3 :
165- this . mouseDown = false ;
166+ this . mouseDown . next ( false ) ;
166167 ev . preventDefault ( ) ;
167168 this . opts . et . cursor ( { unit : 'block' } ) ;
168169 break ;
169170 case 4 :
170- this . mouseDown = false ;
171+ this . mouseDown . next ( false ) ;
171172 ev . preventDefault ( ) ;
172173 this . opts . et . cursor ( { unit : 'all' } ) ;
173174 break ;
174175 }
175176 } ;
176177
177178 private readonly onMouseMove = ( ev : MouseEvent ) : void => {
178- if ( ! this . mouseDown ) return ;
179+ if ( ! this . mouseDown . value ) return ;
179180 const at = this . selAnchor ;
180181 if ( at < 0 ) return ;
181182 const { clientX, clientY} = ev ;
@@ -190,7 +191,7 @@ export class CursorController implements UiLifeCycles, Printable {
190191 } ;
191192
192193 private readonly onMouseUp = ( ev : MouseEvent ) : void => {
193- this . mouseDown = false ;
194+ this . mouseDown . next ( false ) ;
194195 } ;
195196
196197 private onKeyDown = ( event : KeyboardEvent ) : void => {
@@ -242,6 +243,6 @@ export class CursorController implements UiLifeCycles, Printable {
242243 /** ----------------------------------------------------- {@link Printable} */
243244
244245 public toString ( tab ?: string ) : string {
245- return `cursor { focus: ${ this . focus . value } , x: ${ this . x } , y: ${ this . y } , mouseDown: ${ this . mouseDown } }` ;
246+ return `cursor { focus: ${ this . focus . value } , x: ${ this . x } , y: ${ this . y } , mouseDown: ${ this . mouseDown . value } }` ;
246247 }
247248}
0 commit comments