@@ -72,6 +72,8 @@ export class TextScanner extends EventDispatcher {
72
72
/** @type {?string } */
73
73
this . _excludeSelector = null ;
74
74
/** @type {?string } */
75
+ this . _touchExcludeSelector = null ;
76
+ /** @type {?string } */
75
77
this . _language = null ;
76
78
77
79
/** @type {?import('text-scanner').InputInfo } */
@@ -124,8 +126,6 @@ export class TextScanner extends EventDispatcher {
124
126
this . _sentenceBackwardQuoteMap = new Map ( ) ;
125
127
/** @type {import('text-scanner').InputConfig[] } */
126
128
this . _inputs = [ ] ;
127
- /** @type {boolean } */
128
- this . _scanAltText = true ;
129
129
130
130
/** @type {boolean } */
131
131
this . _enabled = false ;
@@ -198,6 +198,15 @@ export class TextScanner extends EventDispatcher {
198
198
this . _excludeSelector = value ;
199
199
}
200
200
201
+ /** @type {?string } */
202
+ get touchEventExcludeSelector ( ) {
203
+ return this . _touchExcludeSelector ;
204
+ }
205
+
206
+ set touchEventExcludeSelector ( value ) {
207
+ this . _touchExcludeSelector = value ;
208
+ }
209
+
201
210
/** @type {?string } */
202
211
get language ( ) { return this . _language ; }
203
212
set language ( value ) { this . _language = value ; }
@@ -257,7 +266,6 @@ export class TextScanner extends EventDispatcher {
257
266
preventMiddleMouse,
258
267
sentenceParsingOptions,
259
268
matchTypePrefix,
260
- scanAltText,
261
269
scanWithoutMousemove,
262
270
scanResolution,
263
271
} ) {
@@ -294,9 +302,6 @@ export class TextScanner extends EventDispatcher {
294
302
if ( typeof matchTypePrefix === 'boolean' ) {
295
303
this . _matchTypePrefix = matchTypePrefix ;
296
304
}
297
- if ( typeof scanAltText === 'boolean' ) {
298
- this . _scanAltText = scanAltText ;
299
- }
300
305
if ( typeof scanWithoutMousemove === 'boolean' ) {
301
306
this . _scanWithoutMousemove = scanWithoutMousemove ;
302
307
}
@@ -348,9 +353,9 @@ export class TextScanner extends EventDispatcher {
348
353
clonedTextSource . setEndOffset ( length , false , layoutAwareScan ) ;
349
354
350
355
const includeSelector = this . _includeSelector ;
351
- const excludeSelector = this . _excludeSelector ;
356
+ const excludeSelector = this . _getExcludeSelectorForPointerType ( pointerType ) ;
352
357
if ( includeSelector !== null || excludeSelector !== null ) {
353
- this . _constrainTextSource ( clonedTextSource , includeSelector , excludeSelector , layoutAwareScan , pointerType ) ;
358
+ this . _constrainTextSource ( clonedTextSource , includeSelector , excludeSelector , layoutAwareScan ) ;
354
359
}
355
360
356
361
return clonedTextSource . text ( ) ;
@@ -460,8 +465,17 @@ export class TextScanner extends EventDispatcher {
460
465
async _search ( textSource , searchTerms , searchKanji , inputInfo , showEmpty = false ) {
461
466
try {
462
467
const isAltText = textSource instanceof TextSourceElement ;
463
- if ( isAltText && ! this . _scanAltText ) {
464
- return ;
468
+ if ( inputInfo . pointerType === 'touch' ) {
469
+ if ( isAltText ) {
470
+ return ;
471
+ }
472
+ const { imposterSourceElement, rangeStartOffset} = textSource ;
473
+ if ( imposterSourceElement instanceof HTMLTextAreaElement || imposterSourceElement instanceof HTMLInputElement ) {
474
+ const isFocused = imposterSourceElement === document . activeElement ;
475
+ if ( ! isFocused || imposterSourceElement . selectionStart !== rangeStartOffset ) {
476
+ return ;
477
+ }
478
+ }
465
479
}
466
480
467
481
const inputInfoDetail = inputInfo . detail ;
@@ -1637,11 +1651,9 @@ export class TextScanner extends EventDispatcher {
1637
1651
* @param {?string } includeSelector
1638
1652
* @param {?string } excludeSelector
1639
1653
* @param {boolean } layoutAwareScan
1640
- * @param {import('input').PointerType | undefined } pointerType
1641
1654
*/
1642
- _constrainTextSource ( textSource , includeSelector , excludeSelector , layoutAwareScan , pointerType ) {
1655
+ _constrainTextSource ( textSource , includeSelector , excludeSelector , layoutAwareScan ) {
1643
1656
let length = textSource . text ( ) . length ;
1644
- excludeSelector = this . _createExcludeSelectorForPointerType ( excludeSelector , pointerType ) ;
1645
1657
1646
1658
while ( length > 0 ) {
1647
1659
const nodes = textSource . getNodesInRange ( ) ;
@@ -1658,17 +1670,14 @@ export class TextScanner extends EventDispatcher {
1658
1670
}
1659
1671
1660
1672
/**
1661
- * @param {?string } excludeSelector
1662
1673
* @param {import('input').PointerType | undefined } pointerType
1663
1674
* @returns {?string }
1664
1675
*/
1665
- _createExcludeSelectorForPointerType ( excludeSelector , pointerType ) {
1676
+ _getExcludeSelectorForPointerType ( pointerType ) {
1666
1677
if ( pointerType === 'touch' ) {
1667
- // Avoid trigger search with tapping on popup link, tag and inflection.
1668
- const popupClickableSelector = '.gloss-link, .gloss-link *, .tag, .tag *, .inflection' ;
1669
- return excludeSelector ? `${ excludeSelector } ,${ popupClickableSelector } ` : popupClickableSelector ;
1678
+ return this . _excludeSelector ? `${ this . _excludeSelector } ,${ this . touchEventExcludeSelector } ` : this . touchEventExcludeSelector ;
1670
1679
}
1671
- return excludeSelector ;
1680
+ return this . _excludeSelector ;
1672
1681
}
1673
1682
1674
1683
/**
0 commit comments