message: Add/remove highlights in the Find extension when it is open/closed.
diff: @@ -56,19 +56,18 @@ class FindWidget {
  this._terminal.onDidAppendViewer((viewer: Viewer) => {
  this._handleViewerAppended(viewer);
  });
  - }
  - focus(): void {
  - this._ui.focus();
  - }
  + this._widget.onDidClose(() => {
  + this._handleClose();
  + });
  - private _close(): void {
  - const termViewers = this._getViewers();
  - for (const viewer of termViewers) {
  - viewer.highlight(null);
  + this._widget.onDidOpen(() => {
  + this._applyHighlight();
  + });
  }
  - this._widget.close();
  + focus(): void {
  + this._ui.focus();
  }
  private _needleRegExp(extraFlags=""): RegExp {
  @@ -84,10 +83,9 @@ class FindWidget {
  }
  private _find(): void {
  + this._applyHighlight();
  +
  const termViewers = this._getViewers();
  - for (const viewer of termViewers) {
  - viewer.highlight(this._needleRegExp("g"));
  - }
  const needleRegExp = this._needleRegExp();
  for (let i=termViewers.length-1; i> 0; i--) {
  @@ -97,6 +95,20 @@ class FindWidget {
  }
  }
  + private _applyHighlight(): void {
  + const termViewers = this._getViewers();
  + for (const viewer of termViewers) {
  + viewer.highlight(this._needleRegExp("g"));
  + }
  + }
  +
  + private _removeHighlight(): void {
  + const termViewers = this._getViewers();
  + for (const viewer of termViewers) {
  + viewer.highlight(null);
  + }
  + }
  +
  private _getViewers(): (TerminalOutputViewer | TextViewer)[] {
  const termViewers: (TerminalOutputViewer | TextViewer)[] = [];
  for (const viewer of this._terminal.getViewers()) {
  @@ -121,20 +133,18 @@ class FindWidget {
  }
  private _handleViewerAppended(viewer: Viewer): void {
  + if (this._widget.isOpen()) {
  const v = this._unpackViewer(viewer);
  if (v != null) {
  v.highlight(this._needleRegExp("g"));
  }
  }
  + }
  private _findForewards(): void {
  - const termViewers = this._getViewers();
  -
  - const highlightRegExp = this._needleRegExp("g");
  - for (const viewer of termViewers) {
  - viewer.highlight(highlightRegExp);
  - }
  + this._applyHighlight();
  + const termViewers = this._getViewers();
  let i = termViewers.findIndex(v => v.hasSelection());
  if (i === -1) {
  this._find();
  @@ -155,13 +165,9 @@ class FindWidget {
  }
  private _findBackwards(): void {
  - const termViewers = this._getViewers();
  -
  - const highlightRegExp = this._needleRegExp("g");
  - for (const viewer of termViewers) {
  - viewer.highlight(highlightRegExp);
  - }
  + this._applyHighlight();
  + const termViewers = this._getViewers();
  let i = termViewers.findIndex(v => v.hasSelection());
  if (i === -1) {
  this._find();
  @@ -180,6 +186,15 @@ class FindWidget {
  }
  }
  }
  +
  + private _handleClose(): void {
  + this._removeHighlight();
  + }
  +
  + private _close(): void {
  + this._widget.close();
  + }
  +
  }
  @Component(
  