Skip to content

Commit

Permalink
Browse mode: Elements List dialog: Delay applying filter for smoother…
Browse files Browse the repository at this point in the history
… response (#10308)

Related to #7197, but does not solve it.

Summary of the issue:
In browse mode, in the Elements List dialog, speed typing a filter string leads to slow responsiveness from the UI and NVDA itself.

Description of how this pull request fixes the issue:
lightly delay the refresh of the elements list by 300 ms. (same technique as PR #10307)

---------

Co-authored-by: Leonard de Ruijter <leonardder@users.noreply.github.com>
Co-authored-by: Sean Budd <sean@nvaccess.org>
  • Loading branch information
3 people committed Jun 20, 2023
1 parent f6ac801 commit a574f83
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions source/browseMode.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2007-2021 NV Access Limited, Babbage B.V., James Teh, Leonard de Ruijter,
# Copyright (C) 2007-2023 NV Access Limited, Babbage B.V., James Teh, Leonard de Ruijter,
# Thomas Stivers, Accessolutions, Julien Cochuyt
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

from typing import Any, Callable, Union
from typing import (
Any,
Callable,
Union,
cast,
)
import os
import itertools
import collections
Expand Down Expand Up @@ -980,7 +985,8 @@ def __init__(self, document):
# in the browse mode Elements List dialog.
filterText = _("Filter b&y:")
labeledCtrl = gui.guiHelper.LabeledControlHelper(self, filterText, wx.TextCtrl)
self.filterEdit = labeledCtrl.control
self.filterEdit = cast(wx.TextCtrl, labeledCtrl.control)
self.filterTimer: Optional[wx.CallLater] = None
self.filterEdit.Bind(wx.EVT_TEXT, self.onFilterEditTextChange)
contentsSizer.Add(labeledCtrl.sizer)
contentsSizer.AddSpacer(gui.guiHelper.SPACE_BETWEEN_VERTICAL_DIALOG_ITEMS)
Expand Down Expand Up @@ -1206,8 +1212,14 @@ def _iterReachableTreeItemsFromItem(self, item):

item = self.tree.GetNextSibling(item)

def onFilterEditTextChange(self, evt):
self.filter(self.filterEdit.GetValue())
FILTER_TIMER_DELAY_MS = 300

def onFilterEditTextChange(self, evt: wx.CommandEvent) -> None:
filter = self.filterEdit.GetValue()
if self.filterTimer is None:
self.filterTimer = wx.CallLater(self.FILTER_TIMER_DELAY_MS, self.filter, filter)
else:
self.filterTimer.Start(self.FILTER_TIMER_DELAY_MS, filter)
evt.Skip()

def onAction(self, activate):
Expand Down

0 comments on commit a574f83

Please sign in to comment.