Merge pull request #10100 from Snuffleupagus/findbarclose
Clear all find highlights when the findbar is closed (issue 7468)
This commit is contained in:
commit
d0620ec894
@ -169,20 +169,27 @@ class MozL10n {
|
|||||||
'findhighlightallchange',
|
'findhighlightallchange',
|
||||||
'findcasesensitivitychange',
|
'findcasesensitivitychange',
|
||||||
'findentirewordchange',
|
'findentirewordchange',
|
||||||
|
'findbarclose',
|
||||||
];
|
];
|
||||||
let handleEvent = function(evt) {
|
let handleEvent = function({ type, detail, }) {
|
||||||
if (!PDFViewerApplication.initialized) {
|
if (!PDFViewerApplication.initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (type === 'findbarclose') {
|
||||||
|
PDFViewerApplication.eventBus.dispatch('findbarclose', {
|
||||||
|
source: window,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
PDFViewerApplication.eventBus.dispatch('find', {
|
PDFViewerApplication.eventBus.dispatch('find', {
|
||||||
source: window,
|
source: window,
|
||||||
type: evt.type.substring('find'.length),
|
type: type.substring('find'.length),
|
||||||
query: evt.detail.query,
|
query: detail.query,
|
||||||
phraseSearch: true,
|
phraseSearch: true,
|
||||||
caseSensitive: !!evt.detail.caseSensitive,
|
caseSensitive: !!detail.caseSensitive,
|
||||||
entireWord: !!evt.detail.entireWord,
|
entireWord: !!detail.entireWord,
|
||||||
highlightAll: !!evt.detail.highlightAll,
|
highlightAll: !!detail.highlightAll,
|
||||||
findPrevious: !!evt.detail.findPrevious,
|
findPrevious: !!detail.findPrevious,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -216,7 +216,8 @@ class PDFFindBar {
|
|||||||
this.opened = false;
|
this.opened = false;
|
||||||
this.toggleButton.classList.remove('toggled');
|
this.toggleButton.classList.remove('toggled');
|
||||||
this.bar.classList.add('hidden');
|
this.bar.classList.add('hidden');
|
||||||
this.findController.active = false;
|
|
||||||
|
this.eventBus.dispatch('findbarclose', { source: this, });
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
|
@ -53,11 +53,24 @@ class PDFFindController {
|
|||||||
|
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
|
eventBus.on('findbarclose', () => {
|
||||||
|
this._highlightMatches = false;
|
||||||
|
|
||||||
|
eventBus.dispatch('updatetextlayermatches', {
|
||||||
|
source: this,
|
||||||
|
pageIndex: -1,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Compile the regular expression for text normalization once.
|
// Compile the regular expression for text normalization once.
|
||||||
const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
|
const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
|
||||||
this._normalizationRegex = new RegExp(`[${replace}]`, 'g');
|
this._normalizationRegex = new RegExp(`[${replace}]`, 'g');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get highlightMatches() {
|
||||||
|
return this._highlightMatches;
|
||||||
|
}
|
||||||
|
|
||||||
get pageMatches() {
|
get pageMatches() {
|
||||||
return this._pageMatches;
|
return this._pageMatches;
|
||||||
}
|
}
|
||||||
@ -75,7 +88,7 @@ class PDFFindController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.active = false; // If active, find results will be highlighted.
|
this._highlightMatches = false;
|
||||||
this._pageMatches = [];
|
this._pageMatches = [];
|
||||||
this._pageMatchesLength = null;
|
this._pageMatchesLength = null;
|
||||||
this._state = null;
|
this._state = null;
|
||||||
@ -353,7 +366,7 @@ class PDFFindController {
|
|||||||
const currentPageIndex = this._pdfViewer.currentPageNumber - 1;
|
const currentPageIndex = this._pdfViewer.currentPageNumber - 1;
|
||||||
const numPages = this._pdfViewer.pagesCount;
|
const numPages = this._pdfViewer.pagesCount;
|
||||||
|
|
||||||
this.active = true;
|
this._highlightMatches = true;
|
||||||
|
|
||||||
if (this._dirtyMatch) {
|
if (this._dirtyMatch) {
|
||||||
// Need to recalculate the matches, reset everything.
|
// Need to recalculate the matches, reset everything.
|
||||||
|
@ -260,6 +260,8 @@ class PDFPageView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancelRendering(keepAnnotations = false) {
|
cancelRendering(keepAnnotations = false) {
|
||||||
|
const renderingState = this.renderingState;
|
||||||
|
|
||||||
if (this.paintTask) {
|
if (this.paintTask) {
|
||||||
this.paintTask.cancel();
|
this.paintTask.cancel();
|
||||||
this.paintTask = null;
|
this.paintTask = null;
|
||||||
@ -275,6 +277,14 @@ class PDFPageView {
|
|||||||
this.annotationLayer.cancel();
|
this.annotationLayer.cancel();
|
||||||
this.annotationLayer = null;
|
this.annotationLayer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (renderingState !== RenderingStates.INITIAL) {
|
||||||
|
this.eventBus.dispatch('pagecancelled', {
|
||||||
|
source: this,
|
||||||
|
pageNumber: this.id,
|
||||||
|
renderingState,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cssTransform(target, redrawAnnotations = false) {
|
cssTransform(target, redrawAnnotations = false) {
|
||||||
|
@ -56,6 +56,9 @@ class TextLayerBuilder {
|
|||||||
this.textLayerRenderTask = null;
|
this.textLayerRenderTask = null;
|
||||||
this.enhanceTextSelection = enhanceTextSelection;
|
this.enhanceTextSelection = enhanceTextSelection;
|
||||||
|
|
||||||
|
this._boundEvents = Object.create(null);
|
||||||
|
this._bindEvents();
|
||||||
|
|
||||||
this._bindMouse();
|
this._bindMouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +317,7 @@ class TextLayerBuilder {
|
|||||||
clearedUntilDivIdx = match.end.divIdx + 1;
|
clearedUntilDivIdx = match.end.divIdx + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.findController === null || !this.findController.active) {
|
if (!this.findController || !this.findController.highlightMatches) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,6 +334,40 @@ class TextLayerBuilder {
|
|||||||
this.renderMatches(this.matches);
|
this.renderMatches(this.matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_bindEvents() {
|
||||||
|
const { eventBus, _boundEvents, } = this;
|
||||||
|
|
||||||
|
_boundEvents.pageCancelled = (evt) => {
|
||||||
|
if (evt.pageNumber !== this.pageNumber) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.textLayerRenderTask) {
|
||||||
|
console.error('TextLayerBuilder._bindEvents: `this.cancel()` should ' +
|
||||||
|
'have been called when the page was reset, or rendering cancelled.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Ensure that all event listeners are cleaned up when the page is reset,
|
||||||
|
// since re-rendering will create new `TextLayerBuilder` instances and the
|
||||||
|
// number of (stale) event listeners would otherwise grow without bound.
|
||||||
|
for (const name in _boundEvents) {
|
||||||
|
eventBus.off(name.toLowerCase(), _boundEvents[name]);
|
||||||
|
delete _boundEvents[name];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
_boundEvents.updateTextLayerMatches = (evt) => {
|
||||||
|
if (evt.pageIndex !== -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.updateMatches();
|
||||||
|
};
|
||||||
|
|
||||||
|
eventBus.on('pagecancelled', _boundEvents.pageCancelled);
|
||||||
|
eventBus.on('updatetextlayermatches', _boundEvents.updateTextLayerMatches);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Improves text selection by adding an additional div where the mouse was
|
* Improves text selection by adding an additional div where the mouse was
|
||||||
* clicked. This reduces flickering of the content if the mouse is slowly
|
* clicked. This reduces flickering of the content if the mouse is slowly
|
||||||
|
Loading…
x
Reference in New Issue
Block a user